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

build backend: optional dependencies don't make it to PKG-INFO #10091

Open
cthoyt opened this issue Dec 22, 2024 · 1 comment · May be fixed by #10110
Open

build backend: optional dependencies don't make it to PKG-INFO #10091

cthoyt opened this issue Dec 22, 2024 · 1 comment · May be fixed by #10110
Assignees
Labels
bug Something isn't working preview Experimental behavior

Comments

@cthoyt
Copy link
Contributor

cthoyt commented Dec 22, 2024

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 xyz

If 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 <[email protected]>
Requires-Python: >=3.11
Provides-Extra: xml
Description-Content-Type: text/markdown

Here'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

Requires-Dist: flask>=3,<4
Requires-Dist: sqlalchemy[asyncio]>=2.0.35,<3
Maintainer: Konsti
Maintainer-email: Konsti <[email protected]>
Project-URL: Homepage, https://github.com/astral-sh/uv
Project-URL: Repository, https://astral.sh
Provides-Extra: mysql
Provides-Extra: postgres
is incomplete, since it's also missing the appropriate 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/xyz

This 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 <[email protected]>
Requires-Python: >=3.11
Provides-Extra: xml
Requires-Dist: defusedxml>=0.7.1; extra == 'xml'
cthoyt added a commit to biopragmatics/curies that referenced this issue Dec 22, 2024
Closes #147

Temporarily switches to hatch as a backend until
astral-sh/uv#10091 is addressed. setuptools
still has a major bug with metadata upload to PyPI related to licenses
between metadata version 2.3 and 2.4, so it doesn't make sense to go
back to that at all.

The following should now work:

```console
$ git clone https://github.com/biopragmatics/curies
$ cd curies
$ git checkout -b hatch-backend
$ python -m pip install -e .[flask,rdflib]
$ python -m curies mapper --host 0.0.0.0 --port 8764 bioregistry

# then, navigate to http://0.0.0.0:8764/sparql
```
@charliermarsh charliermarsh added bug Something isn't working preview Experimental behavior labels Dec 22, 2024
@charliermarsh charliermarsh self-assigned this Dec 22, 2024
@charliermarsh
Copy link
Member

(I'll fix this, I've already implemented it before.)

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

Successfully merging a pull request may close this issue.

2 participants