mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-12-22 18:50:43 -06:00
43 lines
2.7 KiB
Python
Executable file
43 lines
2.7 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
|
|
# <<<<< auto-generated by viv (v23.5a2-2-gebb657c-dev)
|
|
# see `python3 <(curl -fsSL gh.dayl.in/viv/viv.py) --help`
|
|
# fmt: off
|
|
def _viv_use(*pkgs, track_exe=False, name=""): # noqa
|
|
T,F=True,False;i,s,m,e,spec=__import__,str,map,lambda x: T if x else F,[*pkgs] # noqa
|
|
if not {*m(type,pkgs)}=={s}: raise ValueError(f"spec: {pkgs} is invalid") # noqa
|
|
ge,sys,P,ew=i("os").getenv,i("sys"),i("pathlib").Path,i("sys").stderr.write # noqa
|
|
(cache:=(P(ge("XDG_CACHE_HOME",P.home()/".cache"))/"viv"/"venvs")).mkdir(parents=T,exist_ok=T) # noqa
|
|
((sha256:=i("hashlib").sha256()).update((s(spec)+ # noqa
|
|
(((exe:=("N/A",s(P(i("sys").executable).resolve()))[e(track_exe)])))).encode())) # noqa
|
|
if ((env:=cache/(name if name else (_id:=sha256.hexdigest()))) # noqa
|
|
not in cache.glob("*/")) or ge("VIV_FORCE"): # noqa
|
|
v=e(ge("VIV_VERBOSE"));ew(f"generating new vivenv -> {env.name}\n") # noqa
|
|
i("venv").EnvBuilder(with_pip=T,clear=T).create(env) # noqa
|
|
with (env/"pip.conf").open("w") as f:f.write("[global]\ndisable-pip-version-check=true") # noqa
|
|
if (p:=i("subprocess").run([env/"bin"/"pip","install","--force-reinstall",*spec],text=True, # noqa
|
|
stdout=(-1,None)[v],stderr=(-2,None)[v])).returncode!=0: # noqa
|
|
if env.is_dir():i("shutil").rmtree(env) # noqa
|
|
ew(f"pip had non zero exit ({p.returncode})\n{p.stdout}\n");sys.exit(p.returncode) # noqa
|
|
with (env/"viv-info.json").open("w") as f: # noqa
|
|
i("json").dump({"created":s(i("datetime").datetime.today()), # noqa
|
|
"id":_id,"spec":spec,"exe":exe},f) # noqa
|
|
sys.path = [p for p in (*sys.path,s(*(env/"lib").glob("py*/si*"))) if p!=i("site").USER_SITE] # noqa
|
|
return env # noqa
|
|
# fmt: on
|
|
# >>>>> code golfed with <3
|
|
|
|
import subprocess
|
|
import sys
|
|
|
|
if __name__ == "__main__":
|
|
vivenv = _viv_use(
|
|
"black==23.3.0",
|
|
"click==8.1.3",
|
|
"mypy-extensions==1.0.0",
|
|
"packaging==23.1",
|
|
"pathspec==0.11.1",
|
|
"platformdirs==3.5.1",
|
|
)
|
|
sys.exit(subprocess.run([vivenv / "bin" / "black", *sys.argv[1:]]).returncode)
|