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

Environments and dependency version specifiers don't work with workspaces #7821

Closed
chadrik opened this issue Sep 30, 2024 · 4 comments · Fixed by #7824
Closed

Environments and dependency version specifiers don't work with workspaces #7821

chadrik opened this issue Sep 30, 2024 · 4 comments · Fixed by #7824
Assignees
Labels
question Asking for clarification or support

Comments

@chadrik
Copy link

chadrik commented Sep 30, 2024

I ran into an issue with locking and version specifiers similar to #4668 and #4669, but the fix there of creating environments for different python versions does not work with workspaces.

Here's how I reproduced this.

I started with this pyproject.toml and confirmed that it works with uv==0.4.17

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

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

[tool.uv]
environments = ["python_version < '3.8'", "python_version >= '3.8'"]
$ uv lock
Using CPython 3.8.19 interpreter at: /usr/local/opt/[email protected]/bin/python3.8
Resolved 2 packages in 3ms

Note that this requires the tool.uv.environment setting recommended in #4668

Next I setup my repo using workspaces, with a folder structure like this:

./
  project-foo/
    pyproject.toml
  pyproject.toml

The root pyproject.toml looks like this:

[tool.uv.workspace]
members = [
    "project-foo",
]

[tool.uv.sources]
foo = { workspace = true }

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

The child looks like this (same as before but without the uv.tool.environment setting):

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

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

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

Locking from the root of the workspace fails:

$ uv lock
Using CPython 3.8.19 interpreter at: /usr/local/opt/[email protected]/bin/python3.8
  × No solution found when resolving dependencies:
  ╰─▶ Because the requested Python version (>=3.7) does not satisfy Python>=3.8 and your project depends on types-psutil{python_full_version
      >= '3.8'}==6.0.0.20240901, we can conclude that your project's requirements are unsatisfiable.

I made a repo to demonstrate: https://github.com/chadrik/uv-tests

These are some PRs mentioned that could be related:

Is there a way to indicate that a dependency simply should not be installed on certain versions of python?

@charliermarsh
Copy link
Member

Thanks. That repo is 404ing for me -- any chance the URL is not quite right?

@charliermarsh
Copy link
Member

(Working now.)

@charliermarsh charliermarsh self-assigned this Sep 30, 2024
@charliermarsh
Copy link
Member

Ah sorry. You need to add a [project] table to the root pyproject.toml:

diff --git a/pyproject.toml b/pyproject.toml
index 504c40f..f0b42da 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,3 +1,7 @@
+[project]
+name = "root"
+version = "0.0.1"
+
 [tool.uv.workspace]
 members = [
     "project-foo",

@charliermarsh charliermarsh added the question Asking for clarification or support label Oct 1, 2024
@charliermarsh
Copy link
Member

I'll lift this restriction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants