Exclude certain dependency version ranges in setuptools/pip

后端 未结 2 1449

Currently the Django Project supports 1.4, 1.7 and 1.8. In my setup.py I want to reflect these versions as being supported.

install_requires=[\'Djan         


        
相关标签:
2条回答
  • 2021-02-20 09:08

    You can use Django>=1.4.2,<1.9,!=1.5.*,!=1.6.*

    This is defined inside PEP440.

    You can test this behavior with the packaging module that is vendored inside the last versions of setuptools and pip.

    In [1]: from packaging import specifiers
    
    In [2]: sp=specifiers.SpecifierSet(">=1.4.2,<1.9,!=1.5.*,!=1.6.*")
    
    In [3]: sp.contains("1.4.2")
    Out[3]: True
    
    In [4]: sp.contains("1.6.4")
    Out[4]: False
    
    In [5]: sp.contains("1.8.2")
    Out[5]: True
    
    0 讨论(0)
  • 2021-02-20 09:19

    I've read some related code of pkg_resources. I think the document here is not accurate. Not only pip fails to find the right package version, python setup.py install, which actually uses setuptools, also fails.

    Some of the related code:

    pip/_vendor/packaging/specifiers.py

    # If we have any specifiers, then we want to wrap our iterable in the
    # filter method for each one, this will act as a logical AND amongst
    # each specifier.
    if self._specs:
        for spec in self._specs:
            iterable = spec.filter(iterable, prereleases=prereleases)
        return iterable
    

    You can see that in the comment, the author emphasized that this will cause an AND amongst each specifier, not OR. So if you do this:

    PickyThing<1.6,>1.9,!=1.9.6,<2.0a0,==2.4c1
    

    You will get nothing!

    I tried with this code below:

    import pkg_resources
    
    a = ['1.4', '1.8', '1.9.2']
    d = pkg_resources.Requirement.parse('PickyThing<1.6,>1.9,!=1.9.6')
    r = d.specifier.filter(a)
    
    print(list(r)) # Nothing, just an empty list []
    

    You may want to file a bug to pip so they can fix it.

    0 讨论(0)
提交回复
热议问题