astral-sh / uv

An extremely fast Python package and project manager, written in Rust.
https://docs.astral.sh/uv
Apache License 2.0
19.87k stars 584 forks source link

Better error message for invalid `[project]` table #6419

Open soof-golan opened 3 weeks ago

soof-golan commented 3 weeks ago

Hey Astral team!

I found an interesting behavior around installing a git based project that is managed by poetry (as opposed to any other build system). Since the name of the project is defined under the tool.poetry section uv fails to pick it up when reading the pyproject.toml file. I'm not sure if this is considered Poetry's fault, but pip definitely succeeds in installing this exact package. I have not checked whether this issue can be also replicated locally with a relative path package.

Many thanks 🙏

What Happens

uv fails to install a (seemingly) valid python dependency. pip successfully installs this project.

Expected Behavior

uv should install the package

Reproduction

cd $(mktemp -d)
uv venv
uv pip install -v git+https://github.com/elevenlabs/elevenlabs-python.git@6db2fdd7458ce5c7f1bbdc2c3936784f995acd44

outputs:

Using Python 3.12.5
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
DEBUG uv 0.3.1
DEBUG Searching for Python interpreter in system path
DEBUG Found `cpython-3.12.5-macos-aarch64-none` at `/private/var/folders/f0/m68x433x79n628trx7zp0x3h0000gn/T/tmp.BZTiKhI3Af/.venv/bin/python3` (virtual environment)
DEBUG Using Python 3.12.5 environment at .venv/bin/python3
DEBUG Acquired lock for `.venv`
DEBUG At least one requirement is not satisfied: git+https://github.com/elevenlabs/elevenlabs-python.git@6db2fdd7458ce5c7f1bbdc2c3936784f995acd44
DEBUG Using request timeout of 30s
DEBUG Fetching source distribution from Git: https://github.com/elevenlabs/elevenlabs-python.git
DEBUG Acquired lock for `https://github.com/elevenlabs/elevenlabs-python`
DEBUG Using existing git source `Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("github.com")), port: None, path: "/elevenlabs/elevenlabs-python.git", query: None, fragment: None }`
DEBUG Acquired lock for `/Users/soof/Library/Caches/uv/built-wheels-v3/git/8be1b43a58e07c63/6db2fdd7458ce5c7`
DEBUG No static `PKG-INFO` available for: git+https://github.com/elevenlabs/elevenlabs-python.git@6db2fdd7458ce5c7f1bbdc2c3936784f995acd44 (MissingPkgInfo)
error: Failed to extract static metadata from `pyproject.toml`
  Caused by: TOML parse error at line 31, column 2
   |
31 | [project.urls]
   |  ^^^^^^^
missing field `name`
image

uv --version

uv 0.3.1 (be17d132a 2024-08-21)

Platform

macOS Sonoma

konstin commented 3 weeks ago

We should fall back to building instead of trying to the read the metadata here, as we're doing in other cases, this is a bug.

Is there a reason you're using [project.urls] here instead of [tool.poetry.urls]?

soof-golan commented 3 weeks ago

@konstin Thanks for the fast response :) This is not a project I own / maintain, but an external package that is specified as a git dependency in another project.

(This is why I wrote seemingly valid)

uv fails to install a (seemingly) valid python dependency

charliermarsh commented 3 weeks ago

@konstin -- I'm somewhat unsure... It is spec-incompliant. If we accept it here, we risk false negatives for other projects.

konstin commented 3 weeks ago

Oh right, because it's not dynamic like in the other cases.

We should change the error message with a note about the [project] table spec, maybe linking to https://packaging.python.org/en/latest/guides/writing-pyproject-toml/

konstin commented 2 weeks ago

The toml crate doesn't give us this information unfortunately, so we can add better context to the error message: https://github.com/toml-rs/toml/issues/778