Make install + start scripts do proper configuration automatically

This commit is contained in:
Ashwin Bharambe 2024-08-06 21:34:09 -07:00
parent 9e1ca4eeb1
commit e1a7aa4773
5 changed files with 84 additions and 39 deletions

View file

@ -6,7 +6,6 @@
import argparse
import os
import textwrap
import pkg_resources
import yaml
@ -78,32 +77,35 @@ class DistributionInstall(Subcommand):
print(f"Using {args.name} as the Conda environment for this distribution")
conda_env = args.conda_env or args.name
return_code = run_with_pty([script, conda_env, " ".join(deps)])
config_file = distrib_dir / "config.yaml"
if config_file.exists():
c = DistributionConfig(**yaml.safe_load(config_file.read_text()))
if c.spec != dist.spec_id:
self.parser.error(
f"already installed distribution with `spec={c.spec}` does not match provided spec `{args.spec}`"
)
return
if c.conda_env != conda_env:
self.parser.error(
f"already installed distribution has `conda_env={c.conda_env}` different from provided conda env `{conda_env}`"
)
return
else:
with open(config_file, "w") as f:
c = DistributionConfig(
spec=dist.spec_id,
name=args.name,
conda_env=conda_env,
)
f.write(yaml.dump(c.dict(), sort_keys=False))
return_code = run_with_pty([script, conda_env, args.name, " ".join(deps)])
assert return_code == 0, cprint(
f"Failed to install distribution {dist.spec_id}", color="red"
)
config_file = distrib_dir / "config.yaml"
with open(config_file, "w") as f:
c = DistributionConfig(
spec=dist.spec_id,
name=args.name,
conda_env=conda_env,
)
f.write(yaml.dump(c.dict(), sort_keys=False))
cprint(
f"Distribution `{args.name}` (with spec {dist.spec_id}) has been installed successfully!",
color="green",
)
print(
textwrap.dedent(
f"""
Update your conda environment and configure this distribution by running:
conda deactivate && conda activate {conda_env}
llama distribution configure --name {args.name}
"""
)
)