From ccf8e0ec61ef7a5dcca5c881025ab70376aa68a7 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 15 Mar 2023 13:16:09 -0500 Subject: [PATCH] refactor!: activate -> use --- README.md | 8 ++++---- docs/demo.py | 2 +- examples/cli.py | 2 +- examples/exe_specific.py | 2 +- examples/frozen_import.py | 2 +- examples/named_env.py | 2 +- examples/scrape.py | 2 +- examples/standalone.py | 4 ++-- examples/stopwatch.py | 2 +- examples/sys_path.py | 2 +- examples/wrong_input.py | 2 +- src/viv/__init__.py | 2 +- src/viv/viv.py | 20 ++++++++++---------- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index be108eb..f4a80f3 100644 --- a/README.md +++ b/README.md @@ -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 --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 ``` diff --git a/docs/demo.py b/docs/demo.py index 27819e8..0878927 100644 --- a/docs/demo.py +++ b/docs/demo.py @@ -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 diff --git a/examples/cli.py b/examples/cli.py index 540daae..667ead8 100644 --- a/examples/cli.py +++ b/examples/cli.py @@ -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 diff --git a/examples/exe_specific.py b/examples/exe_specific.py index c91858e..dbc790d 100644 --- a/examples/exe_specific.py +++ b/examples/exe_specific.py @@ -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 diff --git a/examples/frozen_import.py b/examples/frozen_import.py index e31f728..b863ea7 100644 --- a/examples/frozen_import.py +++ b/examples/frozen_import.py @@ -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", diff --git a/examples/named_env.py b/examples/named_env.py index 304c649..b1e20f9 100644 --- a/examples/named_env.py +++ b/examples/named_env.py @@ -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 diff --git a/examples/scrape.py b/examples/scrape.py index 4179d92..227898f 100644 --- a/examples/scrape.py +++ b/examples/scrape.py @@ -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 diff --git a/examples/standalone.py b/examples/standalone.py index df412b0..3adb88f 100644 --- a/examples/standalone.py +++ b/examples/standalone.py @@ -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 diff --git a/examples/stopwatch.py b/examples/stopwatch.py index d37f32e..3fbcc61 100644 --- a/examples/stopwatch.py +++ b/examples/stopwatch.py @@ -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 diff --git a/examples/sys_path.py b/examples/sys_path.py index 9fb4d7f..dfef4fa 100644 --- a/examples/sys_path.py +++ b/examples/sys_path.py @@ -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 diff --git a/examples/wrong_input.py b/examples/wrong_input.py index 073d6e2..08f4bc1 100644 --- a/examples/wrong_input.py +++ b/examples/wrong_input.py @@ -1,4 +1,4 @@ #!/usr/bin/env python3 # ints are not allowed -__import__("viv").activate(5) +__import__("viv").use(5) diff --git a/src/viv/__init__.py b/src/viv/__init__.py index 41a843b..6a86724 100644 --- a/src/viv/__init__.py +++ b/src/viv/__init__.py @@ -1 +1 @@ -from .viv import activate # noqa +from .viv import use # noqa diff --git a/src/viv/viv.py b/src/viv/viv.py index 7a6ea18..968b71d 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -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')} """