Skip to content

Commit

Permalink
restore shipping help file
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Nov 19, 2024
1 parent 0b0ec6a commit 76755cb
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 48 deletions.
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
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")
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()

# 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

0 comments on commit 76755cb

Please sign in to comment.