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

Error out when using the same normalised source twice #7229

Closed
mkniewallner opened this issue Sep 9, 2024 · 4 comments · Fixed by #7383
Closed

Error out when using the same normalised source twice #7229

mkniewallner opened this issue Sep 9, 2024 · 4 comments · Fixed by #7383
Assignees
Labels
bug Something isn't working

Comments

@mkniewallner
Copy link
Contributor

mkniewallner commented Sep 9, 2024

When mapping dependencies to define sources, because of the TOML specification, uv will raise an error if defining the same source twice. For instance with this pyproject.toml:

[project]
name = "foo"
version = "0.1.0"
dependencies = ["python-multipart"]

[tool.uv.sources]
python-multipart = { url = "https://files.pythonhosted.org/packages/3d/47/444768600d9e0ebc82f8e347775d24aef8f6348cf00e9fa0e81910814e6d/python_multipart-0.0.9-py3-none-any.whl" }
python-multipart = { url = "https://files.pythonhosted.org/packages/c0/3e/9fbfd74e7f5b54f653f7ca99d44ceb56e718846920162165061c4c22b71a/python_multipart-0.0.8-py3-none-any.whl" }

the following error will be raised:

$ uv lock
warning: Failed to parse `pyproject.toml` during settings discovery:
  TOML parse error at line 8, column 1
    |
  8 | python-multipart = { url = "https://files.pythonhosted.org/packages/c0/3e/9fbfd74e7f5b54f653f7ca99d44ceb56e718846920162165061c4c22b71a/python_multipart-0.0.8-py3-none-any.whl" }
    | ^
  duplicate key `python-multipart` in table `tool.uv.sources`

error: Failed to parse: `pyproject.toml`
  Caused by: TOML parse error at line 8, column 1
  |
8 | python-multipart = { url = "https://files.pythonhosted.org/packages/c0/3e/9fbfd74e7f5b54f653f7ca99d44ceb56e718846920162165061c4c22b71a/python_multipart-0.0.8-py3-none-any.whl" }
  | ^
duplicate key `python-multipart` in table `tool.uv.sources`

(btw not sure we should have both a warning and error here)

But while uv applies normalisation for sources (similarly to dependencies), it will not error out if defining the same source twice with different casing that would result in the same name after normalisation:

[project]
name = "foo"
version = "0.1.0"
dependencies = ["python-multipart"]

[tool.uv.sources]
python-multipart = { url = "https://files.pythonhosted.org/packages/3d/47/444768600d9e0ebc82f8e347775d24aef8f6348cf00e9fa0e81910814e6d/python_multipart-0.0.9-py3-none-any.whl" }
python_multipart = { url = "https://files.pythonhosted.org/packages/c0/3e/9fbfd74e7f5b54f653f7ca99d44ceb56e718846920162165061c4c22b71a/python_multipart-0.0.8-py3-none-any.whl" }

Here, locking will work, and will end up choosing the latest source defined in the list (here in python_multipart, and if reversing the list, python-multipart is chosen instead).

Should uv also error out in this case, like it does when using the exact same casing?

@charliermarsh
Copy link
Member

Yeah, I think we should probably error in both cases. Good find.

@charliermarsh
Copy link
Member

(btw not sure we should have both a warning and error here)

Agree though it's somewhat annoying to fix because these happen very far apart from one another.

@charliermarsh charliermarsh added the bug Something isn't working label Sep 9, 2024
@mkniewallner
Copy link
Contributor Author

(btw not sure we should have both a warning and error here)

Agree though it's somewhat annoying to fix because these happen very far apart from one another.

Yeah to be fair this is really just a tiny annoyance, mentioned it just because I stumbled across it 😄

@charliermarsh
Copy link
Member

It bothers me lol.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants