Following on from the question in Exclude certain dependency version ranges in setuptools/pip, I'd like to know if there is a means to use multiple ranges to define supported versions in a version specifier (defined in PEP440).
Take the following usecase:
I have a dependency for which I support versions 1.x, provided x is <3, or 2.x provided x is greater than 1 and less than or equal to 4. The v1.x series is still active, and new versions will continue to be released.
To provide a test case:
import packaging.specifiers as s
def test_specifier_multiple_ranges():
spec = s.SpecifierSet('THE ANSWER GOES HERE')
# A dependency is supported for:
# versions 1.x, provided x is <3
# OR
# versions 2.x provided x is greater than 1 and less than or equal to 3
# The v1.x series is still active, and new versions will continue to
# be released.
possible_versions = [
'1.1', '1.2', '1.3', '1.4', '2.0', '2.1', '2.2', '2.3', '2.4', '3.0'
]
expected = ['1.1', '1.2', '2.2', '2.3']
assert list(spec.filter(possible_versions)) == expected
Note that I am not looking to exclude specific versions, they must be excluded via an upper range - the clause "The v1.x series is still active" rules that out, since at any moment a v1.5 (in the test case above) can appear, which it is already known to be not supported.
Note that in reading the bug report at https://github.com/pypa/pip/issues/2744, as well as PEP440's grammar definition (which lacks any OR capability from what I can see), it is my expectation that this is not possible. I will accept such an answer if it can explicitly reference this limitation (e.g. in PEP440), or it comes from an authoritative source.