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 all 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
17 changes: 12 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ jobs:
pip --version
pip install --upgrade setuptools>=74 wheel

- name: Fix user Scripts missing from PATH
if: matrix.architecture == 'x86'
run: |
# Work around https://github.com/actions/setup-python/issues/1005
$ScriptsPath = python -c "import sysconfig,os; print(sysconfig.get_path('scripts', f'{os.name}_user'))"
echo $ScriptsPath
Add-Content $env:GITHUB_PATH $ScriptsPath

- name: Build and install
run: pip install . -v --user

Expand All @@ -49,18 +57,17 @@ jobs:
- name: Generate PyWin32.chm help file
run: python AutoDuck/make.py

# Smokescreen test to validate it doesn't crash and dlls can be found
# Smokescreen test to validate postinstall doesn't crash, dlls can be found, and both pathless invocation methods work
- name: Run postinstall install/remove
run: |
$UserSite = "$(python -m site --user-site)"
cd "$UserSite/.."
python Scripts/pywin32_postinstall.py -install -destination "$UserSite"
python Scripts/pywin32_postinstall.py -remove -destination "$UserSite"
python -m win32.scripts.pywin32_postinstall -install -destination "$UserSite"
pywin32_postinstall -remove -destination "$UserSite"

- 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
5 changes: 4 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Notable changes in recent builds.
Notable changes in recent builds.

Maintained by hand, so what's "notable" is subjective! Contributors are
encouraged to add entries for their work.
Expand All @@ -14,6 +14,9 @@ https://mhammond.github.io/pywin32_installers.html.
Coming in build 309, as yet unreleased
--------------------------------------

* The postinstall script is now available as a console script. You can invoke it in one of two new methods:
1. `python -m pywin32_postinstall -install` (recommended)
2. `pywin32_postinstall -install` (shorter but you don't have control over which python environment is used)
* 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
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,10 +655,11 @@ def main():

* Typical usage:

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

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

> pywin32_postinstall -install

Given EXE installers are no longer provided,
and wheel installs can't run postinstall scripts,
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