From 9ff63c291443c6be1a06316c1f9f9638e38164e1 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 5 Jan 2025 16:14:52 -0500 Subject: [PATCH 1/2] Automatically run `pywin32_postinstall.py` for local/from source installs (`pip install .`) - Also respect the verbose flag instead of always running quiet - Added support for relative path for the `-destination` argument --- CHANGES.txt | 1 + pywin32_postinstall.py | 7 +++++-- setup.py | 17 +++-------------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 7fe29bddd1..7f4e5c28be 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,7 @@ https://mhammond.github.io/pywin32_installers.html. Coming in build 309, as yet unreleased -------------------------------------- +* Added support for relative path for `pywin32_postinstall`'s `-destination` argument (#2447, @Avasam) * Restored axdebug builds on Python 3.10 (#2416, @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) diff --git a/pywin32_postinstall.py b/pywin32_postinstall.py index e90e354d9f..6974c8eb53 100644 --- a/pywin32_postinstall.py +++ b/pywin32_postinstall.py @@ -642,9 +642,12 @@ def uninstall(lib_dir): # Out of principle, we're still not using system exits. -def verify_destination(location): +def verify_destination(location: str) -> str: + location = os.path.abspath(location) if not os.path.isdir(location): - raise argparse.ArgumentTypeError(f'Path "{location}" does not exist!') + raise argparse.ArgumentTypeError( + f'Path "{location}" is not an existing directory!' + ) return location diff --git a/setup.py b/setup.py index b9a664f444..01aa47d629 100644 --- a/setup.py +++ b/setup.py @@ -856,16 +856,6 @@ def run(self): This is only run for local installs. Wheel-based installs won't run this code. """ install.run(self) - # If self.root has a value, it means we are being "installed" into some other - # directory than Python itself - in which case we must *not* run our installer. - # bdist_wininst used to trigger this by using a temp directory. - # Is this still a concern ? - if self.root: - print( - "Not executing post install script when " - + f"not installing in Python itself (self.root={self.root})" - ) - return self.execute(self._postinstall, (), msg="Executing post install script...") def _postinstall(self): @@ -874,17 +864,16 @@ def _postinstall(self): raise RuntimeError(f"Can't find '{filename}'") # As of setuptools>=74.0.0, we no longer need to # be concerned about distutils calling win32api - subprocess.Popen( - [ + subprocess.check_call( + ( sys.executable, filename, "-install", "-destination", self.install_lib, - "-quiet", "-wait", str(os.getpid()), - ] + ) ) From d1fa2323e8e11e55d509a7fbfa3189daf0cbf195 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 7 Jan 2025 00:02:32 -0500 Subject: [PATCH 2/2] Hacky skip for build-only commands --- setup.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 01aa47d629..ba65669e51 100644 --- a/setup.py +++ b/setup.py @@ -856,7 +856,11 @@ def run(self): This is only run for local installs. Wheel-based installs won't run this code. """ install.run(self) - self.execute(self._postinstall, (), msg="Executing post install script...") + # Hacky, skip for build-only commands + if "build" in sys.argv: + print("Skipping post install script for build commands.") + else: + self.execute(self._postinstall, (), msg="Executing post install script...") def _postinstall(self): filename = os.path.join(self.install_scripts, "pywin32_postinstall.py")