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

Allow users to pre-define dependency metadata #7393

Closed
charliermarsh opened this issue Sep 14, 2024 · 7 comments · Fixed by #7442
Closed

Allow users to pre-define dependency metadata #7393

charliermarsh opened this issue Sep 14, 2024 · 7 comments · Fixed by #7442
Assignees
Labels
enhancement New feature or improvement to existing functionality

Comments

@charliermarsh
Copy link
Member

For packages that don't declare static metadata, it can be a pain to require building the package just to resolve. For example, you might have a dependency that can't be built on ARM, but doesn't declare static metadata. In that case, users can't resolve on ARM, even if the dependency is never installed on ARM (i.e., it has an environment marker).

I think it'd be neat to allow users to define static metadata for their dependencies as an escape hatch, like:

[tool.uv.dependencies]
my-dependency = ["click>0.8"]
@YouJiacheng
Copy link
Contributor

YouJiacheng commented Sep 14, 2024

I planned to file this issue separately, haha. (but I temporarily left my laptop until now) #7291
image

@charliermarsh
Copy link
Member Author

Yeah this would at least make it possible to uv lock without having to build Chumpy at all in your case :)

@YouJiacheng
Copy link
Contributor

I think this should be beyond the direct dependency of the user's project. It should act as hand-crafted resolution rules.

@charliermarsh
Copy link
Member Author

Yeah I think this should be "allowed" for any dependency.

@zanieb
Copy link
Member

zanieb commented Sep 15, 2024

Does this override existing metadata or only get used when not available? I'm a little so-so on the naming because it collides with general dependency groups but otherwise it sounds cool.

@charliermarsh
Copy link
Member Author

I think it would override... It would also allow you to (e.g.) remove dependencies unlike --overrides, if you know all packages that were pulling them in.

@charliermarsh
Copy link
Member Author

(I agree tool.uv.dependencies is bad.)

@charliermarsh charliermarsh self-assigned this Sep 16, 2024
charliermarsh added a commit that referenced this issue Sep 18, 2024
## Summary

This PR enables users to provide pre-defined static metadata for
dependencies. It's intended for situations in which the user depends on
a package that does _not_ declare static metadata (e.g., a
`setup.py`-only sdist), and that is expensive to build or even cannot be
built on some architectures. For example, you might have a Linux-only
dependency that can't be built on ARM -- but we need to build that
package in order to generate the lockfile. By providing static metadata,
the user can instruct uv to avoid building that package at all.

For example, to override all `anyio` versions:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
requires-dist = ["iniconfig"]
```

Or, to override a specific version:

```toml
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["anyio"]

[[tool.uv.dependency-metadata]]
name = "anyio"
version = "3.7.0"
requires-dist = ["iniconfig"]
```

The current implementation uses `Metadata23` directly, so we adhere to
the exact schema expected internally and defined by the standards. Any
entries are treated similarly to overrides, in that we won't even look
for `anyio@3.7.0` metadata in the above example. (In a way, this also
enables #4422, since you could remove a dependency for a specific
package, though it's probably too unwieldy to use in practice, since
you'd need to redefine the _rest_ of the metadata, and do that for every
package that requires the package you want to omit.)

This is under-documented, since I want to get feedback on the core ideas
and names involved.

Closes #7393.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants