refactor: use method instead of standalone function

This commit is contained in:
Daylin Morgan 2023-06-12 08:55:24 -05:00
parent 79ae1da47b
commit e697488dda
Signed by: daylin
GPG key ID: C1E52E7DD81DF79F

View file

@ -50,7 +50,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.5a5-25-g6239661-dev" __version__ = "23.5a5-26-g79ae1da-dev"
class Spinner: class Spinner:
@ -786,6 +786,12 @@ class ViVenv:
def touch(self) -> None: def touch(self) -> None:
self.meta.accessed = str(datetime.today()) 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: def show(self) -> None:
_id = ( _id = (
self.meta.id[:8] 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.addfile(get_caller_path())
vivenv.meta.write() vivenv.meta.write()
modify_sys_path(vivenv.path) vivenv.activate()
return vivenv.path 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]: def get_venvs() -> Dict[str, ViVenv]:
vivenvs = {} vivenvs = {}
for p in Cache().venv.iterdir(): for p in Cache().venv.iterdir():