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

Make pywin32_postinstall and pywin32_testall into Console Scripts #2408

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- 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.
run: python pywin32_testall.py -v -skip-adodbapi
run: python win32/scripts/pywin32_testall.py -v -skip-adodbapi

- name: Build wheels
run: pip wheel . -v --wheel-dir=dist
Expand Down
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,22 @@ There is a post-install script (see below) which should *not* be run inside virt
it should only be run in "global" installs.

For unreleased changes, you can download builds made by [github actions](https://github.com/mhammond/pywin32/actions/) -
choose any "workflow" from the `main` branch and download its "artifacts")
choose any "workflow" from the `main` branch and download its "artifacts"

### Installing globally

Outside of a virtual environment you might want to install COM objects, services, etc. You can do
this by executing:

```shell
python Scripts/pywin32_postinstall.py -install
python -m pywin32_postinstall -install
```

From the root of your Python installation.
or (shorter but you don't have control over which python environment is used)

```shell
pywin32_postinstall -install
```

If you do this with normal permissions it will be global for your user (a few files will be
copied to the root of your Python install and some changes made to HKCU). If you execute this from
Expand Down Expand Up @@ -91,7 +95,13 @@ It usually means one of 2 things:
So you should run it again:

```shell
python Scripts/pywin32_postinstall.py -install
python -m pywin32_postinstall -install
```

or (shorter but you don't have control over which python environment is used)

```shell
pywin32_postinstall -install
```

This will make some small attempts to cleanup older conflicting installs.
Expand Down
13 changes: 12 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2077,7 +2077,18 @@ def convert_optional_data_files(files):
license="PSF",
classifiers=classifiers,
cmdclass=cmdclass,
scripts=["pywin32_postinstall.py", "pywin32_testall.py"],
# This adds the scripts under Python3XX/Scripts, but doesn't actually do much
scripts=[
"win32/scripts/pywin32_postinstall.py",
"win32/scripts/pywin32_testall.py",
],
Comment on lines +2080 to +2084
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm keeping this for now as to not break some poor sysadmin's workflow of looking in Python's Scripts folder 😉 (then again, they were probably using .exe installers, but it's barely 4 lines to keep the support)

# This shortcuts `python -m win32.scripts.some_script` to just `some_script`
entry_points={
"console_scripts": [
"pywin32_postinstall = win32.scripts.pywin32_postinstall:main",
"pywin32_testall = win32.scripts.pywin32_testall:main",
]
},
ext_modules=ext_modules,
package_dir={
"win32com": "com/win32com",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,9 +655,13 @@ def main():

* Typical usage:

> python pywin32_postinstall.py -install
> python -m pywin32_postinstall -install

This should be run automatically after installation,
* or (shorter but you don't have control over which python environment is used)

> pywin32_postinstall -install

This should be run automatically after installation when installing from source,
but if it fails you can run it again.
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.

Suggested change
This should be run automatically after installation when installing from source,
but if it fails you can run it again.

Just tested and the "when installed from source" part isn't even true because self.root=build\bdist.win-amd64\wheel when running pip install . . So class my_install in setup.py right now is complete dead code. I'll tackle that in a different PR.

Edit: Done in #2447


Given EXE installers are no longer provided,
Expand Down
13 changes: 4 additions & 9 deletions pywin32_testall.py → win32/scripts/pywin32_testall.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

# locate the dirs based on where this script is - it may be either in the
# source tree, or in an installed Python 'Scripts' tree.
this_dir = os.path.dirname(__file__)
site_packages = [
site.getusersitepackages(),
] + site.getsitepackages()
project_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
site_packages = [site.getusersitepackages()] + site.getsitepackages()

failures = []

Expand Down Expand Up @@ -45,7 +43,7 @@ def find_and_run(possible_locations, extras):
def main():
import argparse

code_directories = [this_dir] + site_packages
code_directories = [project_root] + site_packages

parser = argparse.ArgumentParser(
description="A script to trigger tests in all subprojects of PyWin32."
Expand Down Expand Up @@ -89,10 +87,7 @@ def main():
# win32com
maybes = [
os.path.join(directory, "win32com", "test", "testall.py")
for directory in [
os.path.join(this_dir, "com"),
]
+ site_packages
for directory in [os.path.join(project_root, "com")] + site_packages
]
extras = remains + ["1"] # only run "level 1" tests in CI
find_and_run(maybes, extras)
Expand Down
Loading