fix: use default setuptools behavior with standalone

This commit is contained in:
Daylin Morgan 2023-08-04 12:32:06 -05:00
parent 5febbe0267
commit 35aa7c2788
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F
2 changed files with 27 additions and 20 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python #!/usr/bin/env python3
# AUTOGENERATED by viv (v23.5a5-19-g93fd53e-dev) # AUTOGENERATED by viv (v23.5a7-6-g5febbe0-dev)
# see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help` # see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help`
@ -14,16 +14,20 @@ def _viv_use(*pkgs, track_exe=False, name=""):
meta = dict.fromkeys(("created", "accessed"), (t := str(datetime.today()))) meta = dict.fromkeys(("created", "accessed"), (t := str(datetime.today())))
runner = str(Path(__file__).absolute().resolve()) runner = str(Path(__file__).absolute().resolve())
force, verbose, xdg = map(os.getenv, ("VIV_FORCE", "VIV_VERBOSE", "XDG_CACHE_HOME")) 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 = (Path(xdg) if xdg else Path.home() / ".cache") / "viv" / "venvs"
cache.mkdir(parents=True, exist_ok=True) cache.mkdir(parents=True, exist_ok=True)
exe = str(Path(sys.executable).resolve()) if track_exe else "N/A" exe = str(Path(sys.executable).resolve()) if track_exe else "N/A"
(sha256 := hashlib.sha256()).update((str(spec := [*pkgs]) + exe).encode()) (sha256 := hashlib.sha256()).update((str(spec := [*pkgs]) + exe).encode())
_id = sha256.hexdigest() _id = sha256.hexdigest()
if (env := cache / (name if name else _id)) not in cache.glob("*/") or force: if (env := cache / (name if name else _id)) not in cache.glob("*/") or F:
sys.stderr.write(f"generating new vivenv -> {env.name}\n") sys.stderr.write(f"generating new vivenv -> {env.name}\n")
venv.create(env, symlinks=True, clear=True) venv.create(env, prompt=f"viv-{name}", symlinks=True, clear=True)
kw = dict(zip(("stdout", "stderr"), ((None,) * 2 if verbose else (-1, 2)))) 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] cmd = ["pip", "--python", str(env / "bin" / "python"), "install", *spec]
p = run(cmd, **kw) p = run(cmd, **kw)
if (rc := p.returncode) != 0: if (rc := p.returncode) != 0:
@ -35,7 +39,6 @@ def _viv_use(*pkgs, track_exe=False, name=""):
else: else:
meta = json.loads((env / "vivmeta.json").read_text()) meta = json.loads((env / "vivmeta.json").read_text())
meta.update(dict(accessed=t, files=sorted({*meta["files"], runner}))) meta.update(dict(accessed=t, files=sorted({*meta["files"], runner})))
(env / "vivmeta.json").write_text(json.dumps(meta)) (env / "vivmeta.json").write_text(json.dumps(meta))
site.addsitedir(sitepkgs := str(*(env / "lib").glob("py*/si*"))) site.addsitedir(sitepkgs := str(*(env / "lib").glob("py*/si*")))
sys.path = [p for p in (sitepkgs, *sys.path) if p != site.USER_SITE] sys.path = [p for p in (sitepkgs, *sys.path) if p != site.USER_SITE]
@ -47,13 +50,11 @@ import sys
if __name__ == "__main__": if __name__ == "__main__":
vivenv = _viv_use( vivenv = _viv_use(
"black==23.3.0", "black==23.7.0",
"click==8.1.3", "click==8.1.6",
"mypy-extensions==1.0.0", "mypy-extensions==1.0.0",
"packaging==23.1", # noqa "packaging==23.1", # noqa
"pathspec==0.11.1", "pathspec==0.11.2",
"platformdirs==3.5.1", "platformdirs==3.10.0",
"tomli==2.0.1",
"typing_extensions==4.6.3",
) # noqa ) # noqa
sys.exit(subprocess.run([vivenv / "bin" / "black", *sys.argv[1:]]).returncode) sys.exit(subprocess.run([vivenv / "bin" / "black", *sys.argv[1:]]).returncode)

View file

@ -52,7 +52,7 @@ from typing import (
from urllib.error import HTTPError from urllib.error import HTTPError
from urllib.request import urlopen from urllib.request import urlopen
__version__ = "23.5a7-5-g0411f81-dev" __version__ = "23.5a7-7-g752dbd1-dev"
class Spinner: class Spinner:
@ -339,16 +339,20 @@ class Template:
meta = dict.fromkeys(("created", "accessed"), (t := str(datetime.today()))) meta = dict.fromkeys(("created", "accessed"), (t := str(datetime.today())))
runner = str(Path(__file__).absolute().resolve()) runner = str(Path(__file__).absolute().resolve())
force, verbose, xdg = map(os.getenv, ("VIV_FORCE", "VIV_VERBOSE", "XDG_CACHE_HOME")) 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 = (Path(xdg) if xdg else Path.home() / ".cache") / "viv" / "venvs"
cache.mkdir(parents=True, exist_ok=True) cache.mkdir(parents=True, exist_ok=True)
exe = str(Path(sys.executable).resolve()) if track_exe else "N/A" exe = str(Path(sys.executable).resolve()) if track_exe else "N/A"
(sha256 := hashlib.sha256()).update((str(spec := [*pkgs]) + exe).encode()) (sha256 := hashlib.sha256()).update((str(spec := [*pkgs]) + exe).encode())
_id = sha256.hexdigest() _id = sha256.hexdigest()
if (env := cache / (name if name else _id)) not in cache.glob("*/") or force: if (env := cache / (name if name else _id)) not in cache.glob("*/") or F:
sys.stderr.write(f"generating new vivenv -> {env.name}\n") sys.stderr.write(f"generating new vivenv -> {env.name}\n")
venv.create(env, prompt=f"viv-{name}", symlinks=True, clear=True) venv.create(env, prompt=f"viv-{name}", symlinks=True, clear=True)
kw = dict(zip(("stdout", "stderr"), ((None,) * 2 if verbose else (-1, 2)))) 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] cmd = ["pip", "--python", str(env / "bin" / "python"), "install", *spec]
p = run(cmd, **kw) p = run(cmd, **kw)
if (rc := p.returncode) != 0: if (rc := p.returncode) != 0:
@ -360,7 +364,6 @@ class Template:
else: else:
meta = json.loads((env / "vivmeta.json").read_text()) meta = json.loads((env / "vivmeta.json").read_text())
meta.update(dict(accessed=t, files=sorted({*meta["files"], runner}))) meta.update(dict(accessed=t, files=sorted({*meta["files"], runner})))
(env / "vivmeta.json").write_text(json.dumps(meta)) (env / "vivmeta.json").write_text(json.dumps(meta))
site.addsitedir(sitepkgs := str(*(env / "lib").glob("py*/si*"))) site.addsitedir(sitepkgs := str(*(env / "lib").glob("py*/si*")))
sys.path = [p for p in (sitepkgs, *sys.path) if p != site.USER_SITE] sys.path = [p for p in (sitepkgs, *sys.path) if p != site.USER_SITE]
@ -397,6 +400,7 @@ python api: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
return f""" return f"""
# AUTOGENERATED by viv (v{__version__}) # AUTOGENERATED by viv (v{__version__})
# see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help` # see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help`
{func_use} {func_use}
""" """
@ -406,7 +410,7 @@ python api: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
raise ValueError("local source must exist") raise ValueError("local source must exist")
path_to_viv = path_to_viv = str( path_to_viv = path_to_viv = str(
local_source.resolve().absolute().parent.parent local_source.resolve().absolute().parent
).replace(str(Path.home()), "~") ).replace(str(Path.home()), "~")
return ( return (
"""__import__("sys").path.append(__import__("os")""" """__import__("sys").path.append(__import__("os")"""
@ -418,7 +422,7 @@ python api: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
if not local_source: if not local_source:
raise ValueError("local source must exist") raise ValueError("local source must exist")
path_to_viv = local_source.resolve().absolute().parent.parent path_to_viv = local_source.resolve().absolute().parent
return f"""__import__("sys").path.append("{path_to_viv}") # noqa""" return f"""__import__("sys").path.append("{path_to_viv}") # noqa"""
@classmethod @classmethod
@ -458,7 +462,9 @@ python api: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
# AUTOGENERATED by viv (v{__version__}) # AUTOGENERATED by viv (v{__version__})
# see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help` # see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help`
{imports} {imports}
import subprocess import subprocess
import sys import sys