mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-12-22 10:40:44 -06:00
refactor: don't shadow hash function
This commit is contained in:
parent
b9100ca2a1
commit
9c2581fafd
3 changed files with 46 additions and 42 deletions
11
README.md
11
README.md
|
@ -80,6 +80,8 @@ viv remove $(viv list -q)
|
||||||
|
|
||||||
# Standalone Viv
|
# Standalone Viv
|
||||||
|
|
||||||
|
*Requires* `python>=3.8`
|
||||||
|
|
||||||
Supposing you want to increase the portability of your script while still employing `viv`.
|
Supposing you want to increase the portability of your script while still employing `viv`.
|
||||||
|
|
||||||
The below function can be freely pasted at the top of your scripts and requires
|
The below function can be freely pasted at the top of your scripts and requires
|
||||||
|
@ -91,16 +93,17 @@ The only part necessary to modify if copied verbatim from below is the call to `
|
||||||
|
|
||||||
output of `viv freeze rich --standalone`:
|
output of `viv freeze rich --standalone`:
|
||||||
```python
|
```python
|
||||||
|
|
||||||
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
|
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
|
||||||
# fmt: off
|
# fmt: off
|
||||||
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None: # noqa
|
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None: # noqa
|
||||||
i,s,m,e,spec=__import__,str,map,lambda x: True if x else False, [*pkgs] # noqa
|
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
|
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
|
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
|
(cache:=(P(ge("XDG_CACHE_HOME",P.home()/".cache"))/"viv"/"venvs")).mkdir(parents=True,exist_ok=True) # noqa
|
||||||
((hash:=i("hashlib").sha256()).update((s(spec)+ # noqa
|
((sha256:=i("hashlib").sha256()).update((s(spec)+ # noqa
|
||||||
(((exe:=s(P(i("sys").executable).resolve()) if track_exe else "N/A")))).encode())) # noqa
|
(((exe:=s(P(i("sys").executable).resolve()) if track_exe else "N/A")))).encode())) # noqa
|
||||||
if (env:=cache/(name if name else (_id:=hash.hexdigest()))) not in cache.glob("*/") or ge("VIV_FORCE"): # noqa
|
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
|
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
|
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
|
with (env/"pip.conf").open("w") as f:f.write("[global]\ndisable-pip-version-check=true") # noqa
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
|
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
|
||||||
# fmt: off
|
# fmt: off
|
||||||
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None: # noqa
|
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None: # noqa
|
||||||
i,s,m,e,spec=__import__,str,map,lambda x: True if x else False, [*pkgs] # noqa
|
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
|
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
|
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
|
(cache:=(P(ge("XDG_CACHE_HOME",P.home()/".cache"))/"viv"/"venvs")).mkdir(parents=True,exist_ok=True) # noqa
|
||||||
((hash:=i("hashlib").sha256()).update((s(spec)+ # noqa
|
((sha256:=i("hashlib").sha256()).update((s(spec)+ # noqa
|
||||||
(((exe:=s(P(i("sys").executable).resolve()) if track_exe else "N/A")))).encode())) # noqa
|
(((exe:=s(P(i("sys").executable).resolve()) if track_exe else "N/A")))).encode())) # noqa
|
||||||
if (env:=cache/(name if name else (_id:=hash.hexdigest()))) not in cache.glob("*/") or ge("VIV_FORCE"): # noqa
|
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
|
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
|
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
|
with (env/"pip.conf").open("w") as f:f.write("[global]\ndisable-pip-version-check=true") # noqa
|
||||||
|
@ -24,6 +24,7 @@ _viv_activate("pyfiglet==0.8.post1")
|
||||||
# fmt: on
|
# fmt: on
|
||||||
# >>>>> code golfed with <3
|
# >>>>> code golfed with <3
|
||||||
|
|
||||||
|
|
||||||
from pyfiglet import Figlet
|
from pyfiglet import Figlet
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -487,13 +487,13 @@ STANDALONE_TEMPLATE = r"""
|
||||||
|
|
||||||
STANDALONE_TEMPLATE_ACTIVATE = r"""
|
STANDALONE_TEMPLATE_ACTIVATE = r"""
|
||||||
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None:
|
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None:
|
||||||
i,s,m,e,spec=__import__,str,map,lambda x: True if x else False, [*pkgs]
|
i,s,m,e,spec=__import__,str,map,lambda x: True if x else False,[*pkgs]
|
||||||
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")
|
||||||
ge,sys,P,ew=i("os").getenv,i("sys"),i("pathlib").Path,i("sys").stderr.write
|
ge,sys,P,ew=i("os").getenv,i("sys"),i("pathlib").Path,i("sys").stderr.write
|
||||||
(cache:=(P(ge("XDG_CACHE_HOME",P.home()/".cache"))/"viv"/"venvs")).mkdir(parents=True, exist_ok=True)
|
(cache:=(P(ge("XDG_CACHE_HOME",P.home()/".cache"))/"viv"/"venvs")).mkdir(parents=True,exist_ok=True)
|
||||||
((hash:=i("hashlib").sha256()).update((s(spec)+
|
((sha256:=i("hashlib").sha256()).update((s(spec)+
|
||||||
(((exe:=s(P(i("sys").executable).resolve()) if track_exe else "N/A")))).encode()))
|
(((exe:=s(P(i("sys").executable).resolve()) if track_exe else "N/A")))).encode()))
|
||||||
if (env:=cache/(name if name else (_id:=hash.hexdigest()))) not in cache.glob("*/") or ge("VIV_FORCE"):
|
if (env:=cache/(name if name else (_id:=sha256.hexdigest()))) not in cache.glob("*/") or ge("VIV_FORCE"):
|
||||||
v=e(ge("VIV_VERBOSE"));ew(f"generating new vivenv -> {{env.name}}\n")
|
v=e(ge("VIV_VERBOSE"));ew(f"generating new vivenv -> {{env.name}}\n")
|
||||||
i("venv").EnvBuilder(with_pip=True,clear=True).create(env)
|
i("venv").EnvBuilder(with_pip=True,clear=True).create(env)
|
||||||
with (env/"pip.conf").open("w") as f:f.write("[global]\ndisable-pip-version-check=true")
|
with (env/"pip.conf").open("w") as f:f.write("[global]\ndisable-pip-version-check=true")
|
||||||
|
|
Loading…
Reference in a new issue