Skip to content

Allow for additional constraints on dependencies used in build environments #10299

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

Open
zahlman opened this issue Mar 25, 2025 · 4 comments · May be fixed by #10388
Open

Allow for additional constraints on dependencies used in build environments #10299

zahlman opened this issue Mar 25, 2025 · 4 comments · May be fixed by #10388
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged

Comments

@zahlman
Copy link

zahlman commented Mar 25, 2025

Issue Kind

Brand new capability

Description

When packages are installed via poetry install (or, I assume, poetry sync), in cases where a source distribution must be used, Poetry creates an isolated build environment, following requirements specified by the package. For various historical reasons, it's very common for the requirements to be, implicitly, "the latest version of Setuptools". Since Setuptools may have breaking changes, and may be updated after the release of the package to be installed, this carries the risk of causing the build to fail.

To avoid the problem, Poetry should provide some form of override to restrict the version of the build-time dependencies used to build the project's dependencies.

This could, for example, take the form of a new pyproject.toml section along the lines of

[tool.poetry.build-constraints]
some_dependency = { setuptools = "<78" }

Impact

The recent kerfuffle around pypa/setuptools#4910 demonstrates clearly, IMO, that #4511 wasn't given sufficient consideration. Updating metadata for Python projects is difficult at the best of times, and there are still tons of legacy projects out there that don't even have a pyproject.toml file in which to specify a Setuptools version. (Trying to do so within setup.py is problematic, of course, because setuptools has to be imported before setup can be called.)

This isn't the first time there has been such a disruption; pypa/setuptools#4519 was the same basic kind of problem appearing in Setuptools 72 (and, notably, both changes were relevant to Requests: psf/requests#6775 psf/requests#6920).

Going forward, Setuptools should be expected to implement (or at least try to implement, until community backlash forces a reversion) more removals of deprecated features - after all, that's what deprecation is for. Every new major version of Setuptools brings the risk of breaking large numbers of packages which don't upper-cap versions for their stated build dependencies. Even when those packages use a pyproject.toml, they might not have a [build-system] table, as long as Setuptools is the community-expected default (described as a lowercase "should" in PEP 517). This problem will therefore keep coming up as long as users don't have a clean way to override overly-permissive build requirement specifications.

This problem potentially impacts all build backends, not just Setuptools. While maintainers are often advised not to upper-cap Python dependencies, it's unclear whether this is good advice for build dependencies. Flit documentation, for example, advises using such a cap, but users are certainly not under any obligation to do so.

Workarounds

Pip can apparently handle this through an environment variable (e.g. pypa/setuptools#4910 (comment) ).

@zahlman zahlman added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Mar 25, 2025
@radoering
Copy link
Member

I agree that such a setting makes sense.

@rzuckerm
Copy link

rzuckerm commented May 1, 2025

I also logged this issue: pypa/build#890

@smoy
Copy link

smoy commented May 9, 2025

Adding an example of how uv provides the functionality

@radoering radoering linked a pull request May 11, 2025 that will close this issue
2 tasks
@radoering
Copy link
Member

I implemented the proposal in #10388. Please try it out and give feedback if it works for you. (See https://python-poetry.org/docs/#installing-with-pipx for how to install Poetry from git.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Feature requests/implementations status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants