From e697488dda0876157b289c6b622eafc68d45c293 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 12 Jun 2023 08:55:24 -0500 Subject: [PATCH] refactor: use method instead of standalone function --- src/viv/viv.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/viv/viv.py b/src/viv/viv.py index dd18dd7..1e63835 100755 --- a/src/viv/viv.py +++ b/src/viv/viv.py @@ -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():