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

Fix Windows build with pyproject.toml #7230

Merged
merged 17 commits into from Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions .appveyor.yml
Expand Up @@ -20,6 +20,7 @@ environment:

install:
- '%PYTHON%\%EXECUTABLE% --version'
- '%PYTHON%\%EXECUTABLE% -m pip install --upgrade pip'
- curl -fsSL -o pillow-depends.zip https://github.com/python-pillow/pillow-depends/archive/main.zip
- curl -fsSL -o pillow-test-images.zip https://github.com/python-pillow/test-images/archive/main.zip
- 7z x pillow-depends.zip -oc:\
Expand All @@ -37,10 +38,9 @@ install:
- path C:\pillow\winbuild\build\bin;%PATH%

build_script:
- ps: |
c:\pillow\winbuild\build\build_pillow.cmd install
$host.SetShouldExit(0)
- cd c:\pillow
- winbuild\build\build_env.cmd
- '%PYTHON%\%EXECUTABLE% -m pip install -v -C raqm=vendor -C fribidi=vendor .'
- '%PYTHON%\%EXECUTABLE% selftest.py --installed'

test_script:
Expand All @@ -62,18 +62,15 @@ cache:
- '%LOCALAPPDATA%\pip\Cache'

artifacts:
- path: pillow\dist\*.egg
- path: pillow\*.egg
name: egg
Comment on lines +65 to 66
Copy link
Member

@hugovk hugovk Jun 30, 2023

Choose a reason for hiding this comment

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

The egg format is newly deprecated on PyPI:

I know we're not uploading these, but do we need them here?

Suggested change
- path: pillow\*.egg
name: egg

(Non-blocking for merge.)

- path: pillow\dist\*.wheel
- path: pillow\*.whl
name: wheel

before_deploy:
- cd c:\pillow
- '%PYTHON%\%EXECUTABLE% -m pip install wheel'
- cd c:\pillow\winbuild\
- c:\pillow\winbuild\build\build_pillow.cmd bdist_wheel
- cd c:\pillow
- ps: Get-ChildItem .\dist\*.* | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
- '%PYTHON%\%EXECUTABLE% -m pip wheel -v -C raqm=vendor -C fribidi=vendor .'
- ps: Get-ChildItem .\*.whl | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }

deploy:
provider: S3
Expand Down
17 changes: 9 additions & 8 deletions .github/workflows/test-windows.yml
Expand Up @@ -57,8 +57,8 @@ jobs:
- name: Print build system information
run: python3 .github/workflows/system-info.py

- name: python3 -m pip install setuptools wheel pytest pytest-cov pytest-timeout defusedxml
run: python3 -m pip install setuptools wheel pytest pytest-cov pytest-timeout defusedxml
- name: python3 -m pip install pytest pytest-cov pytest-timeout defusedxml
run: python3 -m pip install pytest pytest-cov pytest-timeout defusedxml

- name: Install dependencies
id: install
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Prepare build
if: steps.build-cache.outputs.cache-hit != 'true'
run: |
& python.exe winbuild\build_prepare.py -v --python $env:pythonLocation
& python.exe winbuild\build_prepare.py -v
shell: pwsh

- name: Build dependencies / libjpeg-turbo
Expand Down Expand Up @@ -157,9 +157,9 @@ jobs:

- name: Build Pillow
run: |
$FLAGS=""
if ('${{ github.event_name }}' -ne 'pull_request') { $FLAGS="--disable-imagequant" }
& winbuild\build\build_pillow.cmd $FLAGS install
$FLAGS="-C raqm=vendor -C fribidi=vendor"
if ('${{ github.event_name }}' -ne 'pull_request') { $FLAGS+=" -C imagequant=disable" }
cmd /c "winbuild\build\build_env.cmd && $env:pythonLocation\python.exe -m pip install -v $FLAGS ."
& $env:pythonLocation\python.exe selftest.py --installed
shell: pwsh

Expand Down Expand Up @@ -223,15 +223,16 @@ jobs:
)
)
for /f "tokens=3 delims=/" %%a in ("${{ github.ref }}") do echo dist=dist-%%a >> %GITHUB_OUTPUT%
winbuild\\build\\build_pillow.cmd --disable-imagequant bdist_wheel
call winbuild\\build\\build_env.cmd
%pythonLocation%\python.exe -m pip wheel -v -C raqm=vendor -C fribidi=vendor -C imagequant=disable .
shell: cmd

- name: Upload wheel
uses: actions/upload-artifact@v3
if: "github.event_name != 'pull_request'"
with:
name: ${{ steps.wheel.outputs.dist }}
path: dist\*.whl
path: "*.whl"

- name: Upload fribidi.dll
if: "github.event_name != 'pull_request' && matrix.python-version == 3.11"
Expand Down
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -46,13 +46,24 @@ repos:
hooks:
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml

- repo: https://github.com/sphinx-contrib/sphinx-lint
rev: v0.6.7
hooks:
- id: sphinx-lint

- repo: https://github.com/tox-dev/pyproject-fmt
rev: 0.12.1
hooks:
- id: pyproject-fmt

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.13
hooks:
- id: validate-pyproject

- repo: https://github.com/tox-dev/tox-ini-fmt
rev: 1.3.0
hooks:
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
@@ -1,4 +1,9 @@
[build-system]
requires = ["setuptools >= 40.8.0", "wheel"]
build-backend = "backend"
backend-path = ["_custom_build"]
requires = [
"setuptools>=67.8",
"wheel",
]
backend-path = [
"_custom_build",
]
10 changes: 1 addition & 9 deletions setup.py
Expand Up @@ -137,7 +137,6 @@ class RequiredDependencyException(Exception):


PLATFORM_MINGW = os.name == "nt" and "GCC" in sys.version
PLATFORM_PYPY = hasattr(sys, "pypy_version_info")


def _dbg(s, tp=None):
Expand Down Expand Up @@ -848,14 +847,7 @@ def build_extensions(self):
if struct.unpack("h", b"\0\1")[0] == 1:
defs.append(("WORDS_BIGENDIAN", None))

if (
sys.platform == "win32"
and sys.version_info < (3, 9)
and not (PLATFORM_PYPY or PLATFORM_MINGW)
):
defs.append(("PILLOW_VERSION", f'"\\"{PILLOW_VERSION}\\""'))
else:
defs.append(("PILLOW_VERSION", f'"{PILLOW_VERSION}"'))
defs.append(("PILLOW_VERSION", f'"{PILLOW_VERSION}"'))

self._update_extension("PIL._imaging", libs, defs)

Expand Down
6 changes: 3 additions & 3 deletions winbuild/README.md
Expand Up @@ -18,12 +18,12 @@ The following is a simplified version of the script used on AppVeyor:
```
set PYTHON=C:\Python38\bin
cd /D C:\Pillow\winbuild
C:\Python39\bin\python.exe build_prepare.py -v --depends=C:\pillow-depends
%PYTHON%\python.exe build_prepare.py -v --depends=C:\pillow-depends
build\build_dep_all.cmd
build\build_pillow.cmd install
cd ..
%PYTHON%\python.exe -m pip install -v -C raqm=vendor -C fribidi=vendor .
path C:\Pillow\winbuild\build\bin;%PATH%
%PYTHON%\python.exe selftest.py
%PYTHON%\python.exe -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
build\build_pillow.cmd bdist_wheel
%PYTHON%\python.exe -m pip wheel -v -C raqm=vendor -C fribidi=vendor .
```
36 changes: 17 additions & 19 deletions winbuild/build.rst
Expand Up @@ -42,11 +42,10 @@ Run ``build_prepare.py`` to configure the build::

usage: winbuild\build_prepare.py [-h] [-v] [-d PILLOW_BUILD]
[--depends PILLOW_DEPS]
[--architecture {x86,x64,ARM64}]
[--python PYTHON] [--executable EXECUTABLE]
[--nmake] [--no-imagequant] [--no-fribidi]
[--architecture {x86,x64,ARM64}] [--nmake]
[--no-imagequant] [--no-fribidi]

Download dependencies and generate build scripts for Pillow.
Download and generate build scripts for Pillow dependencies.

options:
-h, --help show this help message and exit
Expand All @@ -58,17 +57,13 @@ Run ``build_prepare.py`` to configure the build::
'winbuild\depends')
--architecture {x86,x64,ARM64}
build architecture (default: same as host Python)
--python PYTHON Python install directory (default: use host Python)
--executable EXECUTABLE
Python executable (default: use host Python)
--nmake build dependencies using NMake instead of Ninja
--no-imagequant skip GPL-licensed optional dependency libimagequant
--no-fribidi, --no-raqm
skip LGPL-licensed optional dependency FriBiDi

Arguments can also be supplied using the environment variables PILLOW_BUILD,
PILLOW_DEPS, ARCHITECTURE, PYTHON, EXECUTABLE. See winbuild\build.rst for more
information.
PILLOW_DEPS, ARCHITECTURE. See winbuild\build.rst for more information.

**Warning:** The build directory is wiped when ``build_prepare.py`` is run.

Expand All @@ -86,14 +81,16 @@ or run the individual scripts in order to build each dependency separately.
Building Pillow
---------------

Once the dependencies are built, run
``winbuild\build\build_pillow.cmd install`` to build and install
Pillow for the selected version of Python.
``winbuild\build\build_pillow.cmd bdist_wheel`` will build wheels
instead of installing Pillow.
Once the dependencies are built, make sure the required environment variables
are set by running ``winbuild\build\build_env.cmd`` and install Pillow with pip::

You can also use ``winbuild\build\build_pillow.cmd --inplace develop`` to build
and install Pillow in develop mode (instead of ``python3 -m pip install --editable``).
winbuild\build\build_env.cmd
python.exe -m pip install -v -C raqm=vendor -C fribidi=vendor .

To build a wheel instead, run::

winbuild\build\build_env.cmd
python.exe -m pip wheel -v -C raqm=vendor -C fribidi=vendor .

Testing Pillow
--------------
Expand All @@ -112,11 +109,12 @@ The following is a simplified version of the script used on AppVeyor::

set PYTHON=C:\Python38\bin
cd /D C:\Pillow\winbuild
C:\Python39\bin\python.exe build_prepare.py -v --depends C:\pillow-depends
%PYTHON%\python.exe build_prepare.py -v --depends C:\pillow-depends
build\build_dep_all.cmd
build\build_pillow.cmd install
build\build_env.cmd
cd ..
%PYTHON%\python.exe -m pip install -v -C raqm=vendor -C fribidi=vendor .
path C:\Pillow\winbuild\build\bin;%PATH%
%PYTHON%\python.exe selftest.py
%PYTHON%\python.exe -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests
build\build_pillow.cmd bdist_wheel
%PYTHON%\python.exe -m pip wheel -v -C raqm=vendor -C fribidi=vendor .