在 setuptools/pip 中排除某些依赖版本范围 [英] Exclude certain dependency version ranges in setuptools/pip

查看:71
本文介绍了在 setuptools/pip 中排除某些依赖版本范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前 Django 项目支持 1.4、1.7 和 1.8.在我的 setup.py 中,我想将这些版本反映为受支持.

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=['Django>=1.4.2,<1.8.99,!=1.5,!=1.6']

然而,这仍然允许 1.5.x 和 1.6.x 版本.如何排除整个范围?

However this still allows 1.5.x and 1.6.x releases. How can I exclude a complete range?

Setuptools 列出以下有效要求为例:

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

但是这不适用于 pip(它至少应该匹配 1.4.x/1.5.x):

However this doesn't work with pip (it should at least match 1.4.x / 1.5.x):

没有找到 PickyThing!=1.9.6,<1.6,<2.0a0,==2.4c1,>1.9 的匹配分布

No matching distribution found for PickyThing!=1.9.6,<1.6,<2.0a0,==2.4c1,>1.9

示例更新
例如;我只想包含 当前支持的 Django 版本.这将是 1.4.x、1.7.x 和 1.8.x.所以我会写;

Update with example
For example; I only want to include currently supported versions of Django. This would be 1.4.x, 1.7.x and 1.8.x. So I would write;

#setup.py
install_requires=['Django>=1.4.2,<1.4.99,>=1.7,<1.8.99']

但是,如果我在这个项目上运行 pip install -e .,它会失败;

However if I run pip install -e . on this project, it fails with;

Collecting Django<1.4.99,<1.8.99,>=1.4.2,>=1.7 (from ...)
Could not find a version that satisfies the requirement Django<1.4.99,<1.8.99,>=1.4.2,>=1.7 (from django-two-factor-auth==1.2.0) (from versions: 1.1.3, 1.1.4, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 1.2.7, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.4.14, 1.4.15, 1.4.16, 1.4.17, 1.4.18, 1.4.19, 1.4.20, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11, 1.5.12, 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.6.11, 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.8a1, 1.8b1, 1.8b2, 1.8rc1, 1.8, 1.8.1)
No matching distribution found for Django<1.4.99,<1.8.99,>=1.4.2,>=1.7 (from ...)

很明显,版本号 1.4.20 不能满足 >=1.7 和 1.8.1 不能满足 <1.4.99.然而,来自 Setuptools 的文档(见上文)确实表明应该可以实现这些.然而,这对我来说并不明显.

It is obvious that a version number 1.4.20 cannot satisfy >=1.7 and 1.8.1 cannot satisfy <1.4.99. However the documentation from Setuptools (see above) does suggest that something along these lines should be possible. However, this is non-obvious to me.

推荐答案

我已经阅读了 pkg_resources 的一些相关代码.我认为此处的文档不准确.不仅 pip 无法找到正确的软件包版本,实际上使用 setuptoolspython setup.py install 也失败了.

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.

部分相关代码:

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

您可以在评论中看到,作者强调这将导致每个说明符之间出现AND,而不是OR.所以如果你这样做:

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

你什么也得不到!

我尝试使用以下代码:

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 []

您可能希望向 pip 提交错误,以便他们修复.

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

这篇关于在 setuptools/pip 中排除某些依赖版本范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆