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

Move config from setup.cfg to pyproject.toml #7484

Merged
merged 5 commits into from Oct 26, 2023

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Oct 21, 2023

Follow on from #7171 which crated a minimal pyproject.toml specifying the [build-system].

Leave Flake8 config in setup.cfg because it doesn't support pyproject.toml: https://github.com/search?q=repo%3APyCQA%2Fflake8+pyproject.toml&type=issues

And we may be ditching Flake8 for Ruff anyway.

@hugovk hugovk changed the title Move tools config from setup.cfg to pyproject.toml Move config from setup.cfg to pyproject.toml Oct 21, 2023
@hugovk
Copy link
Member Author

hugovk commented Oct 21, 2023

Updated to move build config as well, this means we can delete setup.cfg. Flake8 config goes in .flake8.

We also need to bump setuptools for the Ubuntu 3.8 and 3.9 jobs because the pyroma test runs without an isolated build, and old setuptools returns "UNKNOWN" for the metadata.

pyproject.toml Outdated Show resolved Hide resolved
]
dynamic = [
"version",
]
Copy link
Member

@radarhere radarhere Oct 22, 2023

Choose a reason for hiding this comment

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

Looking at https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html#dynamic-metadata,
should this not be

dynamic = ["version", "readme"]

and move readme = "README.md" from earlier into

[tool.setuptools.dynamic]
version = {attr = "PIL.__version__"}
readme = {file = "README.md"}

later?

Copy link
Contributor

@nulano nulano Oct 22, 2023

Choose a reason for hiding this comment

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

The readme is listed in both examples at that page, but it looks to me like it should be in the dynamic section so that the content type can be specified (the default is text/x-rst):

readme = {file = "README.md", content-type = "text/markdown"}

Copy link
Member Author

Choose a reason for hiding this comment

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

Version:

Setting the version is good, it means we can move version=PILLOW_VERSION out of setup.py's setup().

README:

Despite the docs saying content-type defaults to text/x-rst, I did a test upload to https://test.pypi.org/project/pillow/10.2.0.dev0/ (files built using python -m build from the current state of the PR) and the README renders just fine, so I think it's fine?

PS @radarhere and other Pillow maintainers: if you like, I can add you to https://test.pypi.org/project/pillow/ in case you want to test anything out there. Just let me know your username (you need to create a new account there).

hugovk and others added 2 commits October 22, 2023 11:07
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
classifiers =
Development Status :: 6 - Mature
License :: OSI Approved :: Historical Permission Notice and Disclaimer (HPND)
Programming Language :: Python :: 3
Copy link
Member

Choose a reason for hiding this comment

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

Why is "Programming Language :: Python :: 3" not present in pyproject.toml?

Copy link
Member Author

Choose a reason for hiding this comment

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

pyproject-fmt removes it:
tox-dev/pyproject-fmt#106

@@ -986,7 +986,6 @@ def debug_build():

try:
setup(
version=PILLOW_VERSION,
Copy link
Member

Choose a reason for hiding this comment

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

Is there a way to query the version from setuptools instead of reading it from a file in get_version?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are 7 options at https://packaging.python.org/en/latest/guides/single-sourcing-package-version/

  1. Also reads from file
  2. I'm not too sure about those external build tools
  3. We're using something like this
  4. Also reads from file
  5. Moves version constant to setup.py, project code fetchs via importlib.metadata
  6. Import the version from src/PIL/__init__.py, but I'm not sure if we can import PIL before the build?
  7. Get the version number from SCM using setuptools_scm. I've used setuptools_scm in other projects, this might work.

But I suggest these could be topics for a followup.

@aclark4life
Copy link
Member

Out of curiosity is it possible to drop setup.py now too? I'm doing it over here: AcademySoftwareFoundation/OpenImageIO#4011. But I'm not exactly sure how it works. Maybe in a project without C extensions you don't need setup.py anymore.

@hugovk
Copy link
Member Author

hugovk commented Oct 26, 2023

Out of curiosity is it possible to drop setup.py now too? I'm doing it over here: AcademySoftwareFoundation/OpenImageIO#4011. But I'm not exactly sure how it works. Maybe in a project without C extensions you don't need setup.py anymore.

Pillow still needs it for building C extensions with setuptools, but pure Python projects can drop both setup.py and setup.cfg for a single pyproject.toml.

@hugovk hugovk merged commit 57c72b6 into python-pillow:main Oct 26, 2023
54 checks passed
@hugovk hugovk deleted the setup-to-pyproject branch October 26, 2023 11:06
@aclark4life
Copy link
Member

Well, the point was more that we could replace setuptools with scikit-build if we were so inclined, and I'm trying to gauge how inclined we are to do that. I'm also not following setuptools very closely anymore and wondering if there are any indications that we should prepare to exist without setuptools.

@radarhere
Copy link
Member

Investigating scikit-build, I found that it depends on setuptools and "is fundamentally just glue between the setuptools Python module and CMake".

That was confusing, but then I found https://github.com/scikit-build/scikit-build-core. I'm guessing that was what was meant?

@aclark4life
Copy link
Member

Correct, the newer one, used in the OIIO PR I referenced above.

@hugovk
Copy link
Member Author

hugovk commented Oct 26, 2023

I'm not necessarily against moving to something newer than setuptools if someone wants to experiment, but our setup.py is 1,013 lines long, so it might be not be an easy task! There's also PDM (I think this just calls setuptools) and meson-python.

I think setuptools is going to be around for a long time. It's still maintained, and they're working to modernise it, which sometimes brings the occasional rocky patch, but we've figured it out.

@aclark4life
Copy link
Member

PDM is what I used to convert OIIO's setup.py to pyproject.toml. I guess the best case scenario would be for setuptools to support C extensions without setup.py, but no idea of that's on the roadmap. I'll do some experiments!

@hugovk hugovk mentioned this pull request Oct 30, 2023
kraj pushed a commit to YoeDistro/meta-openembedded that referenced this pull request Apr 6, 2024
License-Update: Updated copyright year and clean up authors, contributors

* 0001-explicitly-set-compile-options.patch dropped because setup.cfg moved to pyproject.toml -> (python-pillow/Pillow#7484)

        Also, we can give the build option parameters as described in the documentation -> https://pillow.readthedocs.io/en/stable/installation/building-from-source.html#build-options
		Added build options to pass to build with using the variable PEP517_BUILD_OPTS so no need to create patch again.

* "python setup.py" and the use of "setup.py" as a command line tool are deprecated and upstream added a custom build backend to translate -C feature=disable style flags to the old --disable-feature style flags by prepending the build command (typically bdist_wheel) with a build_ext --disable-feature command which builds the extension modules before being added to a wheel. That backend uses the build_meta module of setuptools. The _CustomBuildMetaBackend class is a subclass of this module, adding custom behaviors and enabling settings specific to a particular project.

        https://github.com/python-pillow/Pillow/blob/10.3.0/_custom_build/backend.py

* Ptest tested on qemux86-64 and qemuarm64 with x11.

* Since no ptest error was encountered, python3-pillow has been moved from PTESTS_PROBLEMS_META_PYTHON to PTESTS_SLOW_META_PYTHON.

        Tests with SKIP are related to packages with explicitly disabled build options.

qemux86-64:

Testsuite summary
TOTAL: 4502
PASS: 4152
SKIP: 347
XFAIL: 2
FAIL: 0
XPASS: 1
ERROR: 0
DURATION: 904
END: /usr/lib/python3-pillow/ptest
2024-04-06T15:56
STOP: ptest-runner
TOTAL: 1 FAIL: 0

qemuarm64:

Testsuite summary
TOTAL: 4502
PASS: 4152
SKIP: 347
XFAIL: 2
FAIL: 0
XPASS: 1
ERROR: 0
DURATION: 674
END: /usr/lib/python3-pillow/ptest
2024-04-06T16:40
STOP: ptest-runner
TOTAL: 1 FAIL: 0

Changelog:

https://pillow.readthedocs.io/en/stable/releasenotes/10.3.0.html
https://pillow.readthedocs.io/en/stable/releasenotes/10.2.0.html

Signed-off-by: alperak <alperyasinak1@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
halstead pushed a commit to openembedded/meta-openembedded that referenced this pull request Apr 7, 2024
License-Update: Updated copyright year and clean up authors, contributors

* 0001-explicitly-set-compile-options.patch dropped because setup.cfg moved to pyproject.toml -> (python-pillow/Pillow#7484)

        Also, we can give the build option parameters as described in the documentation -> https://pillow.readthedocs.io/en/stable/installation/building-from-source.html#build-options
		Added build options to pass to build with using the variable PEP517_BUILD_OPTS so no need to create patch again.

* "python setup.py" and the use of "setup.py" as a command line tool are deprecated and upstream added a custom build backend to translate -C feature=disable style flags to the old --disable-feature style flags by prepending the build command (typically bdist_wheel) with a build_ext --disable-feature command which builds the extension modules before being added to a wheel. That backend uses the build_meta module of setuptools. The _CustomBuildMetaBackend class is a subclass of this module, adding custom behaviors and enabling settings specific to a particular project.

        https://github.com/python-pillow/Pillow/blob/10.3.0/_custom_build/backend.py

* Ptest tested on qemux86-64 and qemuarm64 with x11.

* Since no ptest error was encountered, python3-pillow has been moved from PTESTS_PROBLEMS_META_PYTHON to PTESTS_SLOW_META_PYTHON.

        Tests with SKIP are related to packages with explicitly disabled build options.

qemux86-64:

Testsuite summary
TOTAL: 4502
PASS: 4152
SKIP: 347
XFAIL: 2
FAIL: 0
XPASS: 1
ERROR: 0
DURATION: 904
END: /usr/lib/python3-pillow/ptest
2024-04-06T15:56
STOP: ptest-runner
TOTAL: 1 FAIL: 0

qemuarm64:

Testsuite summary
TOTAL: 4502
PASS: 4152
SKIP: 347
XFAIL: 2
FAIL: 0
XPASS: 1
ERROR: 0
DURATION: 674
END: /usr/lib/python3-pillow/ptest
2024-04-06T16:40
STOP: ptest-runner
TOTAL: 1 FAIL: 0

Changelog:

https://pillow.readthedocs.io/en/stable/releasenotes/10.3.0.html
https://pillow.readthedocs.io/en/stable/releasenotes/10.2.0.html

Signed-off-by: alperak <alperyasinak1@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants