Example #1
0
def test_support_prerelease_version() -> None:
    assert not Version("3.9.0").is_prerelease
    v = Version("3.9.0a4")
    assert v.is_prerelease
    assert str(v) == "3.9.0a4"
    assert v.complete() == v
    assert v.bump() == Version("3.9.0a5")
    assert v.bump(2) == Version("3.9.1")
Example #2
0
def _normalize_op_specifier(op: str, version_str: str) -> Tuple[str, Version]:
    version = Version(version_str)
    if version.is_wildcard:
        if op == "==":
            op = "~="
            version[-1] = 0
        elif op == ">":  # >X.Y.* => >=X.Y+1.0
            op = ">="
            version = version.bump(-2)
        elif op in ("<", ">=", "<="):
            # <X.Y.* => <X.Y.0
            # >=X.Y.* => >=X.Y.0
            # <=X.Y.* => <X.Y.0
            version[-1] = 0
            if op == "<=":
                op = "<"
        elif op != "!=":
            raise InvalidPyVersion(f"Unsupported version specifier: {op}{version}")

    if op != "~=" and not (op == "!=" and version.is_wildcard):
        # Don't complete with .0 for ~=3.5 and !=3.4.*:
        version = version.complete()
    return op, version