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

Migrate to pep517 #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

zahlman
Copy link

@zahlman zahlman commented Jul 31, 2024

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 of setup conditional upon successful import of setuptools.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 using twine). 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 whether setup.py will demand doing something else important.) This way, building is done only once locally, and not repeatedly for/by each user.

zahlman added 5 commits July 30, 2024 19:48
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
@zahlman
Copy link
Author

zahlman commented Jul 31, 2024

Forgot to mention, it should also be possible to configure pyproject.toml to tell Setuptools what to put in the sdist, too (i.e., so that MANIFEST.in is no longer necessary. I didn't attempt this change locally, but here is the relevant documentation. Note that in particular, the license, readme etc. are included automatically, so the only real concern is the .dat files.

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.

RandomWords does not install under pip 24.2
1 participant