-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__main__.py
More file actions
127 lines (101 loc) · 3.05 KB
/
__main__.py
File metadata and controls
127 lines (101 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from __future__ import annotations
import os
import sys
import click
from pathlib import Path
from dataclasses import dataclass
from deploy.build import Build
from deploy.config import load_config
from deploy.check import do_check
from deploy.package_list import PackageList
from deploy.sync import do_sync
@dataclass
class _Args:
config_dir: Path = Path()
prefix: Path = Path()
Args = _Args()
@click.group()
@click.option(
"--config-dir",
"-C",
help="Directory of config.yaml [default=.]",
default=".",
)
@click.option(
"--prefix",
"-p",
help="Installation location",
default="./output/prefix",
)
def cli(config_dir: str, prefix: str) -> None:
Args.config_dir = Path(config_dir).expanduser().resolve()
Args.prefix = Path(prefix).expanduser().resolve()
@cli.command(help="Check locations")
def check() -> None:
config = load_config(Path(Args.config_dir))
do_check(config, prefix=Args.prefix)
@cli.command(help="Synchronise all locations")
@click.option(
"--no-async",
help="Don't deploy asynchronously",
is_flag=True,
default=False,
)
@click.option(
"--dry-run",
is_flag=True,
default=False,
)
def sync(no_async: bool, dry_run: bool) -> None:
config = load_config(Args.config_dir)
do_sync(
Args.config_dir,
config,
prefix=Args.prefix,
no_async=no_async,
dry_run=dry_run,
)
@cli.command(help="Build Cirrus and dependencies")
@click.option(
"--force",
"-f",
is_flag=True,
default=False,
help="Force adding a new environment even if one already exists (rollback)",
)
def build(force: bool) -> None:
tmp_path = Path("./output/tmp").resolve()
tmp_path.mkdir(parents=True, exist_ok=True)
config = load_config(Args.config_dir)
builder = Build(
Args.config_dir,
config,
force=force,
prefix=Args.prefix,
)
builder.build()
@cli.command(help="Run tests in ./deploy_tests using pytest")
@click.argument("args", nargs=-1)
def test(args: tuple[str, ...]) -> None:
import pytest
config = load_config(Args.config_dir)
plist = PackageList(Args.config_dir, config, prefix=Args.prefix)
testpath = Args.config_dir / "deploy_tests"
if not testpath.is_dir():
sys.exit(f"Test directory '{testpath}' doesn't exist or is not a directory")
newpath = ":".join(str(p.out / "bin") for p in plist.packages.values())
os.environ["PATH"] = f"{newpath}:{os.environ['PATH']}"
for pkg in plist.packages.values():
os.environ[f"{pkg.config.name}_version"] = pkg.config.version
for name, dest, _ in plist.envs:
os.environ[f"{name}_env"] = f"{Args.prefix / dest}"
for name, dest, _ in plist.envs:
pkg = plist.packages[name]
for path in (plist.prefix / dest).glob("*/manifest"):
if path.read_text() == pkg.manifest:
os.environ[f"{name}_env_version"] = path.parent.name
break
print(f"{os.environ['PATH']=}")
sys.exit(pytest.main([str(testpath), *args]))
if __name__ == "__main__":
cli()