-
Notifications
You must be signed in to change notification settings - Fork 891
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
Weird dependency resolving (for magika → numpy → distutils) #6911
Comments
TL;DR: I want to have this pyproject: # pyproject.toml
[project]
name = "mytool"
requires-python = ">=3.8"
dependencies = [
"magika>=0.5.1; python_version < '3.13'",
] resolve to this:
You can do this manually with PDM: pdm lock --python="<3.9"
pdm lock --python=">=3.9,<3.13" --append
pdm lock --python=">=3.13" --append But since |
In general we try to use the fewest number of versions to satisfy dependencies. But I think we should consider adding an alternate strategy where we try to use the newest versions for each environment. |
Something like |
There is perhaps more then one thing going on in this report. The failure to solve the case |
Fact is, for my problem it's not really required, as both the current and the desired approach use the same amount of dependencies. The only difference is "two magikas, one numpy" versus "one magika, two numpys". Maybe the strategy should consider how deep the dependencies are? Although, picking the "shallowest" is not necessarily the best dedupe strategy... 🤔 |
By the way, there actually is a way to instruct uv to get the exact solve you want here, but it also needs #6268 to work properly: [project]
name = "mytool"
version = "0.0.1"
requires-python = ">=3.8"
dependencies = [
"magika>=0.5.1; python_version < '3.13'",
]
[tool.uv]
environments = [
"python_version >= '3.13'",
"python_version >= '3.9' and python_version < '3.13'",
"python_version < '3.9'"
] (Beware, I'm sharing this even though it will not generate the correct resolution for Python 3.8 until #6268 merges.) |
I believe both are merged in uv 0.4.4, but still uv does not find a solution for "magika==0.5.1"
|
Thank you for following up, I appreciate it. |
Thanks, I see the bug here. |
My issue is similar to the one described in #6509, but I wanted to dig deeper, and I really fail to understand how the resolver works.
Description
I am working on a CLI tool, which depends on
magika
, which is a file detection software with deep learning. I want my tool to be available for every Python starting with 3.8. Magika does not support Python 3.13, and I want to handle it gracefully, so I only install it when the version of Python is under 3.13.I then want to lock and sync the dependencies, but
uv lock
fails because it fails to find distutils.Problem
The comments in #6509 correctly suggest that the numpy version is too old for the environment, as
distutils
is gone from 3.12. Alas, I do not understand why it resolves to this version in the first place.The pyproject.toml from above defined the range for my CLI to be
>=3.8
, and it depends onmagika
if the version is<3.13
. So, just from this I expect at least two resolution markers: "below 3.13" and "3.13 and above".magika itself does have some variable dependencies.
magika==0.5.0
has the following in its wheel's metadata:So, For every Python between 3.8 and 3.11, use any numpy older than 1.24.24.
magika==0.5.1
added support for Python 3.12, with the following metadata:So, now it says: use any numpy older than 1.24.24, unless you are above 3.9, in which case it's stricter.
Expected behaviour
Based on this, I expect three different lockfile resolutions for my package:
Python
>=3.8,<3.9
aka3.8.*
Python
>=3.9,<3.13
Python
>=3.13
This looks easy (at least for me). Just take the latest
magika==0.5.1
(it supports 3.8), and take numpy 1.24 for Python 3.8 and 1.26 for anything else.Actual behaviour
This is not what happens, though. uv.lock does define resolution markers that I expect:
But then, it weirdly decides to use an older magika version for the newer Pythons:
Which then proceeds to only pull
numpy==1.24.4
, as it theoretically satisfies both ranges:I kinda understand why it might do this; after all, we want as little packages as possible to simplify the lock file, but isn't it a better idea to use the newer package whenever possible? I assume one can say that numpy is at fault for not releasing a patch for 1.24 that would specify that it does not support Python 3.12, but isn't there a different way to solve this?
Things I've tried
Set Python
<3.13
formytool
If I tell that my whole too does not support Python 3.13,
uv
just resolves to the latestmagika==0.5.1
and installs without problem. It also correctly locks two numpy versions: 1.24 for Python 3.8 and 1.26 for everything elseSet
magika>=0.5.1
If I explicitly request the latest version of magika, uv can't lock, giving me this error:
I'm surprised to read that "
magika{python_full_version < '3.13'}==0.5.1
depends onnumpy{python_full_version >= '3.9' and python_full_version < '3.13'}>=1.26,<2.0
". Sure, it does, but it also does depend onnumpy{python_full_version >= '3.8' and python_full_version < '3.9'}>=1.24,<2.0
. Can't it use it for "the requested Python version (>=3.8)"?Environment
uv platform: macOS 13.6.9 Ventura, Python 3.12.5 from python.org
uv version:
uv 0.4.1 (Homebrew 2024-08-30)
I had troubles searching for similar issues, as I didn't know what keywords to use; sorry, if this turns out to be a duplicate!
The text was updated successfully, but these errors were encountered: