mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-12-22 02:30:44 -06:00
refactor: move validate spec into ViVenv
This commit is contained in:
parent
0ec266775c
commit
9a33a99480
1 changed files with 14 additions and 15 deletions
|
@ -52,7 +52,7 @@ from typing import (
|
|||
from urllib.error import HTTPError
|
||||
from urllib.request import urlopen
|
||||
|
||||
__version__ = "23.5a3"
|
||||
__version__ = "23.5a2-2-gebb657c-dev"
|
||||
|
||||
|
||||
class Config:
|
||||
|
@ -559,7 +559,7 @@ class ViVenv:
|
|||
name: str = "",
|
||||
path: Path | None = None,
|
||||
) -> None:
|
||||
self.spec = spec
|
||||
self.spec = self._validate_spec(spec)
|
||||
self.exe = str(Path(sys.executable).resolve()) if track_exe else "N/A"
|
||||
self.id = id if id else get_hash(spec, track_exe)
|
||||
self.name = name if name else self.id
|
||||
|
@ -583,6 +583,18 @@ class ViVenv:
|
|||
|
||||
return vivenv
|
||||
|
||||
def _validate_spec(self, spec: Tuple[str, ...]) -> List[str]:
|
||||
"""ensure spec is at least of sequence of strings
|
||||
|
||||
Args:
|
||||
spec: sequence of package specifications
|
||||
"""
|
||||
if not set(map(type, spec)) == {str}:
|
||||
error("unexepected input in package spec")
|
||||
error(f"check your packages definitions: {spec}", code=1)
|
||||
else:
|
||||
return sorted(spec)
|
||||
|
||||
def create(self, quiet: bool = False) -> None:
|
||||
if not quiet:
|
||||
echo(f"new unique vivenv -> {self.name}")
|
||||
|
@ -636,7 +648,6 @@ def use(*packages: str, track_exe: bool = False, name: str = "") -> Path:
|
|||
track_exe: if true make env python exe specific
|
||||
name: use as vivenv name, if not provided id is used
|
||||
"""
|
||||
validate_spec(packages)
|
||||
vivenv = ViVenv(list(packages), track_exe=track_exe, name=name)
|
||||
|
||||
if vivenv.name not in [d.name for d in c.venvcache.iterdir()] or os.getenv(
|
||||
|
@ -650,18 +661,6 @@ def use(*packages: str, track_exe: bool = False, name: str = "") -> Path:
|
|||
return vivenv.path
|
||||
|
||||
|
||||
def validate_spec(spec: Tuple[str, ...]) -> None:
|
||||
"""ensure spec is at least of sequence of strings
|
||||
|
||||
Args:
|
||||
spec: sequence of package specifications
|
||||
"""
|
||||
# ? make this a part of ViVenv?
|
||||
if not set(map(type, spec)) == {str}:
|
||||
error("unexepected input in package spec")
|
||||
error(f"check your packages definitions: {spec}", code=1)
|
||||
|
||||
|
||||
def modify_sys_path(new_path: Path) -> None:
|
||||
# remove user-site
|
||||
for i, path in enumerate(sys.path):
|
||||
|
|
Loading…
Reference in a new issue