requirements.txt: any version < 1.5 (incl dev and rc versions)

huangapple go评论55阅读模式
英文:

requirements.txt: any version < 1.5 (incl dev and rc versions)

问题

我正在寻找一个适用于pip和Python 3.10的requirement.txt的模式,它将覆盖所有可用的版本,直到版本1.5,例如:

  • 1.4.2.dev5+g470a8b8
  • 1.4.dev22+g2be722f
  • 1.4
  • 1.4rc0
  • 1.5rc1

另外,有没有一种巧妙的方法可以在不在新的虚拟环境中实际运行“pip install”的情况下进行测试?

英文:

I am looking for a pattern for Python's requirement.txt (for usage with pip and python 3.10), which will cover all versions available up to a version 1.5, e.g.

  • 1.4.2.dev5+g470a8b8
  • 1.4.dev22+g2be722f
  • 1.4
  • 1.4rc0
  • 1.5rc1

And: is there a clever way to test this without actually running "pip install" in a fresh venv?

答案1

得分: 1

以下是您要求的翻译内容:

You should be able to test with python -m pip install --dry-run without actually installing anything.
您应该能够使用 python -m pip install --dry-run 进行测试,而不会真正安装任何内容。

You can also install and test with packaging which is the library used by pip internally.
您还可以使用 packaging 安装并进行测试,这是 pip 内部使用的库。

I guess !=1.5,&lt;=1.5 should be what you want.
我猜 !=1.5,&lt;=1.5 应该是您想要的。

So you could use it like this:
因此,您可以像这样使用它:

python -m pip install --pre &#39;somepackage!=1.5,&lt;=1.5&#39;

或者在 requirements.txt 文件中:

--pre

somepackage !=1.5, &lt;=1.5

相关:

英文:

You should be able to test with python -m pip install --dry-run without actually installing anything.

You can also install and test with packaging which is the library used by pip internally.

I guess !=1.5,&lt;=1.5 should be what you want.

import packaging.specifiers
import packaging.version

version_strings = [
    &#39;1&#39;,
    &#39;1.0&#39;
    &#39;1.1&#39;,
    &#39;1.4&#39;,
    &#39;1.4.2&#39;,
    &#39;1.4.2.dev5+g470a8b8&#39;,
    &#39;1.4.dev22+g2be722f&#39;,
    &#39;1.4&#39;,
    &#39;1.4rc0&#39;,
    &#39;1.5rc1&#39;,
    &#39;1.5&#39;,
    &#39;1.5.1&#39;,
    &#39;1.6&#39;,
    &#39;2&#39;,
    &#39;2.0&#39;,
]

versions = [packaging.version.Version(v) for v in version_strings]

specifier = packaging.specifiers.SpecifierSet(&#39;!=1.5,&lt;=1.5&#39;, prereleases=True)

for version in versions:
    print(f&#39;{version} in {specifier}: {version in specifier}&#39;)
$ python test.py 
1 in !=1.5,&lt;=1.5: True
1.1.1 in !=1.5,&lt;=1.5: True
1.4 in !=1.5,&lt;=1.5: True
1.4.2 in !=1.5,&lt;=1.5: True
1.4.2.dev5+g470a8b8 in !=1.5,&lt;=1.5: True
1.4.dev22+g2be722f in !=1.5,&lt;=1.5: True
1.4 in !=1.5,&lt;=1.5: True
1.4rc0 in !=1.5,&lt;=1.5: True
1.5rc1 in !=1.5,&lt;=1.5: True
1.5 in !=1.5,&lt;=1.5: False
1.5.post0 in !=1.5,&lt;=1.5: False
1.5.0 in !=1.5,&lt;=1.5: False
1.5.1 in !=1.5,&lt;=1.5: False
1.6 in !=1.5,&lt;=1.5: False
2 in !=1.5,&lt;=1.5: False
2.0 in !=1.5,&lt;=1.5: False

So you could use it like this:

python -m pip install --pre &#39;somepackage!=1.5,&lt;=1.5&#39;

or in a requirements.txt file:

--pre

somepackage !=1.5, &lt;=1.5

Related:

huangapple
  • 本文由 发表于 2023年2月16日 13:54:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468349.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定