mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-12-22 10:40:44 -06:00
refactor: use method instead of standalone function
This commit is contained in:
parent
79ae1da47b
commit
e697488dda
1 changed files with 9 additions and 9 deletions
|
@ -50,7 +50,7 @@ from typing import (
|
|||
from urllib.error import HTTPError
|
||||
from urllib.request import urlopen
|
||||
|
||||
__version__ = "23.5a5-25-g6239661-dev"
|
||||
__version__ = "23.5a5-26-g79ae1da-dev"
|
||||
|
||||
|
||||
class Spinner:
|
||||
|
@ -786,6 +786,12 @@ class ViVenv:
|
|||
def touch(self) -> None:
|
||||
self.meta.accessed = str(datetime.today())
|
||||
|
||||
def activate(self) -> None:
|
||||
# also add sys.path here so that it comes first
|
||||
path_to_add = str(*(self.path / "lib").glob("python*/site-packages"))
|
||||
sys.path = [p for p in (path_to_add, *sys.path) if p != site.USER_SITE]
|
||||
site.addsitedir(path_to_add)
|
||||
|
||||
def show(self) -> None:
|
||||
_id = (
|
||||
self.meta.id[:8]
|
||||
|
@ -853,17 +859,11 @@ def use(*packages: str, track_exe: bool = False, name: str = "") -> Path:
|
|||
vivenv.meta.addfile(get_caller_path())
|
||||
vivenv.meta.write()
|
||||
|
||||
modify_sys_path(vivenv.path)
|
||||
vivenv.activate()
|
||||
|
||||
return vivenv.path
|
||||
|
||||
|
||||
def modify_sys_path(new_path: Path) -> None:
|
||||
# also add sys.path here so that it comes first
|
||||
path_to_add = str(*(new_path / "lib").glob("python*/site-packages"))
|
||||
sys.path = [p for p in (path_to_add, *sys.path) if p != site.USER_SITE]
|
||||
site.addsitedir(path_to_add)
|
||||
|
||||
|
||||
def get_venvs() -> Dict[str, ViVenv]:
|
||||
vivenvs = {}
|
||||
for p in Cache().venv.iterdir():
|
||||
|
|
Loading…
Reference in a new issue