uv icon indicating copy to clipboard operation
uv copied to clipboard

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

Open albertferras-vrf opened this issue 6 months ago • 8 comments

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.

albertferras-vrf avatar Aug 20 '24 15:08 albertferras-vrf