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

Python version limited requirement in universal locking #4668

Closed
davidfritzsche opened this issue Jun 30, 2024 · 15 comments · Fixed by #8628 · May be fixed by #6143
Closed

Python version limited requirement in universal locking #4668

davidfritzsche opened this issue Jun 30, 2024 · 15 comments · Fixed by #8628 · May be fixed by #6143
Assignees
Labels
bug Something isn't working resolver Related to the package resolver

Comments

@davidfritzsche
Copy link
Contributor

With uv 0.2.18 the following fails

$ echo 'uv;python_version>="3.8"' | uv pip compile -p 3.7 --universal -
warning: uv is only compatible with Python 3.8+, found Python 3.7.17.
  × No solution found when resolving dependencies:

Which on one hand makes sense, as there really is no version of uv supporting Python 3.7. On the other hand, uv==X; python_version>="3.8" could be installed under Python 3.7 for any version X.

In non-universal locking, uv;python_version>="3.8" can be compiled for Python 3.7:

$ echo 'uv;python_version>="3.8"' | uv pip compile -p 3.7 -
warning: uv is only compatible with Python 3.8+, found Python 3.7.17.
Resolved 0 packages in 0.77ms
# This file was autogenerated by uv via the following command:
#    uv pip compile -p 3.7 -
@charliermarsh
Copy link
Member

Oh thank you, I think this is the same as #4669 -- sorry, I missed that you created this.

@charliermarsh
Copy link
Member

I'm going to merge into #4669. Good bug!

@charliermarsh charliermarsh closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2024
@charliermarsh charliermarsh added bug Something isn't working resolver Related to the package resolver preview Experimental behavior labels Jun 30, 2024
@charliermarsh charliermarsh reopened this Jul 1, 2024
@charliermarsh
Copy link
Member

Re-opening because this case is a little different than the NumPy one and they'll have separate PRs.

@houbie
Copy link

houbie commented Aug 5, 2024

I'm facing a related issue: using python 3.9, uv pip install pdm correctly installs pdm version 2.17.3, but echo 'pdm==2.17.3'| uv pip compile --universal - fails:

(px-uvdir) % echo 'pdm==2.17.3'| uv pip compile --universal -
  × No solution found when resolving dependencies:
  ╰─▶ Because only the following versions of truststore{python_version >= '3.10'} are available:
          truststore{python_version >= '3.10'}==0.1.0
          truststore{python_version >= '3.10'}==0.2.0
          truststore{python_version >= '3.10'}==0.3.0
          truststore{python_version >= '3.10'}==0.4.0
          truststore{python_version >= '3.10'}==0.5.0
          truststore{python_version >= '3.10'}==0.6.0
          truststore{python_version >= '3.10'}==0.6.1
          truststore{python_version >= '3.10'}==0.7.0
          truststore{python_version >= '3.10'}==0.8.0
          truststore{python_version >= '3.10'}==0.9.0
          truststore{python_version >= '3.10'}==0.9.1
      and the requested Python version (>=3.9.17) does not satisfy Python>=3.10, we can conclude that any of:
          truststore{python_version >= '3.10'}<0.9.0
          truststore{python_version >= '3.10'}>0.9.0
       are incompatible.
      And because truststore{python_version >= '3.10'}==0.9.0 was yanked (reason: Doesn't work for CPython 3.13, upgrade to 0.9.1), we can conclude that all versions of truststore{python_version >= '3.10'} are incompatible.
      And because pdm==2.17.3 depends on truststore{python_version >= '3.10'} and you require pdm==2.17.3, we can conclude that the requirements are unsatisfiable.

pdm has a dependency on truststore Requires-Dist: truststore; python_version >= "3.10"
uv pip compile should retain this dependency with the python constraint instead of failing on it

@charliermarsh
Copy link
Member

@houbie -- Think that's the same as #4668.

@charliermarsh
Copy link
Member

On main there's now a workaround for this:

[project]
name = "foo"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.7"
dependencies = ["uv ; python_version >= '3.8'"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
environments = ["python_version < '3.8'", "python_version >= '3.8'"]

@DanCardin
Copy link

I'm encountering something similar, where the environments workaround doesn't appear to work. It works with only the "numpy >= 2.0; python_version >= '3.9'" dependency, but not with certain other dependencies in combination.

[project]
name = "foo"
version = "0.0.0"
description = ""
requires-python = ">=3.8,<4"
dependencies = [
  "pydantic",
  "numpy >= 2.0; python_version >= '3.9'",
]

[tool.uv]
environments = ["python_version < '3.9'", "python_version >= '3.9'"]

This ^ will attempt to install numpy (which then fails for me), which i think it shouldnt even be attempting.

I'm not sure what significance pydantic has here, it only depends on pydantic-core, typing-extensions and annotated-types. And explicitly stating those dependencies (locked to the locked versions) individually instead doesn't fail.

@charliermarsh
Copy link
Member

Can you clarify what the issue is? It's attempting to install NumPy on which Python versions? (I can uv lock that successfully.)

@DanCardin
Copy link

oh right sorry! uv sync -p 3.8 fails trying to install numpy (when it shouldn't be), uv sync -p 3.9 succeeds and does.

admittedly the failing part is because it's trying to build the wheel and i dont have the requirements necessary, but the point is that it's installing numpy when it shouldn't anyway.

@mkniewallner
Copy link
Contributor

mkniewallner commented Aug 31, 2024

On main there's now a workaround for this:

[project]
name = "foo"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.7"
dependencies = ["uv ; python_version >= '3.8'"]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.uv]
environments = ["python_version < '3.8'", "python_version >= '3.8'"]

It looks like the workaround suggested here does not work anymore on 0.4.1, with the changes made in #6841:

$ uv lock
error: Environment markers `python_full_version >= '3.8'` don't overlap with Python requirement `>=3.7`

Since the workaround was suggested a few weeks ago, is there maybe a better way to work around the issue now?

@charliermarsh
Copy link
Member

If that's not working, it looks like a bug. Let me take a look.

@charliermarsh
Copy link
Member

Apologies @mkniewallner, really dumb bug: #6902

@DanCardin
Copy link

Fwiw, if anyone else runs into #4668 (comment) (because it was blocking by ability to adopt uv), a newer release of uv (0.4.20), given the referenced pyproject.toml, produces

  × No solution found when resolving dependencies for split (python_full_version >= '3.9'):
  ╰─▶ Because the requested Python version (>=3.8, <4) does not satisfy Python>=3.10 and the requested Python version (>=3.8, <4) does not satisfy
      Python>=3.9,<3.10, we can conclude that Python>=3.9 is incompatible.
      And because only the following versions of numpy{python_full_version >= '3.9'} are available:
          numpy{python_full_version >= '3.9'}<=2.0.2
          numpy{python_full_version >= '3.9'}>=2.1.0
      we can conclude that all of:
          numpy{python_full_version >= '3.9'}>=2.0.0,<2.1.0
          numpy{python_full_version >= '3.9'}>2.1.0,<2.1.1
          numpy{python_full_version >= '3.9'}>2.1.1,<2.1.2
          numpy{python_full_version >= '3.9'}>2.1.2
       are incompatible.
      And because the requested Python version (>=3.8, <4) does not satisfy Python>=3.10 and your project depends on numpy{python_full_version >=
      '3.9'}>=2.0, we can conclude that your project's requirements are unsatisfiable.

I took that to imply that I need to match the upper bound with the upper bound of my project: environments = ["python_version < '3.9'", "python_version >= '3.9' and python_version < '4'"], and that solved the issue, at least in the newer version of uv.

ashb added a commit to apache/airflow that referenced this issue Oct 21, 2024
…#43227)

Just having the python_version requirement doesn't seem to correctly make uv
"fork" the resolver path (Charlie's words/terms), so we either need to specify
both module versions here. The other option that could work is putting this in
our pyproject.toml

```
[tool.uv]
environments = ["python_version >= '3.10'", "python_version < '3.10'"]
```

But having both versions specified keeps the fix localized into the provider
so I have chosen this approach.

This is likely why the exclued-python-version setting we already had wasn't
working for uv sync.


astral-sh/uv#4668
harjeevanmaan pushed a commit to harjeevanmaan/airflow that referenced this issue Oct 23, 2024
…apache#43227)

Just having the python_version requirement doesn't seem to correctly make uv
"fork" the resolver path (Charlie's words/terms), so we either need to specify
both module versions here. The other option that could work is putting this in
our pyproject.toml

```
[tool.uv]
environments = ["python_version >= '3.10'", "python_version < '3.10'"]
```

But having both versions specified keeps the fix localized into the provider
so I have chosen this approach.

This is likely why the exclued-python-version setting we already had wasn't
working for uv sync.


astral-sh/uv#4668
PaulKobow7536 pushed a commit to PaulKobow7536/airflow that referenced this issue Oct 24, 2024
…apache#43227)

Just having the python_version requirement doesn't seem to correctly make uv
"fork" the resolver path (Charlie's words/terms), so we either need to specify
both module versions here. The other option that could work is putting this in
our pyproject.toml

```
[tool.uv]
environments = ["python_version >= '3.10'", "python_version < '3.10'"]
```

But having both versions specified keeps the fix localized into the provider
so I have chosen this approach.

This is likely why the exclued-python-version setting we already had wasn't
working for uv sync.


astral-sh/uv#4668
@charliermarsh
Copy link
Member

This should "just work" without any workarounds in the next version (see: #8628).

@potiuk
Copy link

potiuk commented Oct 28, 2024

This should "just work" without any workarounds in the next version (see: #8628).

Cool . We are getting way closer now with uv being the default tool for Airflow development.

ellisms pushed a commit to ellisms/airflow that referenced this issue Nov 13, 2024
…apache#43227)

Just having the python_version requirement doesn't seem to correctly make uv
"fork" the resolver path (Charlie's words/terms), so we either need to specify
both module versions here. The other option that could work is putting this in
our pyproject.toml

```
[tool.uv]
environments = ["python_version >= '3.10'", "python_version < '3.10'"]
```

But having both versions specified keeps the fix localized into the provider
so I have chosen this approach.

This is likely why the exclued-python-version setting we already had wasn't
working for uv sync.


astral-sh/uv#4668
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working resolver Related to the package resolver
Projects
No open projects
Status: Backlog
7 participants