2023-03-07 14:36:51 -06:00
|
|
|
#!/usr/bin/env python3
|
2023-03-14 12:35:00 -05:00
|
|
|
"""
|
|
|
|
Example using the output of `viv freeze pyfiglet --standalone`.
|
|
|
|
With this function it's not necessary for
|
|
|
|
`viv` to exist anywhere on the system.
|
|
|
|
"""
|
2023-03-07 14:36:51 -06:00
|
|
|
|
2023-03-15 16:15:06 -05:00
|
|
|
# <<<<< auto-generated by daylinmorgan/viv (v22.12a3-35-g0d0c66d-dev)
|
2023-03-07 14:36:51 -06:00
|
|
|
# fmt: off
|
2023-03-15 16:15:06 -05:00
|
|
|
def _viv_use(*pkgs: str, track_exe: bool = False, name: str = "") -> None: # noqa
|
2023-03-13 09:07:18 -05:00
|
|
|
i,s,m,e,spec=__import__,str,map,lambda x: True if x else False,[*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=True,exist_ok=True) # noqa
|
|
|
|
((sha256:=i("hashlib").sha256()).update((s(spec)+ # noqa
|
2023-03-14 12:35:00 -05:00
|
|
|
(((exe:=("N/A",s(P(i("sys").executable).resolve()))[e(track_exe)])))).encode())) # noqa
|
2023-03-13 09:07:18 -05:00
|
|
|
if (env:=cache/(name if name else (_id:=sha256.hexdigest()))) 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=True,clear=True).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()),"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
|
2023-03-15 16:15:06 -05:00
|
|
|
_viv_use("pyfiglet==0.8.post1") # noqa
|
2023-03-07 14:36:51 -06:00
|
|
|
# fmt: on
|
|
|
|
# >>>>> code golfed with <3
|
|
|
|
|
|
|
|
from pyfiglet import Figlet
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
f = Figlet(font="slant")
|
|
|
|
figtxt = f.renderText("viv").splitlines()
|
|
|
|
figtxt[-2] += " isn't venv!"
|
|
|
|
print("\n".join(figtxt))
|