Poetry: Malformed METADATA when using optional git dependencies

Created on 20 May 2019  路  2Comments  路  Source: python-poetry/poetry

  • [x] I am on the latest Poetry version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • [x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

Poetry generates a malformed METADATA file when there is an optional git dependency specified in pyproject.toml (see attached gist).

To reproduce you just need to place the files contained in the attached gist in a directory and run:

$ pip install .
[..]
pip._vendor.pkg_resources.RequirementParseError: Parse error at "'extra =='": Expected stringEnd

The responsible for this behaviour is the poetry.masonry.api.prepare_metadata_for_build_wheel function, which is called by pip.

The generated METADATA file looks something like this:

Metadata-Version: 2.1
[..]
Requires-Python: >=3.6
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Provides-Extra: stubs
Requires-Dist: numpy-stubs @ git+https://github.com/numpy/numpy-stubs.git@master; extra == "stubs"

You can verify that the last line is incorrect using pkg_resources:

>>> pkg_resources.Requirement.parse('numpy-stubs @ git+https://github.com/numpy/numpy-stubs.git@master; extra == "stubs"')
pkg_resources.RequirementParseError: Invalid requirement, parse error at "'extra =='"

Or in the exact same way pip does:

>>> from pip._vendor.packaging import requirements as req
>>> req.REQUIREMENT.parseString('numpy-stubs @ git+https://github.com/numpy/numpy-stubs.git@master; extra == "stubs"')
pip._vendor.pyparsing.ParseException: Expected stringEnd (at char 67), (line:1, col:68)

To fix the issue it is necessary to add a space before the ';':

>>> req.REQUIREMENT.parseString('numpy-stubs @ git+https://github.com/numpy/numpy-stubs.git@master ; extra == "stubs"')
(['numpy-stubs', 'git+https://github.com/numpy/numpy-stubs.git@master', <Marker('extra == "stubs"')>], {'name': ['numpy-stubs'], 'url': ['git+https://github.com/numpy/numpy-stubs.git@master'], 'marker': [<Marker('extra == "stubs"')>]})
Bug

Most helpful comment

Is there anything else needed to get #1129 merged and this issue resolved? This is blocking me using Poetry on my project and I'd be happy to help if there's anything that needs to be done.

All 2 comments

I made a pull request #1129 that solves this issue.
It was just an easy bug fix in the generation of the Requires-Dist field of the metadata file when the required package is defined by an url.
Inserting a space between the url and the semicolon allows pip to parse the url correctly.

Is there anything else needed to get #1129 merged and this issue resolved? This is blocking me using Poetry on my project and I'd be happy to help if there's anything that needs to be done.

Was this page helpful?
0 / 5 - 0 ratings