diff --git a/examples/black b/examples/black index 8e0ec92..b07524a 100755 --- a/examples/black +++ b/examples/black @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -# AUTOGENERATED by viv (v23.5a7-6-g5febbe0-dev) +# AUTOGENERATED by viv (v23.8a1-5-g4c782db-dev) # see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help` @@ -14,21 +14,19 @@ def _viv_use(*pkgs, track_exe=False, name=""): meta = dict.fromkeys(("created", "accessed"), (t := str(datetime.today()))) runner = str(Path(__file__).absolute().resolve()) - env = lambda x: os.getenv(f"VIV_{x}") # noqa - F, V, no_st = map(env, ("FORCE", "VERBOSE", "NO_SETUPTOOLS")) - xdg = os.getenv("XDG_CACHE_HOME") - cache = (Path(xdg) if xdg else Path.home() / ".cache") / "viv" / "venvs" - cache.mkdir(parents=True, exist_ok=True) + envvar = lambda x: os.getenv(f"VIV_{x}") # noqa + F, V, no_st = map(envvar, ("FORCE", "VERBOSE", "NO_SETUPTOOLS")) + base = Path(xdg) if (xdg := os.getenv("XDG_CACHE_HOME")) else Path.home() / ".cache" + (cache := (base) / "viv/venvs").mkdir(parents=True, exist_ok=True) exe = str(Path(sys.executable).resolve()) if track_exe else "N/A" - (sha256 := hashlib.sha256()).update((str(spec := [*pkgs]) + exe).encode()) - _id = sha256.hexdigest() + _id = hashlib.sha256((str(spec := [*pkgs]) + exe).encode()).hexdigest() if (env := cache / (name if name else _id)) not in cache.glob("*/") or F: sys.stderr.write(f"generating new vivenv -> {env.name}\n") venv.create(env, prompt=f"viv-{name}", symlinks=True, clear=True) kw = dict(zip(("stdout", "stderr"), ((None,) * 2 if V else (-1, 2)))) - if (not no_st) and (not [x for x in spec if x.startswith("setuptools")]): - spec.append("setuptools") cmd = ["pip", "--python", str(env / "bin" / "python"), "install", *spec] + if (not no_st) and (not [x for x in spec if x.startswith("setuptools")]): + cmd.append("setuptools") p = run(cmd, **kw) if (rc := p.returncode) != 0: if env.is_dir(): diff --git a/src/viv/viv.py b/src/viv/viv.py index 64cffb0..72f87cf 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -53,7 +53,7 @@ from typing import ( from urllib.error import HTTPError from urllib.request import urlopen -__version__ = "23.8a1-3-ga78624c-dev" +__version__ = "23.8a1-5-g4c782db-dev" class Spinner: @@ -340,21 +340,19 @@ class Template: meta = dict.fromkeys(("created", "accessed"), (t := str(datetime.today()))) runner = str(Path(__file__).absolute().resolve()) - env = lambda x: os.getenv(f"VIV_{x}") # noqa - F, V, no_st = map(env, ("FORCE", "VERBOSE", "NO_SETUPTOOLS")) - xdg = os.getenv("XDG_CACHE_HOME") - cache = (Path(xdg) if xdg else Path.home() / ".cache") / "viv" / "venvs" - cache.mkdir(parents=True, exist_ok=True) + envvar = lambda x: os.getenv(f"VIV_{x}") # noqa + F, V, no_st = map(envvar, ("FORCE", "VERBOSE", "NO_SETUPTOOLS")) + base = Path(xdg) if (xdg := os.getenv("XDG_CACHE_HOME")) else Path.home() / ".cache" + (cache := (base) / "viv/venvs").mkdir(parents=True, exist_ok=True) exe = str(Path(sys.executable).resolve()) if track_exe else "N/A" - (sha256 := hashlib.sha256()).update((str(spec := [*pkgs]) + exe).encode()) - _id = sha256.hexdigest() + _id = hashlib.sha256((str(spec := [*pkgs]) + exe).encode()).hexdigest() if (env := cache / (name if name else _id)) not in cache.glob("*/") or F: sys.stderr.write(f"generating new vivenv -> {env.name}\n") venv.create(env, prompt=f"viv-{name}", symlinks=True, clear=True) kw = dict(zip(("stdout", "stderr"), ((None,) * 2 if V else (-1, 2)))) - if (not no_st) and (not [x for x in spec if x.startswith("setuptools")]): - spec.append("setuptools") cmd = ["pip", "--python", str(env / "bin" / "python"), "install", *spec] + if (not no_st) and (not [x for x in spec if x.startswith("setuptools")]): + cmd.append("setuptools") p = run(cmd, **kw) if (rc := p.returncode) != 0: if env.is_dir():