-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Migrate to pep517 #16
Open
zahlman
wants to merge
5
commits into
tomislater:master
Choose a base branch
from
zahlman:migrate-to-pep517
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In Setuptools 72.0.0, `setuptools.command.test` was temporarily removed. This version of Setuptools was yanked, and 72.1.0 restored the functionality (it appears that the removal didn't follow the standard process, but this functionality has been deprecated for many years). The functionality will be removed in a future version (probably very soon) and that would break this `setup.py` as a result. This commit, as a first step, handles the `ImportError` that results when `setuptools.command.test` is removed, and only attempts to define the `PyTest` command (the only thing depending on it) when it's available. For more details, please see: pypa/setuptools#4519 Although many projects were affected by the change, this one was the unlucky "winner" of a popular Stack Overflow Q&A drawing attention to the general issue: https://stackoverflow.com/questions/78806100
A `pyproject.toml` file is created to represent project metadata, following the standards laid out in PEP 621 and implemented by modern Setuptools: https://peps.python.org/pep-0621/ Data which can be represented this way, and which is not specific to the Setuptools build system, has been moved across and removed from the `setup` keyword arguments.
Add spaces around equals signs, and use double-quotes for strings. This is the standard formatting for TOML that will be output by typical tools (although the other way is also valid).
`pyproject.toml` can also do basic configuration of Setuptools for building packages, as shown. Note that `include-package-data` is set as `True` by default when using `pyproject.toml`.
With the modern approach using `pyproject.toml`, it's not actually necessary to call `setup` to build the project, as long as all necessary information for wheel building is in `pyproject.toml` (which it is now). Therefore, the script now immediately bails out whenever `setuptools.command.test` is not available, and uses a minimal `setup` invocation when it is. Going forward, it is strongly recommended to remove `setup.py` entirely. A `setup.py` file is only required for projects that need to build extensions or have some other compelling reason to execute arbitrary code at build time. The interface implemented here - i.e. calling `setup.py test` - is deprecated, and has been for many years. Instead, consider using a shell alias to make the desired command (i.e. `python -m pytest --strict-markers --verbose --tb=long`) easier to use. For more details, please see: https://setuptools.pypa.io/en/latest/deprecated/commands.html
Forgot to mention, it should also be possible to configure |
This was referenced Jul 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This changeset migrates the project to the new standard for building projects, described in PEP 517 – A build-system independent format for source trees, and makes the implementation of the
PyTest
class and invocation ofsetup
conditional upon successful import ofsetuptools.command.test
.This Setuptools functionality has been deprecated for many years - and so has the general use of Setuptools as a general "project manager" with extensible functionality for testing/development/etc. Currently, Setuptools is only intended for use to build wheels from sdists, either explicitly via a frontend such as
build
or implicitly when installing a project with Pip.The work is split into several commits and the log offers a detailed rationale for each change, with citations of the relevant standards.
This fixes #15 , even for users who get stuck with
setuptools==72.0.0
.In addition to making this change, I strongly recommend building and distributing a wheel for the project. Pip also exposes this functionality directly: it's as easy as
python -m pip wheel .
in the root directory, which produces a.whl
file that can be uploaded to PyPI exactly like the sdist (e.g., by usingtwine
). Distributing the project this way is much more convenient for end users, as it skips a completely unnecessary "build" step for this pure-Python project. (Pip cannot install the files directly from an sdist tarball, because it can't know whethersetup.py
will demand doing something else important.) This way, building is done only once locally, and not repeatedly for/by each user.