astral-sh / uv

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

Bug: `uv publish` missing `METADATA` file #8030

Closed jamesbraza closed 1 week ago

jamesbraza commented 2 weeks ago

I am using uv==0.4.20 and just migrated a publish GitHub Action in a repo using this workspace layout for several packages to uv publish.

    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v3
        with:
          enable-cache: true
      - run: uv sync
      - name: Build a binary wheel and a source tarball
        run: |
          uv build --sdist --wheel --out-dir dist/ .
          uv build --sdist --wheel --out-dir dist/ packages/bird-feeder
          uv build --sdist --wheel --out-dir dist/ packages/seeds
---      - uses: pypa/gh-action-pypi-publish@release/v1
---        with:
---          password: ${{ secrets.PYPI_API_TOKEN }}
+++      - run: uv publish
+++        env:
+++          UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }}

Before, publish worked correctly, but with uv publish I am getting:

warning: `uv publish` is experimental and may change without warning
Publishing 6 files https://upload.pypi.org/legacy/
Uploading seeds-0.7.6-py3-none-any.whl (5.0KiB)
error: Failed to publish `dist/seeds-0.7.6-py3-none-any.whl` to https://upload.pypi.org/legacy/
  Caused by: Upload failed with status code 400 Bad Request. Server says: 400 Wheel 'seeds-0.7.6-py3-none-any.whl' does not contain the required METADATA file: seeds-0.7.6.dist-info/METADATA

Any idea what's going on here? I think this is a uv publish bug given my change was an atomic change, and I was previously using uv build successfully

konstin commented 2 weeks ago

What build backend are you using, and could you share more details about your project and your setup? Additionally, seeds-0.7.6-py3-none-any.whl is a zip file, could you look inside and check what seeds-0.7.6.dist-info in there contains?

Avasam commented 2 weeks ago

Since I just got the same issue, here's a project: https://github.com/Avasam/typed-D3DShot/tree/24954b8122448926b9afddc1c245796b5e9165a0 And here's the wheel file from uv build: typed_D3DShot-1.0.0-py3-none-any.whl.zip FWIW, dist-info does contain this metadata file (I added the .txt extention to upload to GitHub: METADATA

A PyPI issue maybe ? Since I doubt uv publish touches the wheel file's content.

Backend: setuptools uv version: uv 0.4.20 (0e1b25a53 2024-10-08)

Avasam commented 2 weeks ago

Thanks stackoverflow https://stackoverflow.com/a/76757413 It's case sensitive. So uv build issue when naming the folder in the wheel file

I renamed the dist-info folder and it worked. I kept the .whl itself with capital letters.

jamesbraza commented 2 weeks ago

I just took a closer look, and in my case it's seemingly a confusion with . vs _ in the package name. In my attempts earlier in this issue to remove my repo's specifics, I also clouded the issue.

The package name is aviary.gsm8k, and in the uv publish logs:

Uploading aviary_gsm8k-0.7.6-py3-none-any.whl (5.0KiB)
error: Failed to publish `dist/aviary.gsm8k-0.7.6-py3-none-any.whl` to https://upload.pypi.org/legacy/
  Caused by: Upload failed with status code 400 Bad Request. Server says: 400 Wheel 'aviary_gsm8k-0.7.6-py3-none-any.whl' does not contain the required METADATA file: aviary_gsm8k-0.7.6.dist-info/METADATA

We see the issue is a mixup with aviary.gsm8k and aviary_gsm8k. Running ls dist:

.gitignore
aviary.gsm8k-0.7.6-py3-none-any.whl
aviary_gsm8k-0.7.6.tar.gz
konstin commented 1 week ago

The problem here is that the wheel filename is invalid: All . and - need to replaced with _, so the valid name would be aviary_gsm8k-0.7.6-py3-none-any.whl (https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode). This is a setuptools bug: https://github.com/pypa/setuptools/issues/3777.

We're doing two things about this, one is adding a warning for invalid filenames (#8203), the other is adding a workaround specifically for setuptools (#8204), so this wheel can be uploaded, as it can with twine.

jamesbraza commented 1 week ago

Oh thank you @konstin, nice! Just seeking one point of clarification on your above comment, for my understanding:

. and - need to replaced with _, so the valid name would be aviary.gsm8k-0.7.6-py3-none-any.whl

Did you mean to say aviary_gsm8k-0.7.6-py3-none-any.whl?

konstin commented 1 week ago

yes, sorry