How to specify version ranges in install_requires (setuptools, distribute)

前端 未结 4 1825
余生分开走
余生分开走 2020-12-14 05:58

I want to make a package to depend the particular version range e.g. >= 0.5.0, < 0.7.0. Is it possible in install_requires option, and if so

4条回答
  •  无人及你
    2020-12-14 06:17

    Be wary of involuntary beta tests. Package maintainers sometimes release incompatible, incomplete, or broken a, b, and c releases to general audiences without warning. The next time you run setup.py in a fresh virtualenv, you might pull down one of these poisoned eggs, and suddenly your program will break.

    To mitigate this risk, do not use the foo >=0.3, <0.4 style declaration, which has a purely numeric upper bound. <0.4 still admits versions 0.4a0, 0.4a1, 0.4b0, 0.4c3, etc. Instead, use an upper bound like <0.4a0, as in foo >=0.3, <0.4a0, when you write your install_requires.

    When setuptools does something unexpected, trying using verlib to model your version comparisons. Verlib is a pretty good fit as long as your versions are normalized and non-contradictory. Here is an example that demonstrates the potentially counter-intuitive ordering of normalized versions:

    #!/usr/bin/env python
    
    from verlib import NormalizedVersion as V
    
    assert (V("0.7.9") < V("0.8a0") < V("0.8a1") < V("0.8b0") < V("0.8b1")
        < V("0.8b2") < V("0.8.0") < V("0.8.1a0") < V("0.8.1") < V("0.9")
        < V("1.0a3") < V("1.0b2") < V("1.0b20") < V("1.0c0") < V("1.0")
        < V("1.0.1"))
    
    assert (V("0.7.9") < V("0.8.0a0") < V("0.8.0a1") < V("0.8.0b0")
        < V("0.8.0b1") < V("0.8.0b2") < V("0.8.0") < V("0.8.1a0") < V("0.8.1")
        < V("0.9") < V("1.0a3") < V("1.0b2") < V("1.0b20") < V("1.0c0")
        < V("1.0") < V("1.0.1"))
    
    print "Version comparisons are sane."
    

提交回复
热议问题