mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-13 20:47:53 -06:00
fix: use default setuptools behavior with standalone
This commit is contained in:
parent
5febbe0267
commit
35aa7c2788
2 changed files with 27 additions and 20 deletions
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env python
|
||||
# AUTOGENERATED by viv (v23.5a5-19-g93fd53e-dev)
|
||||
#!/usr/bin/env python3
|
||||
# AUTOGENERATED by viv (v23.5a7-6-g5febbe0-dev)
|
||||
# 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())))
|
||||
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.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()
|
||||
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")
|
||||
venv.create(env, symlinks=True, clear=True)
|
||||
kw = dict(zip(("stdout", "stderr"), ((None,) * 2 if verbose else (-1, 2))))
|
||||
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]
|
||||
p = run(cmd, **kw)
|
||||
if (rc := p.returncode) != 0:
|
||||
|
@ -35,7 +39,6 @@ def _viv_use(*pkgs, track_exe=False, name=""):
|
|||
else:
|
||||
meta = json.loads((env / "vivmeta.json").read_text())
|
||||
meta.update(dict(accessed=t, files=sorted({*meta["files"], runner})))
|
||||
|
||||
(env / "vivmeta.json").write_text(json.dumps(meta))
|
||||
site.addsitedir(sitepkgs := str(*(env / "lib").glob("py*/si*")))
|
||||
sys.path = [p for p in (sitepkgs, *sys.path) if p != site.USER_SITE]
|
||||
|
@ -47,13 +50,11 @@ import sys
|
|||
|
||||
if __name__ == "__main__":
|
||||
vivenv = _viv_use(
|
||||
"black==23.3.0",
|
||||
"click==8.1.3",
|
||||
"black==23.7.0",
|
||||
"click==8.1.6",
|
||||
"mypy-extensions==1.0.0",
|
||||
"packaging==23.1", # noqa
|
||||
"pathspec==0.11.1",
|
||||
"platformdirs==3.5.1",
|
||||
"tomli==2.0.1",
|
||||
"typing_extensions==4.6.3",
|
||||
"pathspec==0.11.2",
|
||||
"platformdirs==3.10.0",
|
||||
) # noqa
|
||||
sys.exit(subprocess.run([vivenv / "bin" / "black", *sys.argv[1:]]).returncode)
|
||||
|
|
|
@ -52,7 +52,7 @@ from typing import (
|
|||
from urllib.error import HTTPError
|
||||
from urllib.request import urlopen
|
||||
|
||||
__version__ = "23.5a7-5-g0411f81-dev"
|
||||
__version__ = "23.5a7-7-g752dbd1-dev"
|
||||
|
||||
|
||||
class Spinner:
|
||||
|
@ -339,16 +339,20 @@ class Template:
|
|||
|
||||
meta = dict.fromkeys(("created", "accessed"), (t := str(datetime.today())))
|
||||
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.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()
|
||||
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")
|
||||
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]
|
||||
p = run(cmd, **kw)
|
||||
if (rc := p.returncode) != 0:
|
||||
|
@ -360,7 +364,6 @@ class Template:
|
|||
else:
|
||||
meta = json.loads((env / "vivmeta.json").read_text())
|
||||
meta.update(dict(accessed=t, files=sorted({*meta["files"], runner})))
|
||||
|
||||
(env / "vivmeta.json").write_text(json.dumps(meta))
|
||||
site.addsitedir(sitepkgs := str(*(env / "lib").glob("py*/si*")))
|
||||
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"""
|
||||
# AUTOGENERATED by viv (v{__version__})
|
||||
# see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help`
|
||||
|
||||
{func_use}
|
||||
"""
|
||||
|
||||
|
@ -406,7 +410,7 @@ python api: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
|
|||
raise ValueError("local source must exist")
|
||||
|
||||
path_to_viv = path_to_viv = str(
|
||||
local_source.resolve().absolute().parent.parent
|
||||
local_source.resolve().absolute().parent
|
||||
).replace(str(Path.home()), "~")
|
||||
return (
|
||||
"""__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:
|
||||
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"""
|
||||
|
||||
@classmethod
|
||||
|
@ -458,7 +462,9 @@ python api: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
|
|||
# AUTOGENERATED by viv (v{__version__})
|
||||
# see `python3 <(curl -fsSL viv.dayl.in/viv.py) --help`
|
||||
|
||||
|
||||
{imports}
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
|
Loading…
Reference in a new issue