Poetry: Can't manage cairocffi after initial installation

Created on 20 Feb 2019  路  7Comments  路  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

Installation of cairocffi works the first time, but trying to manage it or anything related to it after initial installation raises an error: Unable to parse "file-.cairocffi-VERSION".

Steps to reproduce:

$ poetry init -n
$ poetry add cairocffi
$ poetry remove cairocffi
Using virtualenv: /Users/matt/Library/Caches/pypoetry/virtualenvs/poetry-test-py3.7

[ParseVersionError]
Unable to parse "file-.cairocffi-VERSION".

Exception trace:
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/application.py in run() at line 94
   status_code = self.do_run(input_, output_)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/console/application.py in do_run() at line 88
   return super(Application, self).do_run(i, o)
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/application.py in do_run() at line 197
   status_code = command.run(input_, output_)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/console/commands/command.py in run() at line 77
   return super(BaseCommand, self).run(i, o)
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/commands/base_command.py in run() at line 146
   status_code = self.execute(input_, output_)
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/commands/command.py in execute() at line 107
   return self.handle()
 /Users/matt/.local/lib/python3.7/site-packages/poetry/console/commands/remove.py in handle() at line 62
   self.poetry.pool,
 /Users/matt/.local/lib/python3.7/site-packages/poetry/installation/installer.py in __init__() at line 57
   installed = self._get_installed()
 /Users/matt/.local/lib/python3.7/site-packages/poetry/installation/installer.py in _get_installed() at line 526
   return InstalledRepository.load(self._env)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/repositories/installed_repository.py in load() at line 23
   repo.add_package(Package(name, version, version))
 /Users/matt/.local/lib/python3.7/site-packages/poetry/packages/package.py in __init__() at line 40
   self._version = Version.parse(version)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/semver/version.py in parse() at line 201
   raise ParseVersionError('Unable to parse "{}".'.format(text))

remove [-D|--dev] [--dry-run] [--] <packages> (<packages>)...

$ poetry add pre-commit -vvv
Using virtualenv: /Users/matt/Library/Caches/pypoetry/virtualenvs/poetry-test-py3.7
PyPI: 122 packages found for pre-commit *
Using version ^1.14 for pre-commit


[ParseVersionError]
Unable to parse "file-.cairocffi-VERSION".

Exception trace:
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/application.py in run() at line 94
   status_code = self.do_run(input_, output_)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/console/application.py in do_run() at line 88
   return super(Application, self).do_run(i, o)
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/application.py in do_run() at line 197
   status_code = command.run(input_, output_)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/console/commands/command.py in run() at line 77
   return super(BaseCommand, self).run(i, o)
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/commands/base_command.py in run() at line 146
   status_code = self.execute(input_, output_)
 /Users/matt/.pyenv/versions/3.7.0/lib/python3.7/site-packages/cleo/commands/command.py in execute() at line 107
   return self.handle()
 /Users/matt/.local/lib/python3.7/site-packages/poetry/console/commands/add.py in handle() at line 131
   self.poetry.pool,
 /Users/matt/.local/lib/python3.7/site-packages/poetry/installation/installer.py in __init__() at line 57
   installed = self._get_installed()
 /Users/matt/.local/lib/python3.7/site-packages/poetry/installation/installer.py in _get_installed() at line 526
   return InstalledRepository.load(self._env)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/repositories/installed_repository.py in load() at line 23
   repo.add_package(Package(name, version, version))
 /Users/matt/.local/lib/python3.7/site-packages/poetry/packages/package.py in __init__() at line 40
   self._version = Version.parse(version)
 /Users/matt/.local/lib/python3.7/site-packages/poetry/semver/version.py in parse() at line 201
   raise ParseVersionError('Unable to parse "{}".'.format(text))

add [-D|--dev] [--git GIT] [--path PATH] [-E|--extras EXTRAS] [--optional] [--python PYTHON] [--platform PLATFORM] [--allow-prereleases] [--dry-run] [--] <name> (<name>)...

Most helpful comment

No it's definitely a poetry issue. Cairocffi is using the "file:" syntax in setup.cfg which is perfectly valid. Poetry is expecting a semantic version number to be passed, but that's not the output of pip freeze. I will expand on the issue later when I've got access to the code.

All 7 comments

This should be caused by cairocffi setup.py, AFAIK, the latest versions of cairocffi, including 1.0.1, 1.0.2, have some problems in packaging.

No it's definitely a poetry issue. Cairocffi is using the "file:" syntax in setup.cfg which is perfectly valid. Poetry is expecting a semantic version number to be passed, but that's not the output of pip freeze. I will expand on the issue later when I've got access to the code.

OK, expanding as promised and the more I look at it the more I think it's actually a problem with pip.

cairocffi specifies its version string in the setup.cfg as a reference to an external file. The version string looks like this: version = file: cairocffi/VERSION. This is valid according to setuptools as documented here: https://setuptools.readthedocs.io/en/latest/setuptools.html#metadata

The issue in poetry is occuring after it executes pip freeze to get installed package versions here: https://github.com/sdispater/poetry/blob/4a8228781db17f92640a9b868f231bad5b4fb67c/poetry/repositories/installed_repository.py#L19

When I do a poetry run pip freeze myself in a test environment I get the following output:

$ poetry run pip freeze
cairocffi===file-.cairocffi-VERSION
cffi==1.12.1
pycparser==2.19

The version of pip in the virtualenv is 19.0.3:

poetry run pip --version
pip 19.0.3 from /Users/matt/Library/Caches/pypoetry/virtualenvs/poetry-test-py3.7/lib/python3.7/site-packages/pip (python 3.7)

pip is failing to get a version for cairocffi and instead throwing back the sanitised reference to the file. This obviously fails to match against the COMPLETE_VERSION regular expression in the parse method of the Version object: https://github.com/sdispater/poetry/blob/4a8228781db17f92640a9b868f231bad5b4fb67c/poetry/semver/version.py#L199

So the question is who's responsible for getting the version from the file? Judging by the sanitised output of pip freeze I feel that probably this is an oversight in pip itself, and that it should be returning the version from the file instead of what it currently does.

OK turns out this is a setuptools issue, and if you update to the latest version of setuptools before installing cairocffi everything is fine.

Interesting, but it worked, thx!

Is there a way to make poetry install the upgraded version of setuptools into the virtualenv to start with? Currently to fix the problem I have to poetry env remove <version> and then poetry run pip install -U setuptools before I poetry install, which is a bit tricky to get right.

I'm getting this on a server with the latest setuptools installed prior to running poetry install

pip3 show setuptools Name: setuptools Version: 46.1.3 Summary: Easily download, build, install, upgrade, and uninstall Python packages Home-page: https://github.com/pypa/setuptools Author: Python Packaging Authority Author-email: [email protected] License: UNKNOWN Location: /usr/local/lib/python3.6/dist-packages

Was this page helpful?
0 / 5 - 0 ratings