mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-14 04:57:53 -06:00
fix: handle viv_run_modes appropriately with script mode
This commit is contained in:
parent
c7bcdfefee
commit
f88a7bd15f
1 changed files with 31 additions and 21 deletions
|
@ -52,7 +52,7 @@ from typing import (
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
__version__ = "23.8b1-7-g3031e5f-dev"
|
__version__ = "23.8b1-8-gc7bcdfe-dev"
|
||||||
|
|
||||||
|
|
||||||
class Spinner:
|
class Spinner:
|
||||||
|
@ -1002,11 +1002,9 @@ class ViVenv:
|
||||||
self.set_path(Path(tmpdir))
|
self.set_path(Path(tmpdir))
|
||||||
yield
|
yield
|
||||||
elif run_mode == "semi-ephemeral":
|
elif run_mode == "semi-ephemeral":
|
||||||
(
|
ephemeral_cache = _path_ok(
|
||||||
ephemeral_cache := (
|
|
||||||
Path(tempfile.gettempdir()) / "viv-ephemeral-cache" / "venvs"
|
Path(tempfile.gettempdir()) / "viv-ephemeral-cache" / "venvs"
|
||||||
)
|
)
|
||||||
).mkdir(exist_ok=True, parents=True)
|
|
||||||
self.set_path(ephemeral_cache / self.name)
|
self.set_path(ephemeral_cache / self.name)
|
||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
|
@ -1678,6 +1676,20 @@ class Viv:
|
||||||
|
|
||||||
make_executable(output)
|
make_executable(output)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _update_cache(env: Dict[str, str], keep: bool, tmpdir: str):
|
||||||
|
run_mode = Env().viv_run_mode
|
||||||
|
if not keep:
|
||||||
|
if run_mode == "ephemeral":
|
||||||
|
new_cache = tmpdir
|
||||||
|
elif run_mode == "semi-ephemeral":
|
||||||
|
new_cache = str(
|
||||||
|
Path(tempfile.gettempdir()) / "viv-ephemeral-cache" / "venvs"
|
||||||
|
)
|
||||||
|
|
||||||
|
env.update({"VIV_CACHE": new_cache})
|
||||||
|
os.environ["VIV_CACHE"] = new_cache
|
||||||
|
|
||||||
def _run_script(
|
def _run_script(
|
||||||
self, spec: List[str], script: str, keep: bool, rest: List[str]
|
self, spec: List[str], script: str, keep: bool, rest: List[str]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -1711,10 +1723,7 @@ class Viv:
|
||||||
)
|
)
|
||||||
|
|
||||||
scriptpath.write_text(script_text)
|
scriptpath.write_text(script_text)
|
||||||
|
self._update_cache(env, keep, tmpdir)
|
||||||
if not keep:
|
|
||||||
env.update({"VIV_CACHE": tmpdir})
|
|
||||||
os.environ["VIV_CACHE"] = tmpdir
|
|
||||||
|
|
||||||
if viv_used:
|
if viv_used:
|
||||||
log.debug(f"script invokes viv.use passing along spec: \n '{spec}'")
|
log.debug(f"script invokes viv.use passing along spec: \n '{spec}'")
|
||||||
|
@ -1727,6 +1736,7 @@ class Viv:
|
||||||
subprocess_run_quit([sys.executable, "-S", scriptpath, *rest])
|
subprocess_run_quit([sys.executable, "-S", scriptpath, *rest])
|
||||||
else:
|
else:
|
||||||
vivenv = ViVenv(spec + deps)
|
vivenv = ViVenv(spec + deps)
|
||||||
|
with vivenv.use(keep=keep):
|
||||||
vivenv.ensure()
|
vivenv.ensure()
|
||||||
vivenv.touch()
|
vivenv.touch()
|
||||||
vivenv.meta.write()
|
vivenv.meta.write()
|
||||||
|
|
Loading…
Reference in a new issue