mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-09 19:13:14 -06:00
refactor: use id
instead of build_id
This commit is contained in:
parent
0d583584dc
commit
10599dcd01
1 changed files with 12 additions and 14 deletions
|
@ -348,14 +348,14 @@ class ViVenv:
|
||||||
self,
|
self,
|
||||||
spec: List[str],
|
spec: List[str],
|
||||||
track_exe: bool = False,
|
track_exe: bool = False,
|
||||||
build_id: str | None = None,
|
id: str | None = None,
|
||||||
name: str = "",
|
name: str = "",
|
||||||
path: Path | None = None,
|
path: Path | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.spec = spec
|
self.spec = spec
|
||||||
self.exe = str(Path(sys.executable).resolve()) if track_exe else "N/A"
|
self.exe = str(Path(sys.executable).resolve()) if track_exe else "N/A"
|
||||||
self.build_id = build_id if build_id else get_hash(spec, track_exe)
|
self.id = id if id else get_hash(spec, track_exe)
|
||||||
self.name = name if name else self.build_id
|
self.name = name if name else self.id
|
||||||
self.path = path if path else c.venvcache / self.name
|
self.path = path if path else c.venvcache / self.name
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
@ -371,9 +371,7 @@ class ViVenv:
|
||||||
with (c.venvcache / name / "viv-info.json").open("r") as f:
|
with (c.venvcache / name / "viv-info.json").open("r") as f:
|
||||||
venvconfig = json.load(f)
|
venvconfig = json.load(f)
|
||||||
|
|
||||||
vivenv = cls(
|
vivenv = cls(name=name, spec=venvconfig["spec"], id=venvconfig["id"])
|
||||||
name=name, spec=venvconfig["spec"], build_id=venvconfig["build_id"]
|
|
||||||
)
|
|
||||||
vivenv.exe = venvconfig["exe"]
|
vivenv.exe = venvconfig["exe"]
|
||||||
|
|
||||||
return vivenv
|
return vivenv
|
||||||
|
@ -407,7 +405,7 @@ class ViVenv:
|
||||||
# means it needs to be loaded first
|
# means it needs to be loaded first
|
||||||
info = {
|
info = {
|
||||||
"created": str(datetime.today()),
|
"created": str(datetime.today()),
|
||||||
"build_id": self.build_id,
|
"id": self.id,
|
||||||
"spec": self.spec,
|
"spec": self.spec,
|
||||||
"exe": self.exe,
|
"exe": self.exe,
|
||||||
}
|
}
|
||||||
|
@ -426,7 +424,7 @@ def activate(*packages: str, track_exe: bool = False, name: str = "") -> None:
|
||||||
Args:
|
Args:
|
||||||
packages: package specifications with optional version specifiers
|
packages: package specifications with optional version specifiers
|
||||||
track_exe: if true make env python exe specific
|
track_exe: if true make env python exe specific
|
||||||
name: use as vivenv name, if not provided build_id is used
|
name: use as vivenv name, if not provided id is used
|
||||||
"""
|
"""
|
||||||
validate_spec(packages)
|
validate_spec(packages)
|
||||||
vivenv = ViVenv(list(packages), track_exe=track_exe, name=name)
|
vivenv = ViVenv(list(packages), track_exe=track_exe, name=name)
|
||||||
|
@ -518,13 +516,13 @@ def generate_import(
|
||||||
echo("generating new vivenv")
|
echo("generating new vivenv")
|
||||||
vivenv, resolved_spec = freeze_venv(reqs + reqs_from_file)
|
vivenv, resolved_spec = freeze_venv(reqs + reqs_from_file)
|
||||||
|
|
||||||
# update build_id and move vivenv
|
# update id and move vivenv
|
||||||
vivenv.spec = resolved_spec.splitlines()
|
vivenv.spec = resolved_spec.splitlines()
|
||||||
vivenv.build_id = get_hash(resolved_spec.splitlines())
|
vivenv.id = get_hash(resolved_spec.splitlines())
|
||||||
echo(f"updated hash -> {vivenv.build_id}")
|
echo(f"updated hash -> {vivenv.id}")
|
||||||
|
|
||||||
if not (c.venvcache / vivenv.build_id).exists():
|
if not (c.venvcache / vivenv.id).exists():
|
||||||
vivenv.path = vivenv.path.rename(c.venvcache / vivenv.build_id)
|
vivenv.path = vivenv.path.rename(c.venvcache / vivenv.id)
|
||||||
vivenv.dump_info(write=True)
|
vivenv.dump_info(write=True)
|
||||||
else:
|
else:
|
||||||
echo("this vivenv already exists cleaning up temporary vivenv")
|
echo("this vivenv already exists cleaning up temporary vivenv")
|
||||||
|
@ -713,7 +711,7 @@ class Viv:
|
||||||
for k, v in self.vivenvs.items():
|
for k, v in self.vivenvs.items():
|
||||||
if name_id == k or v.name == name_id:
|
if name_id == k or v.name == name_id:
|
||||||
matches.append(v)
|
matches.append(v)
|
||||||
elif k.startswith(name_id) or v.build_id.startswith(name_id):
|
elif k.startswith(name_id) or v.id.startswith(name_id):
|
||||||
matches.append(v)
|
matches.append(v)
|
||||||
elif v.name.startswith(name_id):
|
elif v.name.startswith(name_id):
|
||||||
matches.append(v)
|
matches.append(v)
|
||||||
|
|
Loading…
Reference in a new issue