Compare commits

...

3 commits

2 changed files with 30 additions and 16 deletions

View file

@ -131,12 +131,13 @@ PACKAGES = [
Package( Package(
name="packaging", name="packaging",
url="https://github.com/pypa/packaging.git", url="https://github.com/pypa/packaging.git",
rev="23.2", # v24.0
rev="7a983f7f0068669ead9d4f7571be24d6c0d83eb9",
files=( files=(
("_structures", [[5, 61]]), ("_structures", [[5, 61]]),
("version", [[17, 563]]), ("version", [[17, 563]]),
("utils", [[54, 100]]), ("utils", [[54, 100]]),
("specifiers", [[28, 1030]]), ("specifiers", [[18, 1017]]),
), ),
basepath=Path(__file__).parent / "packaging/src/packaging", basepath=Path(__file__).parent / "packaging/src/packaging",
prefix=""" prefix="""

View file

@ -1363,7 +1363,7 @@ class v_packaging_Specifier(v_packaging_BaseSpecifier):
) )
self._prereleases = prereleases self._prereleases = prereleases
@property # type: ignore @property
def prereleases(self) -> bool: def prereleases(self) -> bool:
if self._prereleases is not None: if self._prereleases is not None:
return self._prereleases return self._prereleases
@ -1425,7 +1425,7 @@ class v_packaging_Specifier(v_packaging_BaseSpecifier):
return operator_callable return operator_callable
def _compare_compatible(self, prospective: v_packaging_Version, spec: str) -> bool: def _compare_compatible(self, prospective: v_packaging_Version, spec: str) -> bool:
prefix = ".".join( prefix = v_packaging__version_join(
list( list(
itertools.takewhile( itertools.takewhile(
v_packaging__is_not_suffix, v_packaging__version_split(spec) 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]: def v_packaging__version_split(version: str) -> List[str]:
result: 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) match = v_packaging__prefix_regex.search(item)
if match: if match:
result.extend(match.groups()) result.extend(match.groups())
@ -1558,6 +1560,11 @@ def v_packaging__version_split(version: str) -> List[str]:
return result 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: def v_packaging__is_not_suffix(segment: str) -> bool:
return not any( return not any(
segment.startswith(prefix) for prefix in ("dev", "a", "b", "rc", "post") 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]) :]) right_split.append(right[len(right_split[0]) :])
left_split.insert(1, ["0"] * max(0, len(right_split[0]) - len(left_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]))) 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): 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 self, specifiers: str = "", prereleases: Optional[bool] = None
) -> None: ) -> None:
split_specifiers = [s.strip() for s in specifiers.split(",") if s.strip()] split_specifiers = [s.strip() for s in specifiers.split(",") if s.strip()]
v_packaging_parsed: Set[v_packaging_Specifier] = set() self._specs = frozenset(map(v_packaging_Specifier, split_specifiers))
for specifier in split_specifiers:
v_packaging_parsed.add(v_packaging_Specifier(specifier))
self._specs = frozenset(v_packaging_parsed)
self._prereleases = prereleases self._prereleases = prereleases
@property @property
@ -1631,7 +1637,7 @@ class v_packaging_SpecifierSet(v_packaging_BaseSpecifier):
specifier._prereleases = self._prereleases specifier._prereleases = self._prereleases
else: else:
raise ValueError( raise ValueError(
"Cannot combine v_packaging_SpecifierSets " "Cannot combine v_packaging_SpecifierSets"
"with True and False prerelease overrides." "with True and False prerelease overrides."
) )
return specifier return specifier
@ -3452,9 +3458,9 @@ class Viv:
"`python3 <(curl -fsSL viv.dayl.in/viv.py) manage install`" "`python3 <(curl -fsSL viv.dayl.in/viv.py) manage install`"
) )
def _pick_bin(self, reqs: List[str], bin: str) -> Tuple[str, str]: def _pick_bin(self, reqs: List[str], bin: str) -> str:
default = system.bin(re.split(r"[=><~!*]+", reqs[0])[0]) default = system.bin(re.split(r"[=><~!*]+", reqs[0])[0])
return default, (default if not bin else bin) return default if not bin else bin
def cmd_shim( def cmd_shim(
self, self,
@ -3463,6 +3469,7 @@ class Viv:
bin: str, bin: str,
output: Path, output: Path,
freeze: bool, freeze: bool,
generate: bool,
yes: bool, yes: bool,
path: str, path: str,
standalone: bool, standalone: bool,
@ -3475,8 +3482,8 @@ class Viv:
viv shim yartsu -o ~/bin/yartsu --standalone viv shim yartsu -o ~/bin/yartsu --standalone
""" """
default_bin, bin = self._pick_bin(reqs, bin) bin = self._pick_bin(reqs, bin)
output = Env().viv_bin_dir / default_bin if not output else output.absolute() output = Env().viv_bin_dir / bin if not output else output.absolute()
if freeze: if freeze:
spec = resolve_deps(reqs, requirements) spec = resolve_deps(reqs, requirements)
@ -3494,6 +3501,11 @@ class Viv:
with output.open("w") as f: with output.open("w") as f:
f.write(self.t.shim(path, self.local_source, standalone, spec, bin)) f.write(self.t.shim(path, self.local_source, standalone, spec, bin))
make_executable(output) make_executable(output)
if generate:
vivenv = ViVenv(spec)
with vivenv.use():
vivenv.meta.addfile(output)
vivenv.meta.write()
def cmd_run( def cmd_run(
self, self,
@ -3520,7 +3532,7 @@ class Viv:
if script: if script:
Script(path=script, spec=spec, keep=keep, rest=rest, viv=self).run() Script(path=script, spec=spec, keep=keep, rest=rest, viv=self).run()
else: else:
_, bin = self._pick_bin(reqs, bin) bin = self._pick_bin(reqs, bin)
vivenv = ViVenv(spec) vivenv = ViVenv(spec)
with vivenv.use(keep=keep): with vivenv.use(keep=keep):
@ -3577,6 +3589,7 @@ class Cli:
), ),
], ],
("shim",): [ ("shim",): [
BoolArg(flag="generate", help="create vivenv w/shim"),
BoolArg( BoolArg(
flag="freeze", flag="freeze",
help="freeze/resolve all dependencies", help="freeze/resolve all dependencies",