Skip to content

Commit 877a2c2

Browse files
authored
Stop calling setup.py, use a build frontend (#2396)
1 parent b19e86b commit 877a2c2

File tree

11 files changed

+48
-100
lines changed

11 files changed

+48
-100
lines changed

.github/workflows/main.yml

+12-16
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"]
21+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
2222
architecture: ["x64", "x86"]
2323

2424
steps:
@@ -40,8 +40,7 @@ jobs:
4040
pip install --upgrade setuptools>=74 wheel
4141
4242
- name: Build and install
43-
run: |
44-
python setup.py install --user
43+
run: pip install . -v --user
4544

4645
# This needs to happen *after* installing pywin32 since
4746
# AutoDuck/py2d.py currently relies on runtime imports for introspection
@@ -56,15 +55,15 @@ jobs:
5655
run: python pywin32_testall.py -v -skip-adodbapi
5756

5857
- name: Build wheels
59-
run: |
60-
python setup.py bdist_wheel --skip-build
58+
run: pip wheel . -v --wheel-dir=dist
6159

6260
- uses: actions/upload-artifact@v3
6361
# Upload artifacts even if tests fail
6462
if: ${{ always() }}
6563
with:
6664
name: artifacts
6765
path: dist/*.whl
66+
if-no-files-found: error
6867

6968
# We cannot build and test on ARM64, so we cross-compile.
7069
# Later, when available, we can add tests using this wheel on ARM64 VMs
@@ -75,7 +74,7 @@ jobs:
7574
strategy:
7675
fail-fast: false
7776
matrix:
78-
python-version: ["3.10", "3.11", "3.12", "3.13-dev"]
77+
python-version: ["3.10", "3.11", "3.12", "3.13"]
7978
steps:
8079
- uses: actions/checkout@v4
8180

@@ -92,21 +91,19 @@ jobs:
9291
run: |
9392
python --version
9493
pip --version
95-
pip install --upgrade setuptools>=74 wheel
94+
pip install --upgrade setuptools>=74 wheel build
9695
9796
- name: Obtain ARM64 library files
98-
run: |
99-
python .github\workflows\download-arm64-libs.py .\arm64libs
97+
run: python .github\workflows\download-arm64-libs.py .\arm64libs
10098

10199
- name: Build wheels
102-
run: python setup.py build_ext -L .\arm64libs --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64
100+
run: python -m build --wheel --config-setting=--build-option=build_ext --config-setting=--build-option=-L.\arm64libs --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=build --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=bdist_wheel --config-setting=--build-option=--plat-name=win-arm64
103101

104102
- uses: actions/upload-artifact@v3
105-
if: ${{ always() }}
106103
with:
107104
name: artifacts
108-
path: |-
109-
dist/*.whl
105+
path: dist/*.whl
106+
if-no-files-found: error
110107

111108
# This job can be run locally by running `pre-commit run`
112109
checkers:
@@ -139,8 +136,7 @@ jobs:
139136
strategy:
140137
fail-fast: false
141138
matrix:
142-
# mypy won't understand "3.13-dev", keeping the CI simple by just omitting it
143-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
139+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
144140
steps:
145141
- uses: actions/checkout@v4
146142
- uses: actions/setup-python@v5
@@ -158,7 +154,7 @@ jobs:
158154
strategy:
159155
fail-fast: false
160156
matrix:
161-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13-dev"]
157+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
162158
steps:
163159
- uses: actions/checkout@v4
164160
- uses: actions/setup-python@v5

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ __pycache__
1313
*.chw
1414
*.pyo
1515
*.pdb
16+
*.whl
1617
arm64libs/
1718
pywin32.egg-info/
1819
PyWin32.kpf

Pythonwin/pywin/framework/mdi_pychecker.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ def threadPycheckerRun(self):
361361
result = "Can't find python.exe!\n"
362362
elif not os.path.isfile(pychecker):
363363
result = (
364-
"Can't find checker.py - please install pychecker "
365-
"(or run 'setup.py install' if you have the source version)\n"
364+
"Can't find checker.py - please install PyChecker "
365+
"(https://pypi.org/project/PyChecker/)\n"
366366
)
367367
else:
368368
cmd = f'{py} "{pychecker}" {options} {files} 2>&1'

README.md

+4-20
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ To run as a service, you probably want to install pywin32 globally from an eleva
7373
command prompt - see above.
7474

7575
You also need to ensure Python is installed in a location where the user running
76-
the service has access to the installation and is able to load `pywintypesXX.dll` and `pythonXX.dll`. In particular, the `LocalSystem` account typically will not have access
77-
to your local `%USER%` directory structure.
76+
the service has access to the installation and is able to load `pywintypesXX.dll` and `pythonXX.dll`.
77+
In particular, the `LocalSystem` account typically will not have access to your local `%USER%` directory structure.
7878

7979
## Troubleshooting
8080

@@ -112,23 +112,7 @@ Install Visual Studio 2019 (later probably works, but options might be different
112112
follow the instructions in [Build environment](/build_env.md#build-environment)
113113
for the version you install.
114114

115-
(the free compilers probably work too, but haven't been tested - let me know your experiences!)
116-
117-
`setup.py` is a standard distutils build script, so you probably want:
118-
119-
```shell
120-
python setup.py install
121-
```
122-
123-
or
124-
125-
```shell
126-
python setup.py --help
127-
```
128-
129-
Some modules need obscure SDKs to build - `setup.py` should succeed, gracefully
130-
telling you why it failed to build them - if the build actually fails with your
131-
configuration, please [open an issue](https://github.com/mhammond/pywin32/issues).
115+
Then follow the [Build](/build_env.md#build) instructions for the build itself (including ARM64 cross-compilation).
132116

133117
## Release process
134118

@@ -147,7 +131,7 @@ Since build 307 the release process is based on the artifacts created by Github
147131
* Push these changes to github, wait for the actions to complete, then
148132
download the artifacts from that run.
149133

150-
* Upload .whl artifacts to pypi - we do this before pushing the tag because they might be
134+
* Upload `.whl` artifacts to pypi - we do this before pushing the tag because they might be
151135
rejected for an invalid `README.md`. Done via `py -3.? -m twine upload dist/*XXX*.whl`.
152136

153137
* Create a new git tag for the release.

adodbapi/readme.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Prerequisites:
2323
and pywin32 (Mark Hammond's python for windows extensions.)
2424

2525
Installation:
26-
* (C-Python on Windows): Install pywin32 ("pip install pywin32") which includes adodbapi.
26+
* (C-Python on Windows): Install pywin32 (`python -m pip install pywin32`) which includes adodbapi.
2727
* (IronPython on Windows): Download adodbapi from http://sf.net/projects/adodbapi. Unpack the zip.
2828

2929
NOTE: ...........

build_all.bat

-30
This file was deleted.

build_env.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,15 @@ where mc
121121

122122
# Build
123123

124-
One everything is setup, just execute:
124+
Once everything is setup, just execute the following from the pywin32 directory:
125125

126126
```shell
127-
python setup.py -q install
127+
pip install . -v
128128
```
129129

130-
from the pywin32 directory.
130+
Some modules need obscure SDKs to build - `pip install` should succeed, gracefully
131+
telling you why it failed to build them with the `-v` flag - if the build actually fails with your
132+
configuration, please [open an issue](https://github.com/mhammond/pywin32/issues).
131133

132134
## Cross-compiling for ARM64 (Microsoft Visual C++ 14.1 and up)
133135

@@ -155,13 +157,13 @@ from the pywin32 directory.
155157
- Build the extensions, passing the directory from earlier. You may optionally add the `bdist_wheel` command to generate a wheel.
156158

157159
```shell
158-
python setup.py build_ext -L "<temporary path from earlier>" bdist_wheel
160+
python -m build --wheel --config-setting=--build-option=build_ext --config-setting=--build-option=-L.\arm64libs --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=bdist_wheel --config-setting=--build-option=--plat-name=win-arm64
159161
```
160162

161163
- If you are not using an initialized build environment, you will need to specify the `build_ext`, `build` and `bdist_wheel` commands and pass `--plat-name win-arm64` to *each* of them separately. Otherwise you may get a mixed platform build and/or linker errors.
162164

163165
- Copy the built wheel to the target machine and install directly:
164166

165167
```shell
166-
python -m pip install "<path to wheel>"
168+
pip install "<path to wheel>" -v
167169
```

make_all.bat

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
11
@if "%1"=="quick" goto quick
2-
@if "%1"=="already_built" goto already_built
32
if exist build\. rd /s/q build
43
if exist build\. goto couldnt_rm
54
:quick
6-
call build_all.bat
7-
@if errorlevel 1 goto failed
85
py autoduck\make.py
96
@if errorlevel 1 goto failed
10-
:already_built
11-
rem Now the binaries.
127

138
rem Check /build_env.md#build-environment to make sure you have all the required components installed
149

15-
py -3.8-32 setup.py -q bdist_wheel --skip-build
16-
py -3.8 setup.py -q bdist_wheel --skip-build
10+
py -3.8-32 -m build --wheel
11+
py -3.8 -m build --wheel
1712

18-
py -3.9-32 setup.py -q bdist_wheel --skip-build
19-
py -3.9 setup.py -q bdist_wheel --skip-build
13+
py -3.9-32 -m build --wheel
14+
py -3.9 -m build --wheel
2015

21-
py -3.10-32 setup.py -q bdist_wheel --skip-build
22-
py -3.10 setup.py -q bdist_wheel --skip-build
16+
py -3.10-32 -m build --wheel
17+
py -3.10 -m build --wheel
2318

24-
py -3.11-32 setup.py -q bdist_wheel --skip-build
25-
py -3.11 setup.py -q bdist_wheel --skip-build
19+
py -3.11-32 -m build --wheel
20+
py -3.11 -m build --wheel
2621

27-
py -3.12-32 setup.py -q bdist_wheel --skip-build
28-
py -3.12 setup.py -q bdist_wheel --skip-build
22+
py -3.12-32 -m build --wheel
23+
py -3.12 -m build --wheel
2924

30-
py -3.13-32 setup.py -q bdist_wheel --skip-build
31-
py -3.13 setup.py -q bdist_wheel --skip-build
25+
py -3.13-32 -m build --wheel
26+
py -3.13 -m build --wheel
3227

3328
rem Check /build_env.md#build-environment to make sure you have all the required ARM64 components installed
34-
py -3.10 setup.py -q build_ext --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64
35-
py -3.11 setup.py -q build_ext --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64
36-
py -3.12 setup.py -q build_ext --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64
37-
py -3.13 setup.py -q build_ext --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64
29+
py -3.10 -m build --wheel --config-setting=--build-option=build_ext --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=build --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=bdist_wheel --config-setting=--build-option=--plat-name=win-arm64
30+
py -3.11 -m build --wheel --config-setting=--build-option=build_ext --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=build --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=bdist_wheel --config-setting=--build-option=--plat-name=win-arm64
31+
py -3.12 -m build --wheel --config-setting=--build-option=build_ext --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=build --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=bdist_wheel --config-setting=--build-option=--plat-name=win-arm64
32+
py -3.13 -m build --wheel --config-setting=--build-option=build_ext --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=build --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=bdist_wheel --config-setting=--build-option=--plat-name=win-arm64
3833

3934
@goto xit
4035
:couldnt_rm

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
1010
To build and install locally for testing etc, you need a build environment
1111
which is capable of building the version of Python you are targeting, then:
12-
python setup.py -q install
12+
pip install . -v
1313
1414
For a debug (_d) version, you need a local debug build of Python, but must use
1515
the release version executable for the build. eg:
16-
python setup.py -q build --debug install
16+
pip install . -v --config-setting=--build-option=build --config-setting=--build-option=--debug
1717
1818
Cross-compilation from x86 to ARM is well supported (assuming installed vs tools etc) - eg:
19-
python setup.py -q build_ext --plat-name win-arm64 build --plat-name win-arm64 bdist_wheel --plat-name win-arm64
19+
python -m build --wheel --config-setting=--build-option=build_ext --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=build --config-setting=--build-option=--plat-name=win-arm64 --config-setting=--build-option=bdist_wheel --config-setting=--build-option=--plat-name=win-arm64
2020
2121
Some modules require special SDKs or toolkits to build (eg, mapi/exchange),
2222
which often aren't available in CI. The build process treats them as optional -

win32/Demos/c_extension/setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# A sample distutils script to show to build your own
22
# extension module which extends pywintypes or pythoncom.
33
#
4-
# Use 'python setup.py build' to build this extension.
4+
# Use 'python -m build' to build this extension.
55
import os
66
from setuptools import Extension, setup
77
from sysconfig import get_paths

win32/Lib/pywintypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def __import_pywin32_system_module__(modname, globs):
8383

8484
# There are 2 site-packages directories - one "global" and one "user".
8585
# We could be in either, or both (but with different versions!). Factors include
86-
# virtualenvs, post-install script being run or not, `setup.py install` flags, etc.
86+
# virtualenvs, post-install script being run or not, `pip install` flags, etc.
8787

8888
# In a worst-case, it means, say 'python -c "import win32api"'
8989
# will not work but 'python -c "import pywintypes, win32api"' will,

0 commit comments

Comments
 (0)