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

Add a --universal-strategy-like setting to the resolver #7190

Closed
charliermarsh opened this issue Sep 8, 2024 · 1 comment · Fixed by #9868
Closed

Add a --universal-strategy-like setting to the resolver #7190

charliermarsh opened this issue Sep 8, 2024 · 1 comment · Fixed by #9868
Assignees
Labels
resolver Related to the package resolver

Comments

@charliermarsh
Copy link
Member

In the universal resolver, we prioritize solving for as few versions as possible. Sometimes, users instead want to get the newest possible version for every fork (e.g., they'd prefer getting the newest versions of foo for Python 3.10+, even if it means they have two versions of foo in the lockfile, one for Python 3.9 and earlier, and one for Python 3.10 and later).

(--universal-strategy is obviously a bad name.)

One implementation of this would be to ignore preferences from other forks.

@henryiii
Copy link
Contributor

henryiii commented Oct 29, 2024

I'd even think this might be a nice default. Currently, the following simple example:

$ mkdir example
$ cd example
$ cat > pyproject.toml << EOL
[project]
name = "example"
version = "0.1"
requires-python = ">=3.8"
dependencies = ["numpy"]
EOL
$ uv run python
Resolved 2 packages in 7ms
error: Failed to prepare distributions
  Caused by: Failed to download and build `numpy==1.24.4`
  Caused by: Build backend failed to determine requirements with `build_wheel()` (exit status: 1)

[stderr]
Traceback (most recent call last):
  File "<string>", line 8, in <module>
  File "/Users/henryschreiner/.cache/uv/builds-v0/.tmpjYjj2d/lib/python3.12/site-packages/setuptools/__init__.py", line 10, in <module>
    import distutils.core
ModuleNotFoundError: No module named 'distutils'
  Caused by: distutils was removed from the standard library in Python 3.12. Consider adding a constraint (like `numpy >1.24.4`) to avoid building a version of numpy that depends on distutils.

will break on Python 3.12 and newer. Any package that supports a narrower range than you do (and packages should be allowed to stop supporting old Python versions) will cause you do never get updates, and updates are often required for new Python versions.

This is one of the biggest drawbacks of a universal solver, as most users starting out don't realize that "dependencies = ["numpy"]` isn't going to give them the latest version on the version of Python they are running. I think this would really reduce the friction when starting out.

See #8492 also.

@charliermarsh charliermarsh self-assigned this Oct 29, 2024
charliermarsh added a commit that referenced this issue Dec 13, 2024
## Summary

This PR makes the behavior in #9827
the default: we try to select the latest supported package version for
each supported Python version, but we still optimize for choosing fewer
versions when stratifying by platform.

However, you can opt out with `--fork-strategy fewest`.

Closes #7190.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resolver Related to the package resolver
Projects
None yet
2 participants