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

Add option to add files that need to be considered for the cache key in pyproject.toml #6255

Closed
albertferras-vrf opened this issue Aug 20, 2024 · 9 comments · Fixed by #7136
Assignees
Labels
enhancement New feature or request

Comments

@albertferras-vrf
Copy link

Consider the following pyproject.toml file, which uses dynamic metadata to reference requirements.in files.

[project]
name = "myproject"
version = "0.1.0"
requires-python = ">=3.9"
dynamic = ["dependencies"]

[tool.setuptools.dynamic]
dependencies = {file = ["requirements.in"]}

When invoking the command uv pip compile -o requirements.txt pyproject.toml then setuptools is used to build the project, which is the tool that understands the dynamic and tool.setuptools.dynamic configuration. Once the build is finished, uv reads the package's requires.txt and generates requirements.txt.
The problem is that after (only) modifying requirements.in, the command uv pip compile does not update the requirements.txtfile. This is because the content pyproject.toml did not change and uv decide to not reinstall the package (call setuptools) again.
The current workaround is to add --reinstall or --reinstall-package=myproject to the command or configuration and force setuptools to run.

This was discussed in discord, and the user @ThiefMaster suggested that we could add a new configuration under [tool.uv] which allows specifying which files have to be considered as part of 'pyproject.toml's cache key.
One example would be:

[tool.uv]
cache_key_files = ["requirements.in", "requirements.dev.in"]

Worth mentioning also (not part of this ticket) that it would be good if uv supported popular dynamic implementations natively and not need to invoke setuptools for it.

@charliermarsh
Copy link
Member

I want to work on this but I don't yet have a good solution for setuptools_scm or other things that depend on the Git state.

@charliermarsh
Copy link
Member

I could special-case .git in the array though it's not a great API.

@charliermarsh
Copy link
Member

@konstin @zanieb -- any ideas? If we're gonna support this, I think we need an answer for setuptools_scm too since it's so popular.

@zanieb
Copy link
Member

zanieb commented Sep 4, 2024

Well... something like cache_key_paths = ["path.txt", { file = "other-path.txt }, { git = "." }) is an option? e.g. allow dictionaries so we can define types and default to paths if a simple value is provided? (git = "." being a Git repository rooted in the project directory, we could also do like git = true but I'm not sure it's better)

@charliermarsh
Copy link
Member

That seems reasonable to me.

@zanieb
Copy link
Member

zanieb commented Sep 4, 2024

How complicated does support for Git state need to be? Like... the commit hash changed? There are unstaged changes? The tree is dirty? Number of commits since a tag? etc.

@charliermarsh
Copy link
Member

I think "commit hash changed" is fine.

@charliermarsh
Copy link
Member

I guess setuptools-scm will also reflect uncommitted changes, but that may not be necessary.

@charliermarsh
Copy link
Member

This exists as of v0.4.8. You can do things like:

[tool.uv]
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements.txt" }, { git = true }]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants