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

Automatically run pywin32_postinstall.py for "local"/"from source" installs #2447

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
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
--------------------------------------

* Added support for relative path for `pywin32_postinstall`'s `-destination` argument (#2447, @Avasam)
* Removed param `hIcon` from `win32comext.shell.ShellExecuteEx`. It was unusable since Windows Vista (#2423, @Avasam)
* Fixed `nbios.NCBStruct` packing (#2406, @Avasam)
* Restored axdebug builds on Python 3.10 (#2416, @Avasam)
Expand Down
7 changes: 5 additions & 2 deletions pywin32_postinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
17 changes: 3 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Copy link
Collaborator Author

@Avasam Avasam Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: This wouldn't replace #2392
That other PR also tests uninstalling
In fact both together should be better as it would test the install under 2 different contexts, and test a re-install.

[
subprocess.check_call(
(
sys.executable,
filename,
"-install",
"-destination",
self.install_lib,
"-quiet",
Copy link
Collaborator Author

@Avasam Avasam Jan 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I did

Suggested change
"-quiet",
*([] if self.verbose else ["-quiet"]),

but realized pip without -v isn't printing any of this anyway.

"-wait",
str(os.getpid()),
]
)
)


Expand Down
Loading