mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-13 20:47: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,
|
||||
)
|
||||
|
||||
__version__ = "23.8b1-7-g3031e5f-dev"
|
||||
__version__ = "23.8b1-8-gc7bcdfe-dev"
|
||||
|
||||
|
||||
class Spinner:
|
||||
|
@ -1002,11 +1002,9 @@ class ViVenv:
|
|||
self.set_path(Path(tmpdir))
|
||||
yield
|
||||
elif run_mode == "semi-ephemeral":
|
||||
(
|
||||
ephemeral_cache := (
|
||||
ephemeral_cache = _path_ok(
|
||||
Path(tempfile.gettempdir()) / "viv-ephemeral-cache" / "venvs"
|
||||
)
|
||||
).mkdir(exist_ok=True, parents=True)
|
||||
self.set_path(ephemeral_cache / self.name)
|
||||
yield
|
||||
finally:
|
||||
|
@ -1678,6 +1676,20 @@ class Viv:
|
|||
|
||||
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(
|
||||
self, spec: List[str], script: str, keep: bool, rest: List[str]
|
||||
) -> None:
|
||||
|
@ -1711,10 +1723,7 @@ class Viv:
|
|||
)
|
||||
|
||||
scriptpath.write_text(script_text)
|
||||
|
||||
if not keep:
|
||||
env.update({"VIV_CACHE": tmpdir})
|
||||
os.environ["VIV_CACHE"] = tmpdir
|
||||
self._update_cache(env, keep, tmpdir)
|
||||
|
||||
if viv_used:
|
||||
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])
|
||||
else:
|
||||
vivenv = ViVenv(spec + deps)
|
||||
with vivenv.use(keep=keep):
|
||||
vivenv.ensure()
|
||||
vivenv.touch()
|
||||
vivenv.meta.write()
|
||||
|
|
Loading…
Reference in a new issue