-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
I'm on uv 0.5.11 (c4d0caa 2024-12-19).
The issue here is that optional dependencies aren't being written properly to PKG-INFO, therefore making it impossible to pip install the package with options. This was originally identified in biopragmatics/curies#147. Here's a minimal reproduction:
$ uv --preview init xyz --build-backend uv
Initialized project `xyz` at `/Users/cthoyt/xyz`
$ cd xyz
$ uv --preview add defusedxml --optional xml
Using CPython 3.11.10
Creating virtual environment at: .venv
Resolved 2 packages in 59ms
Built xyz @ file:///Users/cthoyt/xyz
Prepared 1 package in 5ms
Installed 2 packages in 3ms
+ defusedxml==0.7.1
+ xyz==0.1.0 (from file:///Users/cthoyt/xyz)
$ echo "import defusedxml" > src/xyz/__init__.py
$ echo "def main(): print('hello from modified xyz')" >> src/xyz/__init__.py
$ uv run xyz
hello from modified xyzIf you start from scratch, you need to do uv run --extra xml xyz, since the option isn't installed yet.
Now comes the problematic part, after building:
$ uv --preview build
Building source distribution (uv build backend)...
Building wheel from source distribution (uv build backend)...
Successfully built dist/xyz-0.1.0.tar.gz
Successfully built dist/xyz-0.1.0-py3-none-any.whl
$ tar -xOzf dist/xyz-0.1.0.tar.gz xyz-0.1.0/PKG-INFO
Metadata-Version: 2.3
Name: xyz
Version: 0.1.0
Summary: Add your description here
Author: Charles Tapley Hoyt
Author-email: Charles Tapley Hoyt <cthoyt@gmail.com>
Requires-Python: >=3.11
Provides-Extra: xml
Description-Content-Type: text/markdownHere's the bug: This PKG-INFO file should also include the line Requires-Dist: defusedxml>=0.7.1; extra == 'xml'.
I believe this also implies that the test scenario at
uv/crates/uv-build-backend/src/metadata.rs
Lines 1029 to 1036 in ad92aaf
| Requires-Dist: flask>=3,<4 | |
| Requires-Dist: sqlalchemy[asyncio]>=2.0.35,<3 | |
| Maintainer: Konsti | |
| Maintainer-email: Konsti <konstin@mailbox.org> | |
| Project-URL: Homepage, https://github.com/astral-sh/uv | |
| Project-URL: Repository, https://astral.sh | |
| Provides-Extra: mysql | |
| Provides-Extra: postgres |
Requires-Dist: lines for mysql and postgres
What this means for pip users
This affects users by the following scenario using pip to install the package. The minimal reproduction below should follow the code before, in which it creates a virtual environment, activates it (I'm using fish, but so activation will vary based on your console), installing pip in the virtual environment, then using pip to install the package locally
This can be reproduced with a pip installation scenario by creating a new virtual environment, installing pip in it, then using pip to install. Note that the same thing happens whether you're using -e for an editable installation or not.
$ uv venv
Creating virtual environment at: .venv
Activate with: source .venv/bin/activate.fish
$ source .venv/bin/activate.fish
$ uv pip install pip
Resolved 1 package in 196ms
Prepared 1 package in 182ms
Installed 1 package in 6ms
+ pip==24.3.1
$ UV_PREVIEW=1 python -m pip install .[xml]
Processing /Users/cthoyt/Desktop/xyz
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: xyz
Building wheel for xyz (pyproject.toml) ... done
Created wheel for xyz: filename=xyz-0.1.0-py3-none-any.whl size=1503 sha256=23ddd26cc3e4c20321aec8053bf8ce5e80d9340977d96555e34ce06b7450c6f5
Stored in directory: /private/var/folders/6k/r2gmmc213vl6h7bv20x624xw0000gn/T/pip-ephem-wheel-cache-hcnf61u2/wheels/92/98/ae/8e6e182b3e32485aed6bab20d53b27efc72ed7f772a8da227b
Successfully built xyz
Installing collected packages: xyz
Successfully installed xyz-0.1.0
$ pip list
Package Version Editable project location
------- ------- -------------------------
pip 24.3.1
xyz 0.1.0 /Users/cthoyt/Desktop/xyzThis listing should include defusedxml, but doesn't
How it should look, using hatch backend
Here's an alternate reproduction that gets the right thing, using hatchling as the backend:
$ uv init xyz --build-backend hatch
Initialized project `xyz` at `/Users/cthoyt/Desktop/xyz`
$ cd xyz
$ uv add defusedxml --optional xml
Using CPython 3.11.10
Creating virtual environment at: .venv
Resolved 2 packages in 1ms
Built xyz @ file:///Users/cthoyt/Desktop/xyz
Prepared 1 package in 218ms
Installed 2 packages in 1ms
+ defusedxml==0.7.1
+ xyz==0.1.0 (from file:///Users/cthoyt/Desktop/xyz)
$ uv build
Building source distribution...
Building wheel from source distribution...
Successfully built dist/xyz-0.1.0.tar.gz
Successfully built dist/xyz-0.1.0-py3-none-any.whl
$ tar -xOzf dist/xyz-0.1.0.tar.gz xyz-0.1.0/PKG-INFO
Metadata-Version: 2.4
Name: xyz
Version: 0.1.0
Summary: Add your description here
Author-email: Charles Tapley Hoyt <cthoyt@gmail.com>
Requires-Python: >=3.11
Provides-Extra: xml
Requires-Dist: defusedxml>=0.7.1; extra == 'xml'