Skip to content

Adding a package and pinning to a specific index by name only with uv add #10140

@menzenski

Description

@menzenski

This issue is something of a followup to #6582, which was a duplicate of #171. That issue has comments #171 (comment) and #171 (comment) which seems to be the same thing I am interested in here (but I can't find anything in search that suggests those have been opened as independent issues yet).

Desired Behavior

Given an index definition named my_artifactory in pyproject.toml:

[[tool.uv.index]]
name = "my_artifactory"
url = "https://myorg.jfrog.io/artifactory/api/pypi/pypi/simple"
explicit = true

I would like to be able to run uv add my-private-package --index my_artifactory (or similar command - the important part here is that the CLI command references an index by name only, not by name and URL), with the resulting behavior that the package has been added and pinned to that specific index. Desired output in pyproject.toml:

dependencies = [
    "my-private-package>=0.18.0",
]

[tool.uv.sources]
my-private-package = { index = "my_artifactory" }

Current Workaround

My current workaround is to add the tool.uv.sources entry first, manually in the pyproject.toml file:

[tool.uv.sources]
my-private-package = { index = "my_artifactory" }

Then I can run uv add my-private-package. But I would prefer not to be manually updating pyproject.toml for this - it would be nice to be able to do all "add/update dependency" tasks via the uv CLI.

Comparison to Poetry

I am trying to migrate from Poetry to uv. With Poetry, I can specify an explicit source in pyproject.toml:

[[tool.poetry.source]]
name = "my_artifactory"
url = "https://myorg.jfrog.io/artifactory/api/pypi/pypi/simple"
priority = "explicit"

and add a dependency using poetry add with a --source my_artifactory option, e.g.:

$ poetry add my-private-package --source my_artifactory

The result of this command is a package that is pinned to that specific source:

[tool.poetry.dependencies]
my-private-package = {version = "^0.18.0", source = "my_artifactory"}

I am hoping that the same behavior is possible with uv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement to existing functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions