pypa / twine

Utilities for interacting with PyPI
https://twine.readthedocs.io/
Apache License 2.0
1.61k stars 308 forks source link

Invalid distribution metadata; `UNKNOWN` package name #853

Closed LordHeImchen closed 2 years ago

LordHeImchen commented 2 years ago

Hey guys, i have a problem when executing twine check dist/*. Since I am completely new to publishing packages I cannot fix this error. But one by one:

1) Your operating system: Mac OS 2) Version of python you are running:

python 3.7.6

3) How did you install twine? Did you use your operating system's package manager or pip or something else?

pip install twine

4) Version of twine you have installed (include complete output of):

twine version 3.7.1 (importlib_metadata: 4.10.0, pkginfo: 1.8.2, requests:
2.26.0, requests-toolbelt: 0.9.1, tqdm: 4.42.1)

5) Which package repository are you targeting? pypi

The Issue

Please describe the issue that you are experiencing. After building the package with python3 -m build . a MANIFEST, ipypetrinet-1.0.0.tar.gz and UNKNOWN-0.0.0-py2.py3-none-any.whl file is successfully created. After that i tried twine check dist/* which throws the following error:

Checking dist/UNKNOWN-0.0.0-py2.py3-none-any.whl: InvalidDistribution: Invalid distribution metadata. 
This version of twine supports Metadata-Version 1.0, 1.1, 1.2, 2.0, 2.1, and 2.2

But when I unzip UNKNOWN-0.0.0-py2.py3-none-any.whl and look into the files, the only file containing the keyword Metadata-Version has an appropriate Metadata-Version of 2.1. To visualize this METADATA-file I will paste the first few lines below:

Metadata-Version: 2.1
Name: UNKNOWN
Version: 0.0.0
Summary: UNKNOWN
Home-page: UNKNOWN
License: UNKNOWN
Platform: UNKNOWN
Description-Content-Type: text/markdown
License-File: LICENSE.txt

Does anyone know how to deal with this? Any help is appreciated! Thanks in advance.

bhrutledge commented 2 years ago

Hm. I agree that the error message could be more helpful, but I'm guessing the root cause is something in your package configuration that's resulting in Name: UNKNOWN. It seems like that should be something Name: ipypetrinet, and the wheel should be ipypetrinet-0.0.0-py2.py3-none-any.whl.

Are you able to share the source code for your project? Or the contents of files like pyroject.toml, setup.cfg, or setup.py?

LordHeImchen commented 2 years ago

Thank you for the fast reply. Of course i can share the source code. I already looked at the setup.py file but didn't see any flaws. You can find the whole project on https://gitlab-iwi.dfki.de/Bucksch/ipypetrinet.

bhrutledge commented 2 years ago

Thanks for sharing. I don't entirely understand what's going on, but when I ran python3 -m build, I noticed that the sdist (ipypetrinet-1.0.0.tar.gz) didn't include setup.py. Without that, none of the metadata defined in that file was used when building the .whl, which resulted in the UNKNOWN values.

A quick resolution seems to be adding setup.py to MANIFEST.in:

@@ -1,6 +1,7 @@
 include LICENSE.txt
 include README.md

+include setup.py
 include pyproject.toml
 include pytest.ini
 include .coverage.rc

I confirmed that it's included in the sdist, and that the wheel is ipypetrinet-1.0.0-py2.py3-none-any.whl, which avoids InvalidDistribution error.

So, ultimately, I think this needs to be fixed in the ipypetrinet repo. Also, when I ran python3 -m build, I noticed that it created a MANIFEST file in the root directory, which seems like it should be in .gitignore. For more on manifest files, take a look at the setuptools documentation.

All that said, I do think the InvalidDistribution error could be more helpful. I'll leave this open for now, with the hope that I can look into that soon.

LordHeImchen commented 2 years ago

Okay, that totally makes sense, but i don't understand why setup.py is not included in MANIFEST.in... Furthermore i already have certain files included in my dist folder, like index.js for example. This leads to the next error, which reads as follows:

Checking dist/ipypetrinet-1.0.0-py2.py3-none-any.whl: PASSED
Checking dist/index.js: InvalidDistribution: Unknown distribution format: 'index.js'

So i totally get the error this time, because twine only accepts .tar.gz, .zip, .whl and .egg files. But i can't just delete these files out of my dist folder, what do you recommend? Do you think i should simply create another folder for ipypetrinet-1.0.0-py2.py3-none-any.whl and ipypetrinet-1.0.0.tar.gz inside my dist folder and execute the command like this twine check dist/newfolder/*? Does that make sense?

Highly appreciate your help! Thank you so much!

sigmavirus24 commented 2 years ago

So i totally get the error this time, because twine only accepts .tar.gz, .zip, .whl and .egg files. But i can't just delete these files out of my dist folder, what do you recommend?

Why do you want index.js in your dist/ folder? Why does it need to be there?

LordHeImchen commented 2 years ago

Well I don't really care about the folder index.js is stored in, but since I worked with a template from https://github.com/jupyter-widgets/widget-ts-cookiecutter and the project is setup their way, i think it needs to be there for everything to work fine.

I am wondering if the "Releasing your initial packages" part at the bottom of their README is up to date because the way the project is structured it does not seem to work anymore...

sigmavirus24 commented 2 years ago

Yeah, it looks like it is expecting a different behaviour and/or those docs were added by someone who didn't properly test the changes to the docs. Personally, for something that involved, I'd have made a Makefile or used some other kind of automation (tox, nox, etc.) and probably cleaned things up between the npm publish and twine check dist/* && twine upload dist/*. An example that may or may not actually work for you (I'm writing these without testing them) would be something like

.PHONY: publish clean

clean:
        @rm -rf dist/ build/ **/*.pyc

publish: clean
        @echo "Publishing JS assets..."
        @npm login
        @npm publish
        @rm -rf dist/
        @python -m build . >/dev/null
        @echo "Checking Python metadata..."
        @twine check dist/*
        @echo "Publishing Python assets..."
        @twine upload dist/*

It does look like the JS portions care about dist/ though: https://github.com/jupyter-widgets/widget-ts-cookiecutter/blob/0e0116cfc12fd61b18d89d17145031992373076b/%7B%7Bcookiecutter.github_project_name%7D%7D/package.json#L11-L15

LordHeImchen commented 2 years ago

Thanks for your effort! But i tried uploading it after moving both the tar.gz and the .whl in another folder and it worked. I know it is a hacky workaround but i do not plan to constantly update this so i think it is okay for my purposes.

Anyways big up to you guys and thanks for your help!

sigmavirus24 commented 2 years ago

@LordHeImchen if you're satisfied, feel free to close this

bhrutledge commented 2 years ago

@LordHeImchen Instead of moving the .tar.gz and .whl files to another folder, I would remove the the dist/ folder before running python3 -m build. I suspect that the index.js file ended up in there accidentally; it doesn't show up for me. For example:

$ rm -Rf dist

$ python3 -m build
* Creating venv isolated environment..
...
running install_scripts
Successfully built ipypetrinet-1.0.0.tar.gz and ipypetrinet-1.0.0-py2.py3-none-any.whl

$ ls dist
ipypetrinet-1.0.0-py2.py3-none-any.whl ipypetrinet-1.0.0.tar.gz
bhrutledge commented 2 years ago

Alternatively, if there's a conflict between the JS and the Python use of dist/, then you can specify a different directory for Python:

$ python3 -m build -o py_dist

$ twine upload py_dist/*

In that case, you'd want to add py_dist to your .gitignore.

LordHeImchen commented 2 years ago

Well I am satisfied and publishing worked, so that's great. And thanks, I will definitely try one of these options above if i update it in a while!

All that said, I do think the InvalidDistribution error could be more helpful. I'll leave this open for now, with the hope that I can look into that soon.

However, I'll leave the issue open for @bhrutledge in order to have a look at the error message. So feel free to close this issue whenever you like.