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

uv fails to parse pyproject.toml when using Hatchling's {root:uri} for dependencies #2475

Closed
object-Object opened this issue Mar 15, 2024 · 6 comments · Fixed by #2492
Closed
Assignees
Labels
compatibility Compatibility with a specification or another tool great writeup A wonderful example of a quality contribution 💜

Comments

@object-Object
Copy link

Hatchling includes a feature that allows specifying local dependencies relative to a project's root directory using the following syntax:

dependencies = [
    "<NAME> @ {root:uri}/pkg_inside_project"
]

uv fails to install projects that are using this feature, even if only used in an optional dependency that is not selected.

Reproduction steps

To reproduce, create this file structure:

/pyproject.toml

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

[project]
name = "project"
version = "0.1.0"
# NOTE: error also occurs if using this instead of optional-dependencies
# dependencies = [
#     "subproject @ {root:uri}/subproject",
# ]

[project.optional-dependencies]
local = [
    "subproject @ {root:uri}/subproject",
]

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build]
include = ["*"]

/subproject/pyproject.toml

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

[project]
name = "subproject"
version = "0.1.0"

[tool.hatch.build]
include = ["*"]

Then run these commands:

uv pip install -e . OR uv pip install -e .[local]

error: Failed to build editables                                                                                                                    
  Caused by: Failed to build editable: file:///C:/Users/object/test/uv-hatch-bug
  Caused by: Invalid pyproject.toml
  Caused by: TOML parse error at line 8, column 16
  |
8 | dependencies = [
  |                ^^^^^^^^^^^^^^^^^
relative path without a working directory: {root:uri}/subproject
subproject @ {root:uri}/subproject
             ^^^^^^^^^^^^^^^^^^^^^

pip install -e .

Obtaining file:///C:/Users/object/test/uv-hatch-bug
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Building wheels for collected packages: project
  Building editable for project (pyproject.toml) ... done
  Created wheel for project: filename=project-0.1.0-py2.py3-none-any.whl size=992 sha256=11807b7ff67c86dc454cef307552ec3d8ac732c790feca196b64012ab91f81b1
  Stored in directory: C:\Users\object\AppData\Local\Temp\pip-ephem-wheel-cache-v6xjjlqo\wheels\06\2b\f9\aa218f95f265aa64e3013e3ab97f138c95307be54f63b231e6
Successfully built project
Installing collected packages: project
Successfully installed project-0.1.0

pip install -e .[local]

Obtaining file:///C:/Users/object/test/uv-hatch-bug
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Processing c:\users\object\test\uv-hatch-bug\subproject (from project==0.1.0)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Checking if build backend supports build_editable ... done
Building wheels for collected packages: project, subproject
  Building editable for project (pyproject.toml) ... done
  Created wheel for project: filename=project-0.1.0-py2.py3-none-any.whl size=992 sha256=11807b7ff67c86dc454cef307552ec3d8ac732c790feca196b64012ab91f81b1
  Stored in directory: C:\Users\object\AppData\Local\Temp\pip-ephem-wheel-cache-_aeumxhm\wheels\06\2b\f9\aa218f95f265aa64e3013e3ab97f138c95307be54f63b231e6
  Building wheel for subproject (pyproject.toml) ... done
  Created wheel for subproject: filename=subproject-0.1.0-py2.py3-none-any.whl size=1017 sha256=0fa7cad32cdb573d95efda0c6e5153e0eec075cfeb7b7e208e893bfd8780da0a
  Stored in directory: C:\Users\object\AppData\Local\Temp\pip-ephem-wheel-cache-_aeumxhm\wheels\96\35\a1\4cbdc9a17151719b42abce24fbf536ab374c79142e12ee2f74
Successfully built project subproject
Installing collected packages: subproject, project
  Attempting uninstall: project
    Found existing installation: project 0.1.0
    Uninstalling project-0.1.0:
      Successfully uninstalled project-0.1.0
Successfully installed project-0.1.0 subproject-0.1.0

Versions

OS: Windows 11
Python: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
uv: 0.1.17 (bb2d06cbb 2024-03-10)

@zanieb
Copy link
Member

zanieb commented Mar 15, 2024

Thanks for the well written report! I think this might be solved by making a PEP 517 request per #1624 — or we could add support for this context formatting directly but I'm hesitant to do that since it's not a Python standard.

@zanieb zanieb added bug Something isn't working great writeup A wonderful example of a quality contribution 💜 labels Mar 15, 2024
@charliermarsh
Copy link
Member

Hmm, I'm not quite sure how projects other than hatch are supposed to be able to build that.

@charliermarsh
Copy link
Member

@ofek - are other frontends expected to be able to build these projects? Any advice? I know Rye doesn't support this either: astral-sh/rye#826.

@charliermarsh charliermarsh added compatibility Compatibility with a specification or another tool and removed bug Something isn't working labels Mar 16, 2024
@ofek
Copy link
Contributor

ofek commented Mar 16, 2024

PDM added support for that but generally no, other projects can't use it without doing the PEP 517 process.

@charliermarsh
Copy link
Member

We do go through the PEP 517 process so assuming all the build hooks work, it should "just work". I think we're failing because we're trying to parse the requirements even though we don't "need" them here. I'll take a look and see if it's easy.

@charliermarsh charliermarsh self-assigned this Mar 16, 2024
@charliermarsh
Copy link
Member

Okay yeah, we can support this.

charliermarsh added a commit that referenced this issue Mar 16, 2024
## Summary

If a package uses Hatch's `root.uri` feature, we currently error:

```toml
dependencies = [
  "black @ {root:uri}/../black_editable"
]
```

Even though we're using PEP 517 hooks to get the metadata, which
_should_ support this. The problem is that we load the full
`PyProjectToml`, which means we parse the requirements, which means we
reject what looks like a relative URL in dependencies.

Instead, we should only enforce a limited subset of `pyproject.toml`
(arguably none).

Closes #2475.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility Compatibility with a specification or another tool great writeup A wonderful example of a quality contribution 💜
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants