mirror of
https://github.com/daylinmorgan/viv.git
synced 2024-11-09 19:13:14 -06:00
fix(#1): get the spec then re-make only when necessary
This commit is contained in:
parent
e8a77fe77c
commit
ddb03df8a2
1 changed files with 14 additions and 21 deletions
|
@ -49,7 +49,7 @@ from typing import (
|
||||||
Generator,
|
Generator,
|
||||||
)
|
)
|
||||||
|
|
||||||
__version__ = "22.12a3-39-gee7fe64-dev"
|
__version__ = "22.12a3-41-g5c40210-dev"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -578,36 +578,29 @@ def generate_import(
|
||||||
keep: bool,
|
keep: bool,
|
||||||
standalone: bool,
|
standalone: bool,
|
||||||
) -> None:
|
) -> None:
|
||||||
# TODO: make compatible with Venv class for now just use the name /tmp/
|
|
||||||
reqs_from_file = []
|
reqs_from_file = []
|
||||||
|
|
||||||
if requirements:
|
if requirements:
|
||||||
with requirements.open("r") as f:
|
with requirements.open("r") as f:
|
||||||
reqs_from_file = f.readlines()
|
reqs_from_file = f.readlines()
|
||||||
|
|
||||||
# refactor to make the below steps context dependent with tmpdir path
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
|
echo("generating frozen spec")
|
||||||
|
vivenv, resolved_spec = freeze_venv(reqs + reqs_from_file, path=Path(tmpdir))
|
||||||
|
|
||||||
if keep:
|
if keep:
|
||||||
# TODO: remove directory if any errors occur?
|
# create env again since path's are hard-coded
|
||||||
echo("generating new vivenv")
|
vivenv = ViVenv(resolved_spec.splitlines())
|
||||||
vivenv, resolved_spec = freeze_venv(reqs + reqs_from_file)
|
|
||||||
|
|
||||||
# update id and move vivenv
|
if vivenv.name not in [d.name for d in c.venvcache.iterdir()] or os.getenv(
|
||||||
vivenv.spec = resolved_spec.splitlines()
|
"VIV_FORCE"
|
||||||
vivenv.id = get_hash(resolved_spec.splitlines())
|
):
|
||||||
echo(f"updated hash -> {vivenv.id}")
|
vivenv.create()
|
||||||
|
vivenv.install_pkgs()
|
||||||
if not (c.venvcache / vivenv.id).exists():
|
|
||||||
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("re-using existing vivenv")
|
||||||
shutil.rmtree(vivenv.path)
|
|
||||||
else:
|
|
||||||
with tempfile.TemporaryDirectory() as tmpdir: #
|
|
||||||
echo("generating temporary vivenv ")
|
|
||||||
vivenv, resolved_spec = freeze_venv(
|
|
||||||
reqs + reqs_from_file, path=Path(tmpdir)
|
|
||||||
)
|
|
||||||
|
|
||||||
echo("see below for import statements\n")
|
echo("see below for import statements\n")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue