fedora-python / pyp2rpm

Tool to convert a package from PyPI to RPM SPECFILE or to generate SRPM.
MIT License
123 stars 39 forks source link

Fix traceback when extracting metadata from .whl is not possible due to missing files #160

Closed irushchyshyn closed 6 years ago

irushchyshyn commented 6 years ago

Fixes #159

Output in the case reported in the issue:

$ ./mybin.py sphinxcontrib_github_alt -s
INFO  Pyp2rpm initialized.
INFO  Using /home/ishcherb/rpmbuild/SOURCES as directory to save source.
INFO  Downloaded package from PyPI: /tmp/tmppy5hne3m/sphinxcontrib_github_alt-1.0-py2.py3-none-any.whl.
INFO  Getting metadata from wheel using WheelMetadataExtractor.
WARNING  Could not extract metadata from metadata.json. Error: the JSON object must be str, bytes or bytearray, not 'NoneType'
WARNING  Could not extract metadata from pydist.json. Error: the JSON object must be str, bytes or bytearray, not 'NoneType'
Unable to extract package metadata from .whl archive. Make sure that the .dist-info directory contains either metadata.json or pydist.json file of valid JSON format

This PR also contains a fix for tests, introduced by renaming vertica-python to python2-vertica in Fedora Rawhide (as we use Fedora Rawhide docker image to run tests on Travis CI).

hroncok commented 6 years ago

You've said:

As sphinxcontrib_github_alt uses wheel version 1.0, it does not have those files, it's .dist-info directory includes METADATA, WHEEL, and RECORD, where METADATA file is of the same format as PKG-INFO files.

From that I assume something like this may be helpful in the error message:

This might be caused by an old .whl format version. You may ask the upstream to upload fresh wheels created with wheel >= 6.6.6 or to upload an sdist as well to workaround this problem.

irushchyshyn commented 6 years ago

From that I assume something like this may be helpful in the error message:

This might be caused by an old .whl format version. You may ask the upstream to upload fresh wheels created with wheel >= 6.6.6 or to upload an sdist as well to workaround this problem.

Yeah, sounds more helpful. However, after a bit more investigation I have figured that it is not weel version, but wheel metadata version should be >= 2.0 (https://www.python.org/dev/peps/pep-0426). So the message will be something like

This might be caused by an old .whl format version. You may ask the upstream to upload fresh wheels created with wheel metadata version >= 2.0 or to upload an sdist as well to workaround this problem.

hroncok commented 6 years ago

I assume there is a certain wheel version that started to use metadata version >= 2.0. May be 0.17.0?

0.17.0: Support latest PEP-426 “pymeta.json” (json-format metadata)

irushchyshyn commented 6 years ago

I assume there is a certain wheel version that started to use metadata version >= 2.0. May be 0.17.0?

Right. Chnaged the message in 262b57b