refactor!: activate -> use

This commit is contained in:
Daylin Morgan 2023-03-15 13:16:09 -05:00
parent 992d039285
commit ccf8e0ec61
Signed by: daylin
GPG Key ID: C1E52E7DD81DF79F
13 changed files with 26 additions and 26 deletions

View File

@ -69,7 +69,7 @@ In any python script with external dependencies you can add this line,
to automate `vivenv` creation and installation of dependencies.
```python
__import__("viv").activate("click")
__import__("viv").use("click")
```
To remove all `vivenvs`:
@ -89,13 +89,13 @@ no modification of your PYTHONPATH or import of additional modules (including do
It can be auto-generated with for example: `viv freeze <spec> --standalone`.
The only part necessary to modify if copied verbatim from below is the call to `_viv_activate`.
The only part necessary to modify if copied verbatim from below is the call to `_viv_use`.
output of `viv freeze rich --standalone`:
```python
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
# fmt: off
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None: # noqa
def _viv_use(*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
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
@ -113,7 +113,7 @@ def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None:
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
_viv_activate("markdown-it-py==2.2.0", "mdurl==0.1.2", "Pygments==2.14.0", "rich==13.3.2") # noqa
_viv_use("markdown-it-py==2.2.0", "mdurl==0.1.2", "Pygments==2.14.0", "rich==13.3.2") # noqa
# fmt: on
# >>>>> code golfed with <3
```

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
__import__("viv").activate("pyfiglet==0.8.post1") # noqa
__import__("viv").use("pyfiglet==0.8.post1") # noqa
from pyfiglet import Figlet

View File

@ -4,7 +4,7 @@ It can be convenient to quickly generate a cli for a short script.
Or to add simple visualization of data using the wonderful rich library.
"""
__import__("viv").activate("typer", "rich-click") # noqa
__import__("viv").use("typer", "rich-click") # noqa
import typer

View File

@ -7,7 +7,7 @@ it will generate a new vivenv.
It may be important to require a exe specificty if you are frequently running
different version of pythons and rely on c extension modules as in numpy.
"""
__import__("viv").activate("numpy", "plotext", track_exe=True) # noqa
__import__("viv").use("numpy", "plotext", track_exe=True) # noqa
import numpy as np
import plotext as plt

View File

@ -6,7 +6,7 @@ This import statement was generated using
Using viv freeze ensures future runs of this
script will use the same essential environment
"""
__import__("viv").activate(
__import__("viv").use(
"numpy==1.24.0",
"pandas==1.5.2",
"python-dateutil==2.8.2",

View File

@ -7,7 +7,7 @@ Meaning that it will save it within the viv cache not using a hash.
*This environment could then be reused by specifying the name*
"""
__import__("viv").activate("rich", name="rich-env")
__import__("viv").use("rich", name="rich-env")
from rich.console import Console
from rich.markdown import Markdown

View File

@ -6,7 +6,7 @@ modified from:
https://medium.com/analytics-vidhya/a-super-easy-python-script-for-web-scraping-that-anybody-can-use-d3bd6ab86c89
"""
__import__("viv").activate("requests", "bs4", "rich") # noqa
__import__("viv").use("requests", "bs4", "rich") # noqa
import requests
from bs4 import BeautifulSoup

View File

@ -7,7 +7,7 @@ With this function it's not necessary for
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
# fmt: off
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None: # noqa
def _viv_use(*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
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
@ -25,7 +25,7 @@ def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None:
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
_viv_activate("pyfiglet==0.8.post1") # noqa
_viv_use("pyfiglet==0.8.post1") # noqa
# fmt: on
# >>>>> code golfed with <3

View File

@ -3,7 +3,7 @@
https://github.com/Textualize/textual/tree/main/docs/examples/tutorial
"""
__import__("viv").activate("textual")
__import__("viv").use("textual")
from time import monotonic

View File

@ -7,7 +7,7 @@ Embed the viv.py on the sys.path at runtime rather than using PYTHONPATH
__import__("sys").path.append(
__import__("os").path.expanduser("~/.viv/src")
) # noqa # isort: off
__import__("viv").activate("pyfiglet") # noqa # isort: off
__import__("viv").use("pyfiglet") # noqa # isort: off
import sys

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
# ints are not allowed
__import__("viv").activate(5)
__import__("viv").use(5)

View File

@ -1 +1 @@
from .viv import activate # noqa
from .viv import use # noqa

View File

@ -3,7 +3,7 @@
viv -h
OR
__import__("viv").activate("requests", "bs4")
__import__("viv").use("requests", "bs4")
"""
import hashlib
@ -419,7 +419,7 @@ class ViVenv:
a.table((("key", "value"), *((k, v) for k, v in info.items())))
def activate(*packages: str, track_exe: bool = False, name: str = "") -> None:
def use(*packages: str, track_exe: bool = False, name: str = "") -> None:
"""create a vivenv and append to sys.path
Args:
@ -476,18 +476,18 @@ REL_SYS_PATH_TEMPLATE = (
"""__import__("sys").path.append(__import__("os")"""
""".path.expanduser("{path_to_viv}")) # noqa"""
)
IMPORT_TEMPLATE = """__import__("viv").activate({spec}) # noqa"""
IMPORT_TEMPLATE = """__import__("viv").use({spec}) # noqa"""
STANDALONE_TEMPLATE = r"""
# <<<<< auto-generated by daylinmorgan/viv (v.22.12a3)
# fmt: off
{activate}
{use}
# fmt: on
# >>>>> code golfed with <3
""" # noqa
STANDALONE_TEMPLATE_ACTIVATE = r"""
def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None:
STANDALONE_TEMPLATE_USE = r"""
def _viv_use(*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]
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
@ -505,7 +505,7 @@ def _viv_activate(*pkgs: str, track_exe: bool = False, name: str = "") -> None:
with (env/"viv-info.json").open("w") as f:
i("json").dump({{"created":s(i("datetime").datetime.today()),"id":_id,"spec":spec,"exe":exe}},f)
sys.path = [p for p in (*sys.path,s(*(env/"lib").glob("py*/si*"))) if p!=i("site").USER_SITE]
_viv_activate({spec})
_viv_use({spec})
"""[ # noqa
1:
]
@ -586,8 +586,8 @@ def generate_import(
sys.stdout.write(
STANDALONE_TEMPLATE.format(
version=__version__,
activate=noqa(
STANDALONE_TEMPLATE_ACTIVATE.format(
use=noqa(
STANDALONE_TEMPLATE_USE.format(
spec=", ".join(f'"{pkg}"' for pkg in resolved_spec.splitlines())
)
),
@ -758,7 +758,7 @@ description = f"""
from command line:
`{a.style("viv -h","bold")}`
within python script:
{a.style('__import__("viv").activate("typer", "rich-click")','bold')}
{a.style('__import__("viv").use("typer", "rich-click")','bold')}
"""