mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-12-22 02:30:44 -06:00
refactor: more consolidation
This commit is contained in:
parent
78e533b0a2
commit
0136568137
1 changed files with 13 additions and 10 deletions
|
@ -52,7 +52,7 @@ from typing import (
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
__version__ = "23.8b2-11-gf522352-dev"
|
__version__ = "23.8b2-13-g1f0eed9-dev"
|
||||||
|
|
||||||
|
|
||||||
class Spinner:
|
class Spinner:
|
||||||
|
@ -1006,7 +1006,7 @@ class ViVenv:
|
||||||
)
|
)
|
||||||
|
|
||||||
def ensure(self) -> None:
|
def ensure(self) -> None:
|
||||||
self.existse()
|
self.exists()
|
||||||
if not self.loaded or Env().viv_force:
|
if not self.loaded or Env().viv_force:
|
||||||
self.create()
|
self.create()
|
||||||
self.install_pkgs()
|
self.install_pkgs()
|
||||||
|
@ -1029,7 +1029,7 @@ class ViVenv:
|
||||||
*(
|
*(
|
||||||
p
|
p
|
||||||
for p in sys.path
|
for p in sys.path
|
||||||
if not any(map(p.endswith, ("dist-packages", "site-packages")))
|
if not p.endswith(("dist-packages", "site-packages"))
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
site.addsitedir(path_to_add)
|
site.addsitedir(path_to_add)
|
||||||
|
@ -1048,21 +1048,24 @@ class ViVenv:
|
||||||
|
|
||||||
self.size = f"{size:.1f}{unit}B"
|
self.size = f"{size:.1f}{unit}B"
|
||||||
|
|
||||||
|
# TODO: reconsider this function which is starting to do heavy lifting
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def use(self, keep: bool = True) -> Generator[None, None, None]:
|
def use(self, keep: bool = True) -> Generator[None, None, None]:
|
||||||
run_mode = Env().viv_run_mode
|
run_mode = Env().viv_run_mode
|
||||||
_path = self.path
|
_path = self.path
|
||||||
|
|
||||||
|
def common():
|
||||||
|
self.ensure()
|
||||||
|
self.touch()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.loaded:
|
if self.loaded or keep or run_mode == "persist":
|
||||||
self.ensure()
|
common()
|
||||||
yield
|
|
||||||
elif keep or run_mode == "persist":
|
|
||||||
self.ensure()
|
|
||||||
yield
|
yield
|
||||||
elif run_mode == "ephemeral":
|
elif run_mode == "ephemeral":
|
||||||
with tempfile.TemporaryDirectory(prefix="viv-") as tmpdir:
|
with tempfile.TemporaryDirectory(prefix="viv-") as tmpdir:
|
||||||
self.set_path(Path(tmpdir))
|
self.set_path(Path(tmpdir))
|
||||||
self.ensure()
|
common()
|
||||||
yield
|
yield
|
||||||
elif run_mode == "semi-ephemeral":
|
elif run_mode == "semi-ephemeral":
|
||||||
ephemeral_cache = _path_ok(
|
ephemeral_cache = _path_ok(
|
||||||
|
@ -1070,7 +1073,7 @@ class ViVenv:
|
||||||
)
|
)
|
||||||
os.environ.update(dict(VIV_CACHE=str(ephemeral_cache)))
|
os.environ.update(dict(VIV_CACHE=str(ephemeral_cache)))
|
||||||
self.set_path(ephemeral_cache / "venvs" / self.name)
|
self.set_path(ephemeral_cache / "venvs" / self.name)
|
||||||
self.ensure()
|
common()
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
self.set_path(_path)
|
self.set_path(_path)
|
||||||
|
|
Loading…
Reference in a new issue