uv: `[tool.uv.sources]` can't be used as `[sources]` in `uv.toml`

As mentioned in the docs, tool.uv.sources works fine for specifying sources overrides, but it seems that [sources] in uv.toml does not.

Confusingly, using tool.uv.sources and a uv.toml doing other things throws this warning:

warning: Found both a `uv.toml` file and a `[tool.uv]` section in an adjacent `pyproject.toml`. The `[tool.uv]` section will be ignored in favor of the `uv.toml` file.

However, it actually works fine to have it split among the two files.

Let me know if you need more to reproduce, but it should be straightforward as it’s just a config file distinction for all forms of [tool.uv.sources].


Version: uv 0.3.3 Platform: MacOS / Linux Command: uv sync

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 2
  • Comments: 19 (8 by maintainers)

Most upvoted comments

I would have another use-case for sources in uv.toml: My laptop doesn’t have a GPU, so I generally want any pytorch package to be the cpu-only variant. While we can handle this for our local projects via pyproject.toml, if I install external dependencies directly into a fresh venv I have to manually pass the corresponding index url again. Adding the pytorch cpu-only index (without marking it at explicit) is not an option, since it has unintended side-effects unless we use an unsafe index strategy. Being able to explicitly pin pytorch to the cpu index globally via a sources field in the uv.toml would resolve that issue.

My usecase is very close to what @befelix describes.

I’m writing a lib based on PyTorch on my laptop, which does not have GPU, and I configured the [tool.uv.sources] section with an explicit pytorch-cpu index. However, because the [tool.uv.sources] section can only be specified in pyproject.toml, I have to comment out the section every time I publish it to PyPI.

If the [sources] section is allowed in uv.toml, I can easily use pytorch-cpu index locally – I can add uv.toml to .gitignore and there’s no need to comment out those configuration again!

uv is the best package manager I’ve ever met and I appreciate your work so much, and I can’t be too grateful if this feature is accepted😊.

We can, but each project (dozens) would need to do it. Since our uv.toml is generated and shared automatically to all users to keep their private registry auth in sync, it would let us maintain a single list of dependencies to override.

It’s not a huge deal for us, just a nice workaround while we hunt down the legacy projects shadowing dependencies when they really shouldn’t be.

I also have a use case for this. Internally we have a private registry that contains a number of shadowed package versions for legacy tools, which is causing the resolver to not find the OSS packages with the default index strategy.

We could resolve it by setting the default strategy to unsafe-first-index in the global uv.toml we provide, but it would be more security friendly to include a list of overrides for the effected packages in sources instead. Long term we want to purge all of these shadowed packages, but this would really help our current efforts to adopt uv.

Why can’t you put the cache-dir setting in a user-level uv.toml?

I didn’t know that’s an option. It looks like that works and doesn’t give the warning above, therefore that works for what I needed. Thank you @charliermarsh

Why can’t you put the cache-dir setting in a user-level uv.toml?