Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore shipping help file #2432

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ on:
push:
branches:
- main
pull_request: # Temporary just for test
branches:
- main

jobs:
generate:
Expand All @@ -25,17 +22,16 @@ jobs:
with:
python-version: '3.9'

# We still need to install pywin32 because
# AutoDuck/py2d.py currently relies on runtime imports for introspection
# Downloading latest release is faster than re-building
# We install pywin32's latest release just to avoid re-building
# We could instead try to use a GitHub artifact
- name: Install latest release
run: pip install --user --upgrade pywin32

- name: Generate PyWin32.chm help file
run: python AutoDuck/make.py
- name: Set Python user site directory
run: python -c "import os,site; open(os.environ['GITHUB_ENV'], 'a').write(f'USER_DIR={site.USER_SITE}\n')"

- name: Decompile help file into HTML
run: hh -decompile site PyWin32.chm
- name: Decompile shipped help file
run: hh -decompile site ${env:USER_DIR}\PyWin32.chm

- name: Rename root HTML file
run: mv site\PyWin32.HTML site\index.html
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ jobs:
run: |
python setup.py install --user

# This needs to happen *after* installing pywin32 since
# AutoDuck/py2d.py currently relies on runtime imports for introspection
# This isn't included in the wheel (TODO: could we?)
# and only servces as a PR test for the docs.yaml workflow
- name: Generate PyWin32.chm help file
run: python AutoDuck/make.py

- name: Run tests
# Run the tests directly from the source dir so support files (eg, .wav files etc)
# can be found - they aren't installed into the Python tree.
Expand Down
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ https://mhammond.github.io/pywin32_installers.html.
Coming in build 309, as yet unreleased
--------------------------------------

* Restored shipping a helpfile with the wheel. Run like for pywin32 306 and before, you can run the `pywin32_postinstall` script to register it (#2432, @Avasam)
* Pythonwin: Bumped Scintilla from 1.77 to 4.4.6. The full changelog can be found here: https://www.scintilla.org/ScintillaHistory.html
* Fixed `ddeclient` and `ddeserver` demos import error (#2290, @Avasam)
* The `EvtSubscribe_push` demo now actually demonstrates the callback action and the event context being filled. (#2281, @Avasam)
Expand Down
13 changes: 5 additions & 8 deletions pywin32_postinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,10 @@ def RegisterHelpFile(register=True, lib_dir=None):
if register:
# Register the .chm help file.
chm_file = os.path.join(lib_dir, "PyWin32.chm")
if os.path.isfile(chm_file):
# This isn't recursive, so if 'Help' doesn't exist, we croak
SetPyKeyVal("Help", None, None)
SetPyKeyVal("Help\\Pythonwin Reference", None, chm_file)
return chm_file
else:
print("NOTE: PyWin32.chm can not be located, so has not been registered")
# This isn't recursive, so if 'Help' doesn't exist, we croak
SetPyKeyVal("Help", None, None)
SetPyKeyVal("Help\\Pythonwin Reference", None, chm_file)
return chm_file
else:
UnsetPyKeyVal("Help\\Pythonwin Reference", None, delete_key=True)
return None
Expand Down Expand Up @@ -510,7 +507,7 @@ def install(lib_dir):
try:
chm_file = RegisterHelpFile(True, lib_dir)
except Exception:
print("Failed to register help file")
print(f"Failed to register help file")
Avasam marked this conversation as resolved.
Show resolved Hide resolved
traceback.print_exc()
else:
if verbose:
Expand Down
71 changes: 48 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import shutil
import subprocess
import sys
import sysconfig
import winreg
from pathlib import Path
from setuptools import Extension, setup
Expand Down Expand Up @@ -491,6 +492,48 @@ def _build_scintilla(self):
os.path.join(self.build_lib, "pythonwin"),
)

def _build_helpfile(self) -> None:
"""
Since AutoDuck/py2d.py relies on import,
this must be done after all extensions are built.

We can't just add to sys.path to point to the build folder,
because this uses subprocesses,
so we we create a temporary .pth file instead.
"""
build_lib_absolute = os.path.abspath(self.build_lib)
tmp_pywin32_build_pth = (
Path(sysconfig.get_paths()["platlib"]) / "tmp_pywin32_build.pth"
)

# Delete the previous helpfile to ensure that this build worked
Path("PyWin32.chm").unlink(missing_ok=True)

# Create the temporary .pth file
with open("pywin32.pth") as path_file:
# Copy paths from pywin32.pth and expand them to absolute paths
paths = [
(
path.strip()
# support the "import pywin32_bootstrap" hack
if path.startswith("import ")
else os.path.join(build_lib_absolute, path.strip())
)
for path in path_file.readlines()
if not path.startswith("#")
] + [
build_lib_absolute,
# For pythoncom.py, since it doesn't get added to the build folder
os.path.abspath("com"),
]
tmp_pywin32_build_pth.write_text("\n".join(paths))

# Actually generate the helpfile
subprocess.run((sys.executable, "AutoDuck/make.py"), check=True)

# Cleanup
# tmp_pywin32_build_pth.unlink()
Avasam marked this conversation as resolved.
Show resolved Hide resolved

# find the VC base path corresponding to distutils paths, and
# potentially upgrade for extra include / lib paths (MFC)
def _check_vc(self):
Expand Down Expand Up @@ -635,6 +678,8 @@ def build_extensions(self):
for mfc_content in mfc_contents:
self.copy_file(mfc_content, target_dir)

self._build_helpfile()

def build_exefile(self, ext):
suffix = "_d" if self.debug else ""
logging.info("building exe '%s'", ext.name)
Expand Down Expand Up @@ -2024,20 +2069,6 @@ def convert_data_files(files: Iterable[str]):
return ret


def convert_optional_data_files(files):
ret = []
for file in files:
try:
temp = convert_data_files([file])
except RuntimeError as details:
if not str(details.args[0]).startswith("No file"):
raise
logging.info("NOTE: Optional file %s not found - skipping", file)
else:
ret.append(temp[0])
return ret


################################################################
if len(sys.argv) == 1:
# distutils will print usage - print our docstring first.
Expand Down Expand Up @@ -2181,11 +2212,6 @@ def maybe_fixup_exes():
packages=packages,
py_modules=py_modules,
data_files=[("", (os.path.join(gettempdir(), "pywin32.version.txt"),))]
+ convert_optional_data_files(
[
"PyWin32.chm",
]
)
+ convert_data_files(
[
"Pythonwin/start_pythonwin.pyw",
Expand Down Expand Up @@ -2243,9 +2269,8 @@ def maybe_fixup_exes():
"adodbapi/examples/*.py",
]
)
+
# The headers and .lib files
[
+ [
("win32/include", ("win32/src/PyWinTypes.h",)),
(
"win32com/include",
Expand All @@ -2256,14 +2281,14 @@ def maybe_fixup_exes():
),
),
]
+
# And data files convert_data_files can't handle.
[
+ [
("win32com", ("com/License.txt",)),
# pythoncom.py doesn't quite fit anywhere else.
# Note we don't get an auto .pyc - but who cares?
("", ("com/pythoncom.py",)),
("", ("pywin32.pth",)),
("", ("PyWin32.chm",)),
],
)

Expand Down
Loading