mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-12-22 02:30:44 -06:00
fix: use raw string literal
This commit is contained in:
parent
a6bd81dfc3
commit
e257b2a49b
2 changed files with 36 additions and 30 deletions
|
@ -1,32 +1,36 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
def _viv_use(*pkgs, track_exe=False, name=""):
|
# fmt: off
|
||||||
T,F,N=True,False,None;i,s,m,spec=__import__,str,map,[*pkgs]
|
def _viv_use(*pkgs, track_exe=False, name=""): # noqa
|
||||||
e,w=lambda x: T if x else F,lambda p,t: p.write_text(t)
|
T,F,N=True,False,None;i,s,m,spec=__import__,str,map,[*pkgs] # noqa
|
||||||
if not {*m(type,pkgs)}=={s}: raise ValueError(f"spec: {pkgs} is invalid")
|
e,w=lambda x: T if x else F,lambda p,t: p.write_text(t) # noqa
|
||||||
ge,sys,P,ew=i("os").getenv,i("sys"),i("pathlib").Path,i("sys").stderr.write
|
if not {*m(type,pkgs)}=={s}: raise ValueError(f"spec: {pkgs} is invalid") # noqa
|
||||||
(cache:=(P(ge("XDG_CACHE_HOME",P.home()/".cache"))/"viv"/"venvs")).mkdir(parents=T,exist_ok=T)
|
ge,sys,P,ew=i("os").getenv,i("sys"),i("pathlib").Path,i("sys").stderr.write # noqa
|
||||||
((sha256:=i("hashlib").sha256()).update((s(spec)+
|
(cache:=(P(ge("XDG_CACHE_HOME",P.home()/".cache"))/"viv"/"venvs")).mkdir(parents=T,exist_ok=T) # noqa
|
||||||
(((exe:=("N/A",s(P(i("sys").executable).resolve()))[e(track_exe)])))).encode()))
|
((sha256:=i("hashlib").sha256()).update((s(spec)+ # noqa
|
||||||
if {env:=cache/(((_id:=sha256.hexdigest()),name)[e(name)])}-{*cache.glob("*/")} or ge("VIV_FORCE"):
|
(((exe:=("N/A",s(P(i("sys").executable).resolve()))[e(track_exe)])))).encode())) # noqa
|
||||||
v=e(ge("VIV_VERBOSE"));ew(f"generating new vivenv -> {env.name}
|
if {env:=cache/(((_id:=sha256.hexdigest()),name)[e(name)])}-{*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)
|
i("venv").EnvBuilder(with_pip=T,clear=T).create(env) # noqa
|
||||||
w(env/"pip.conf","[global]
|
w(env/"pip.conf","[global]\ndisable-pip-version-check=true") # noqa
|
||||||
disable-pip-version-check=true")
|
if (rc:=(p:=i("subprocess").run([env/"bin"/"pip","install","--force-reinstall",*spec],text=T, # noqa
|
||||||
if (rc:=(p:=i("subprocess").run([env/"bin"/"pip","install","--force-reinstall",*spec],text=T,
|
stdout=(-1,N)[v],stderr=(-2,N)[v])).returncode)!=0: # noqa
|
||||||
stdout=(-1,N)[v],stderr=(-2,N)[v])).returncode)!=0:
|
if env.is_dir():i("shutil").rmtree(env) # noqa
|
||||||
if env.is_dir():i("shutil").rmtree(env)
|
ew(f"pip had non zero exit ({rc})\n{p.stdout}\n");sys.exit(rc) # noqa
|
||||||
ew(f"pip had non zero exit ({rc})
|
w(env/"viv-info.json",i("json").dumps( # noqa
|
||||||
{p.stdout}
|
{"created":s(i("datetime").datetime.today()),"id":_id,"spec":spec,"exe":exe})) # noqa
|
||||||
");sys.exit(rc)
|
sys.path=[p for p in (*sys.path,s(*(env/"lib").glob("py*/si*")))if p!=i("site").USER_SITE] # noqa
|
||||||
w(env/"viv-info.json",i("json").dumps(
|
return env # noqa
|
||||||
{"created":s(i("datetime").datetime.today()),"id":_id,"spec":spec,"exe":exe}))
|
# fmt: on
|
||||||
sys.path=[p for p in (*sys.path,s(*(env/"lib").glob("py*/si*")))if p!=i("site").USER_SITE]
|
|
||||||
return env
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
vivenv = _viv_use("black==23.3.0", "click==8.1.3", "mypy-extensions==1.0.0", "packaging==23.1",
|
vivenv = _viv_use(
|
||||||
"pathspec==0.11.1", "platformdirs==3.5.1")
|
"black==23.3.0",
|
||||||
|
"click==8.1.3",
|
||||||
|
"mypy-extensions==1.0.0",
|
||||||
|
"packaging==23.1", # noqa
|
||||||
|
"pathspec==0.11.1",
|
||||||
|
"platformdirs==3.5.1",
|
||||||
|
) # noqa
|
||||||
sys.exit(subprocess.run([vivenv / "bin" / "black", *sys.argv[1:]]).returncode)
|
sys.exit(subprocess.run([vivenv / "bin" / "black", *sys.argv[1:]]).returncode)
|
||||||
|
|
|
@ -51,7 +51,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.5a4-12-g138809e-dev"
|
__version__ = "23.5a4-13-ga6bd81d-dev"
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
@ -339,7 +339,7 @@ to create/activate a vivenv:
|
||||||
- from command line: `{a.style("viv -h","bold")}`
|
- from command line: `{a.style("viv -h","bold")}`
|
||||||
- within python script: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
|
- within python script: {a.style('__import__("viv").use("typer", "rich-click")','bold')}
|
||||||
"""
|
"""
|
||||||
_standalone_func = """def _viv_use(*pkgs, track_exe=False, name=""):
|
_standalone_func = r"""def _viv_use(*pkgs, track_exe=False, name=""):
|
||||||
T,F,N=True,False,None;i,s,m,spec=__import__,str,map,[*pkgs]
|
T,F,N=True,False,None;i,s,m,spec=__import__,str,map,[*pkgs]
|
||||||
e,w=lambda x: T if x else F,lambda p,t: p.write_text(t)
|
e,w=lambda x: T if x else F,lambda p,t: p.write_text(t)
|
||||||
if not {*m(type,pkgs)}=={s}: raise ValueError(f"spec: {pkgs} is invalid")
|
if not {*m(type,pkgs)}=={s}: raise ValueError(f"spec: {pkgs} is invalid")
|
||||||
|
@ -426,7 +426,9 @@ to create/activate a vivenv:
|
||||||
bin: str,
|
bin: str,
|
||||||
) -> str:
|
) -> str:
|
||||||
if standalone:
|
if standalone:
|
||||||
imports = self._standalone_func
|
imports = "\n".join(
|
||||||
|
("# fmt: off", self.noqa(self._standalone_func), "# fmt: on")
|
||||||
|
)
|
||||||
elif path == "abs":
|
elif path == "abs":
|
||||||
imports = self._absolute_import(local_source)
|
imports = self._absolute_import(local_source)
|
||||||
elif path == "rel":
|
elif path == "rel":
|
||||||
|
@ -440,7 +442,7 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
vivenv = {self._use_str(spec, standalone)}
|
vivenv = {self.noqa(self._use_str(spec, standalone))}
|
||||||
sys.exit(subprocess.run([vivenv / "bin" / "{bin}", *sys.argv[1:]]).returncode)
|
sys.exit(subprocess.run([vivenv / "bin" / "{bin}", *sys.argv[1:]]).returncode)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue