pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.46k stars 1.18k forks source link

working_set drops python_version marker #1072

Open mmulich opened 7 years ago

mmulich commented 7 years ago

Scenario

I'm working on a project that uses python 3.6.x with pytest 3.1.x using the latest release of setuptools and pip.

I've got a pytest plugin that isn't being loaded/registered because pytest ignores it due to entrypoint.load() failing with DistributionNotFound. The given information Entrypoint.load() and therefore to working_set is valid. The problem is that the given information is wrong.

I'm attempting to use cnx-litezip-1.2.0 in my project, which is correctly registered as a pytest plugin. cnx-litezip depends on cnxml, which in-turn has a dependency: pathlib;python_version<='2.7'. The issue seems to be that the working_set dist object for drops the python_version marker.

>>> dist = working_set.by_key.get('cnxml')
>>> dist
cnxml 2.0.0 (/usr/local/lib/python3.6/site-packages)
>>> dist.requires()
[Requirement.parse('pathlib')]

When it really should be, but is not:

>>> dist.requires()
[Requirement.parse('pathlib; python_version <= "2.7"')]

Workaround

The temporary workaround to this issue has been to simply install the missing package, but this isn't ideal, seeing as pathlib is included in the standard library.

wjwwood commented 6 years ago

I think I've run into the same issue, where the dependency:

install_requires=[
    "enum34 ;  python_version <= '2.7'",
    ...
],

-- from: https://github.com/PyCQA/flake8-import-order/commit/c52371fd5314429895064135146ef80e7c36a07f#diff-2eeaed663bd0d25b7e608891384b7298R32

Is getting installed even for Python version 3.6. I haven't had a chance to verify it in the same way as @pumazi did just yet, but I will as soon as I have time to get access to the machine.

The way I noticed is that installing enum34 breaks importing on newer versions of python, hence the version constraint. But when that's ignored it installs it anyways. So you can uninstall enum34, but it gets reinstalled when you update flake8-import-order again.