From c43f2f027c3a4149704ca9814300fb043a243059 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 18 Apr 2024 14:48:28 -0500 Subject: [PATCH] chore: bump packaging to v24 --- scripts/vendor.py | 5 +++-- src/viv/viv.py | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/scripts/vendor.py b/scripts/vendor.py index dbe2af5..6f2f850 100755 --- a/scripts/vendor.py +++ b/scripts/vendor.py @@ -131,12 +131,13 @@ PACKAGES = [ Package( name="packaging", url="https://github.com/pypa/packaging.git", - rev="23.2", + # v24.0 + rev="7a983f7f0068669ead9d4f7571be24d6c0d83eb9", files=( ("_structures", [[5, 61]]), ("version", [[17, 563]]), ("utils", [[54, 100]]), - ("specifiers", [[28, 1030]]), + ("specifiers", [[18, 1017]]), ), basepath=Path(__file__).parent / "packaging/src/packaging", prefix=""" diff --git a/src/viv/viv.py b/src/viv/viv.py index e6c07f3..e8399a7 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -1363,7 +1363,7 @@ class v_packaging_Specifier(v_packaging_BaseSpecifier): ) self._prereleases = prereleases - @property # type: ignore + @property def prereleases(self) -> bool: if self._prereleases is not None: return self._prereleases @@ -1425,7 +1425,7 @@ class v_packaging_Specifier(v_packaging_BaseSpecifier): return operator_callable def _compare_compatible(self, prospective: v_packaging_Version, spec: str) -> bool: - prefix = ".".join( + prefix = v_packaging__version_join( list( itertools.takewhile( v_packaging__is_not_suffix, v_packaging__version_split(spec) @@ -1549,7 +1549,9 @@ v_packaging__prefix_regex = re.compile("^([0-9]+)((?:a|b|c|rc)[0-9]+)$") def v_packaging__version_split(version: str) -> List[str]: result: List[str] = [] - for item in version.split("."): + epoch, _, rest = version.rpartition("!") + result.append(epoch or "0") + for item in rest.split("."): match = v_packaging__prefix_regex.search(item) if match: result.extend(match.groups()) @@ -1558,6 +1560,11 @@ def v_packaging__version_split(version: str) -> List[str]: return result +def v_packaging__version_join(components: List[str]) -> str: + epoch, *rest = components + return f"{epoch}!{'.'.join(rest)}" + + def v_packaging__is_not_suffix(segment: str) -> bool: return not any( segment.startswith(prefix) for prefix in ("dev", "a", "b", "rc", "post") @@ -1574,7 +1581,9 @@ def v_packaging__pad_version( right_split.append(right[len(right_split[0]) :]) left_split.insert(1, ["0"] * max(0, len(right_split[0]) - len(left_split[0]))) right_split.insert(1, ["0"] * max(0, len(left_split[0]) - len(right_split[0]))) - return list(itertools.chain(*left_split)), list(itertools.chain(*right_split)) + return list(itertools.chain.from_iterable(left_split)), list( + itertools.chain.from_iterable(right_split) + ) class v_packaging_SpecifierSet(v_packaging_BaseSpecifier): @@ -1582,10 +1591,7 @@ class v_packaging_SpecifierSet(v_packaging_BaseSpecifier): self, specifiers: str = "", prereleases: Optional[bool] = None ) -> None: split_specifiers = [s.strip() for s in specifiers.split(",") if s.strip()] - v_packaging_parsed: Set[v_packaging_Specifier] = set() - for specifier in split_specifiers: - v_packaging_parsed.add(v_packaging_Specifier(specifier)) - self._specs = frozenset(v_packaging_parsed) + self._specs = frozenset(map(v_packaging_Specifier, split_specifiers)) self._prereleases = prereleases @property @@ -1631,7 +1637,7 @@ class v_packaging_SpecifierSet(v_packaging_BaseSpecifier): specifier._prereleases = self._prereleases else: raise ValueError( - "Cannot combine v_packaging_SpecifierSets " + "Cannot combine v_packaging_SpecifierSets" "with True and False prerelease overrides." ) return specifier