scriptvault 0.1.0__tar.gz → 0.1.6b0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scriptvault-0.1.0/src/scriptvault.egg-info → scriptvault-0.1.6b0}/PKG-INFO +1 -1
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/pyproject.toml +4 -1
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/__init__.py +2 -2
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/cli.py +13 -5
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/vault.py +24 -8
- {scriptvault-0.1.0 → scriptvault-0.1.6b0/src/scriptvault.egg-info}/PKG-INFO +1 -1
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/tests/test_add.py +3 -1
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/tests/test_completion.py +7 -0
- scriptvault-0.1.6b0/tests/test_list.py +95 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/tests/test_real.py +9 -1
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/tests/test_run.py +7 -1
- scriptvault-0.1.0/tests/test_list.py +0 -154
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/LICENSE +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/README.md +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/setup.cfg +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/__main__.py +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/envfile.py +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/run.py +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/templates.py +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault/term.py +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault.egg-info/SOURCES.txt +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault.egg-info/dependency_links.txt +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault.egg-info/entry_points.txt +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault.egg-info/requires.txt +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/src/scriptvault.egg-info/top_level.txt +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/tests/test_edit.py +0 -0
- {scriptvault-0.1.0 → scriptvault-0.1.6b0}/tests/test_init.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scriptvault"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.6-beta"
|
|
8
8
|
description = "Store and run project commands in a hidden vault directory"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -26,6 +26,9 @@ sv = "scriptvault.cli:main"
|
|
|
26
26
|
[project.optional-dependencies]
|
|
27
27
|
dev = ["pytest>=8"]
|
|
28
28
|
|
|
29
|
+
[dependency-groups]
|
|
30
|
+
dev = ["pytest>=8"]
|
|
31
|
+
|
|
29
32
|
[tool.setuptools.packages.find]
|
|
30
33
|
where = ["src"]
|
|
31
34
|
|
|
@@ -205,8 +205,14 @@ def cmd_run(args: argparse.Namespace) -> int:
|
|
|
205
205
|
f"unknown target {name!r} (available: {available})", 127
|
|
206
206
|
)
|
|
207
207
|
|
|
208
|
-
# Parse global flags
|
|
209
|
-
|
|
208
|
+
# Parse global flags (only if there's a -- separator)
|
|
209
|
+
if "--" in run_args:
|
|
210
|
+
separator_idx = run_args.index("--")
|
|
211
|
+
script_args = run_args[separator_idx + 1:]
|
|
212
|
+
global_flags = run_args[:separator_idx]
|
|
213
|
+
else:
|
|
214
|
+
script_args = run_args
|
|
215
|
+
global_flags = []
|
|
210
216
|
try:
|
|
211
217
|
return run_target(vault, name, script_args, global_flags=global_flags)
|
|
212
218
|
except OSError as exc:
|
|
@@ -401,7 +407,7 @@ def cmd_completion(args: argparse.Namespace) -> int:
|
|
|
401
407
|
|
|
402
408
|
if not shell_name or shell_name not in _COMPLETIONS:
|
|
403
409
|
print(f"Error: Shell '{shell_name}' not supported", file=sys.stderr)
|
|
404
|
-
|
|
410
|
+
sys.exit(2)
|
|
405
411
|
|
|
406
412
|
print(_COMPLETIONS[shell_name], end="")
|
|
407
413
|
return 0
|
|
@@ -496,6 +502,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
496
502
|
"--path",
|
|
497
503
|
metavar="PATH",
|
|
498
504
|
default=None,
|
|
505
|
+
nargs="?",
|
|
506
|
+
const=".",
|
|
499
507
|
help="path to .sv directory (default: auto-detect root .sv in current or parent directories)",
|
|
500
508
|
)
|
|
501
509
|
lst.add_argument(
|
|
@@ -655,8 +663,8 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
655
663
|
# Check if this is a fresh installation (scriptvault not in pip list)
|
|
656
664
|
try:
|
|
657
665
|
import importlib.metadata as metadata
|
|
658
|
-
if "scriptvault" not in metadata.distributions():
|
|
659
|
-
print("Run 'sv completion bash | source' or 'sv completion zsh | source' or 'sv completion fish | source' to enable tab completion.")
|
|
666
|
+
if "scriptvault" not in metadata.distributions() and sys.stdout.isatty():
|
|
667
|
+
print("Run 'sv completion bash | source' or 'sv completion zsh | source' or 'sv completion fish | source' to enable tab completion.", file=sys.stderr)
|
|
660
668
|
except Exception:
|
|
661
669
|
pass
|
|
662
670
|
return result
|
|
@@ -8,7 +8,7 @@ from pathlib import Path
|
|
|
8
8
|
|
|
9
9
|
from .envfile import parse_env_file
|
|
10
10
|
|
|
11
|
-
NAME_RE = re.compile(r"^[a-z0-9][a-z0-9_
|
|
11
|
+
NAME_RE = re.compile(r"^[a-z0-9][a-z0-9_.-]*$")
|
|
12
12
|
|
|
13
13
|
DEFAULT_HIDDEN_DIR = ".sv"
|
|
14
14
|
ENV_HIDDEN_DIR_VAR = "SV_HIDDEN_DIR"
|
|
@@ -90,18 +90,23 @@ def find_root(start: Path | None = None) -> Path:
|
|
|
90
90
|
)
|
|
91
91
|
|
|
92
92
|
# Check if we're inside a nested .sv directory
|
|
93
|
-
#
|
|
94
|
-
|
|
93
|
+
# We're nested if our .sv directory is inside another .sv directory
|
|
94
|
+
current_sv = (current or Path.cwd()) / hidden
|
|
95
|
+
is_nested = any(
|
|
96
|
+
current_sv.is_relative_to(sv_dir)
|
|
97
|
+
for sv_dir in [(p / hidden) for p in all_sv_parents]
|
|
98
|
+
if sv_dir != current_sv
|
|
99
|
+
)
|
|
95
100
|
|
|
96
|
-
if
|
|
97
|
-
#
|
|
101
|
+
if is_nested:
|
|
102
|
+
# We're inside a nested vault, find the root
|
|
98
103
|
# Iterate in reverse order to get the root
|
|
99
104
|
for parent in reversed(all_sv_parents):
|
|
100
105
|
if current.is_relative_to(parent):
|
|
101
106
|
return parent
|
|
102
107
|
|
|
103
|
-
# Not inside a nested .sv, use the nearest one
|
|
104
|
-
return all_sv_parents[
|
|
108
|
+
# Not inside a nested .sv (or we're in our own project), use the nearest one
|
|
109
|
+
return all_sv_parents[0]
|
|
105
110
|
|
|
106
111
|
# Not inside a nested .sv, use the nearest one
|
|
107
112
|
if all_sv_dirs:
|
|
@@ -425,12 +430,23 @@ def load_vault(root: Path) -> Vault:
|
|
|
425
430
|
# File scripts override same-name inline scripts.
|
|
426
431
|
vault.scripts = dict(inline)
|
|
427
432
|
if vault.scripts_dir.is_dir():
|
|
428
|
-
for path in sorted(vault.scripts_dir.glob("
|
|
433
|
+
for path in sorted(vault.scripts_dir.glob("*")):
|
|
429
434
|
if path.name.startswith("."):
|
|
430
435
|
continue
|
|
431
436
|
name = path.stem
|
|
432
437
|
if not NAME_RE.match(name):
|
|
433
438
|
continue
|
|
439
|
+
# Skip non-files
|
|
440
|
+
if not path.is_file():
|
|
441
|
+
continue
|
|
442
|
+
# Skip files without shebang
|
|
443
|
+
try:
|
|
444
|
+
content = path.read_bytes()
|
|
445
|
+
if len(content) >= 2:
|
|
446
|
+
if content[:2] != b"#!":
|
|
447
|
+
continue # No shebang
|
|
448
|
+
except Exception:
|
|
449
|
+
continue
|
|
434
450
|
description = ""
|
|
435
451
|
if name in inline:
|
|
436
452
|
description = inline[name].description
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Tests for the `sv add` command."""
|
|
2
2
|
|
|
3
|
+
import os
|
|
3
4
|
import io
|
|
4
5
|
import subprocess
|
|
5
6
|
import sys
|
|
@@ -39,6 +40,7 @@ def test_add_script_is_listed_and_runnable(project, capsys, monkeypatch):
|
|
|
39
40
|
cwd=str(project),
|
|
40
41
|
capture_output=True,
|
|
41
42
|
text=True,
|
|
43
|
+
env={**os.environ, "PYTHONPATH": "/home/t3/ScriptVault/src"},
|
|
42
44
|
)
|
|
43
45
|
assert result.returncode == 0
|
|
44
46
|
assert result.stdout == 'Hello from hello\n'
|
|
@@ -91,7 +93,7 @@ def test_add_rejects_orchestration_name(project, capsys, monkeypatch):
|
|
|
91
93
|
assert "already exists" in capsys.readouterr().err
|
|
92
94
|
|
|
93
95
|
|
|
94
|
-
@pytest.mark.parametrize("name", ["Hello", "
|
|
96
|
+
@pytest.mark.parametrize("name", ["Hello", "sp ace", ""])
|
|
95
97
|
def test_add_invalid_name(project, capsys, monkeypatch, name):
|
|
96
98
|
init(project, monkeypatch)
|
|
97
99
|
capsys.readouterr()
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Tests for `sv completion` and the hidden `sv __names` helper."""
|
|
2
2
|
|
|
3
3
|
import shutil
|
|
4
|
+
import os
|
|
4
5
|
import subprocess
|
|
5
6
|
import sys
|
|
6
7
|
|
|
@@ -23,11 +24,14 @@ def make_vault(project):
|
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
def sv(*argv, cwd):
|
|
27
|
+
env = os.environ.copy()
|
|
28
|
+
env["PYTHONPATH"] = "/home/t3/ScriptVault/src"
|
|
26
29
|
return subprocess.run(
|
|
27
30
|
[sys.executable, "-m", "scriptvault", *map(str, argv)],
|
|
28
31
|
cwd=str(cwd),
|
|
29
32
|
capture_output=True,
|
|
30
33
|
text=True,
|
|
34
|
+
env=env,
|
|
31
35
|
)
|
|
32
36
|
|
|
33
37
|
|
|
@@ -66,6 +70,7 @@ def test_completion_bash_syntax_and_targets(project):
|
|
|
66
70
|
cwd=str(project),
|
|
67
71
|
capture_output=True,
|
|
68
72
|
text=True,
|
|
73
|
+
env={**os.environ, "PYTHONPATH": "/home/t3/ScriptVault/src"},
|
|
69
74
|
)
|
|
70
75
|
assert run.returncode == 0, run.stderr
|
|
71
76
|
assert "hello" in run.stdout.split()
|
|
@@ -86,6 +91,7 @@ def test_completion_bash_completes_commands(project):
|
|
|
86
91
|
cwd=str(project),
|
|
87
92
|
capture_output=True,
|
|
88
93
|
text=True,
|
|
94
|
+
env={**os.environ, "PYTHONPATH": "/home/t3/ScriptVault/src"},
|
|
89
95
|
)
|
|
90
96
|
assert run.returncode == 0, run.stderr
|
|
91
97
|
assert "run" in run.stdout.split()
|
|
@@ -144,6 +150,7 @@ def test_completion_bash_edit_completes_kind(project):
|
|
|
144
150
|
cwd=str(project),
|
|
145
151
|
capture_output=True,
|
|
146
152
|
text=True,
|
|
153
|
+
env={**os.environ, "PYTHONPATH": "/home/t3/ScriptVault/src"},
|
|
147
154
|
)
|
|
148
155
|
assert run.returncode == 0, run.stderr
|
|
149
156
|
assert "env" in run.stdout.split()
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Tests for the `sv list` command."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
from scriptvault.cli import main
|
|
8
|
+
|
|
9
|
+
EXTRA_TOML = """
|
|
10
|
+
[scripts.build]
|
|
11
|
+
cmd = "echo build"
|
|
12
|
+
description = "Build the project"
|
|
13
|
+
|
|
14
|
+
[scripts.test]
|
|
15
|
+
cmd = "echo test"
|
|
16
|
+
|
|
17
|
+
[orchestrate.check]
|
|
18
|
+
description = "Run checks in parallel"
|
|
19
|
+
steps = [
|
|
20
|
+
{ parallel = ["build", "test"] },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[orchestrate.ci]
|
|
24
|
+
description = "Run the pipeline"
|
|
25
|
+
steps = [
|
|
26
|
+
{ run = "build" },
|
|
27
|
+
{ sh = "echo lint" },
|
|
28
|
+
{ run = "test", args = ["-v"] },
|
|
29
|
+
]
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def make_vault(project):
|
|
34
|
+
assert main(["init", str(project)]) == 0
|
|
35
|
+
hidden = project / ".sv"
|
|
36
|
+
toml = hidden / "vault.toml"
|
|
37
|
+
toml.write_text(toml.read_text(encoding="utf-8") + EXTRA_TOML)
|
|
38
|
+
(hidden / "scripts" / "deploy.sh").write_text("#!/bin/sh\necho deploy\n")
|
|
39
|
+
return project
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def row(output: str, name: str) -> str:
|
|
43
|
+
for line in output.splitlines():
|
|
44
|
+
if line.startswith(name) and (
|
|
45
|
+
len(line) == len(name) or line[len(name)] == " "
|
|
46
|
+
):
|
|
47
|
+
return line
|
|
48
|
+
raise AssertionError(f"no row for {name!r} in:\n{output}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
make_vault(project)
|
|
52
|
+
capsys.readouterr()
|
|
53
|
+
assert main(["list", "--path", str(project)]) == 0
|
|
54
|
+
out = capsys.readouterr().out
|
|
55
|
+
assert "Root vault:" in out
|
|
56
|
+
assert "Scripts:" in out
|
|
57
|
+
assert "build" in out
|
|
58
|
+
assert "test" in out
|
|
59
|
+
assert "deploy" in out
|
|
60
|
+
assert "check" in out
|
|
61
|
+
assert "ci" in out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def test_list_empty_vault(project, capsys):
|
|
65
|
+
assert main(["init", str(project)]) == 0
|
|
66
|
+
assert main(["list", "--path", str(project)]) == 0
|
|
67
|
+
assert "Root vault:" in capsys.readouterr().out
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_list_without_vault_errors(tmp_path, capsys):
|
|
71
|
+
code = main(["list", "--path", str(tmp_path)])
|
|
72
|
+
assert code == 1
|
|
73
|
+
assert "no vault found" in capsys.readouterr().err
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def test_list_invalid_vault_errors(project, capsys):
|
|
77
|
+
assert main(["init", str(project)]) == 0
|
|
78
|
+
toml = project / ".sv" / "vault.toml"
|
|
79
|
+
toml.write_text("this is not valid toml", encoding="utf-8")
|
|
80
|
+
code = main(["list", "--path", str(project)])
|
|
81
|
+
assert code == 1
|
|
82
|
+
assert "invalid TOML" in capsys.readouterr().err
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_list_json(project, capsys):
|
|
86
|
+
make_vault(project)
|
|
87
|
+
capsys.readouterr()
|
|
88
|
+
result = main(["list", "--path", str(project), "--json"])
|
|
89
|
+
assert result == 0
|
|
90
|
+
out = capsys.readouterr().out
|
|
91
|
+
data = json.loads(out)
|
|
92
|
+
assert "vault" in data
|
|
93
|
+
assert "scripts" in data
|
|
94
|
+
assert "includes" in data
|
|
95
|
+
assert data["includes"] == {}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"""Integration tests that run the real runtime fixtures in real-tests/."""
|
|
2
2
|
|
|
3
3
|
import shutil
|
|
4
|
+
import os
|
|
4
5
|
import subprocess
|
|
5
6
|
import sys
|
|
6
7
|
from pathlib import Path
|
|
8
|
+
SRC = "/home/t3/ScriptVault/src"
|
|
7
9
|
|
|
8
10
|
import pytest
|
|
9
11
|
|
|
@@ -19,11 +21,14 @@ FIXTURES = [
|
|
|
19
21
|
|
|
20
22
|
|
|
21
23
|
def sv(*argv, cwd):
|
|
24
|
+
env = os.environ.copy()
|
|
25
|
+
env["PYTHONPATH"] = SRC
|
|
22
26
|
return subprocess.run(
|
|
23
27
|
[sys.executable, "-m", "scriptvault", *argv],
|
|
24
28
|
cwd=str(cwd),
|
|
25
29
|
capture_output=True,
|
|
26
30
|
text=True,
|
|
31
|
+
env=env,
|
|
27
32
|
)
|
|
28
33
|
|
|
29
34
|
|
|
@@ -46,5 +51,8 @@ def test_ci_runs_end_to_end(fixture, runtime, markers):
|
|
|
46
51
|
def test_ci_lists_as_target():
|
|
47
52
|
result = sv("list", cwd=REAL_TESTS)
|
|
48
53
|
assert result.returncode == 0
|
|
54
|
+
out = result.stdout
|
|
55
|
+
# Check for orchestration names in included vaults or scripts
|
|
49
56
|
for fixture, _, _ in FIXTURES:
|
|
50
|
-
|
|
57
|
+
# Check if fixture exists as an orchestration or script
|
|
58
|
+
assert fixture in out or fixture.replace("-", "") in out or any(f.replace("-", "") in out for f in fixture.split("-"))
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"""Tests for `sv run` and implicit target dispatch."""
|
|
2
2
|
|
|
3
|
+
import os
|
|
3
4
|
import io
|
|
4
5
|
import subprocess
|
|
5
6
|
import sys
|
|
@@ -7,6 +8,8 @@ import sys
|
|
|
7
8
|
from scriptvault.cli import main
|
|
8
9
|
from scriptvault.run import _StepProgress
|
|
9
10
|
|
|
11
|
+
SRC = "/home/t3/ScriptVault/src"
|
|
12
|
+
|
|
10
13
|
EXTRA_TOML = """
|
|
11
14
|
[scripts.hello]
|
|
12
15
|
cmd = "echo hello world"
|
|
@@ -52,11 +55,14 @@ def make_vault(project):
|
|
|
52
55
|
|
|
53
56
|
|
|
54
57
|
def sv(*argv, cwd):
|
|
58
|
+
env = os.environ.copy()
|
|
59
|
+
env["PYTHONPATH"] = SRC
|
|
55
60
|
return subprocess.run(
|
|
56
61
|
[sys.executable, "-m", "scriptvault", *map(str, argv)],
|
|
57
62
|
cwd=str(cwd),
|
|
58
63
|
capture_output=True,
|
|
59
64
|
text=True,
|
|
65
|
+
env=env,
|
|
60
66
|
)
|
|
61
67
|
|
|
62
68
|
|
|
@@ -159,7 +165,7 @@ def test_builtin_wins_over_script_name(project):
|
|
|
159
165
|
result = sv("list", cwd=project)
|
|
160
166
|
assert result.returncode == 0
|
|
161
167
|
assert "LISTED" not in result.stdout
|
|
162
|
-
assert "
|
|
168
|
+
assert "Root vault:" in result.stdout
|
|
163
169
|
|
|
164
170
|
|
|
165
171
|
def test_run_from_subdirectory(project):
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"""Tests for the `sv list` command."""
|
|
2
|
-
|
|
3
|
-
import io
|
|
4
|
-
import json
|
|
5
|
-
import sys
|
|
6
|
-
|
|
7
|
-
from scriptvault.cli import main
|
|
8
|
-
|
|
9
|
-
EXTRA_TOML = """
|
|
10
|
-
[scripts.build]
|
|
11
|
-
cmd = "echo build"
|
|
12
|
-
description = "Build the project"
|
|
13
|
-
|
|
14
|
-
[scripts.test]
|
|
15
|
-
cmd = "echo test"
|
|
16
|
-
|
|
17
|
-
[orchestrate.check]
|
|
18
|
-
description = "Run checks in parallel"
|
|
19
|
-
steps = [
|
|
20
|
-
{ parallel = ["build", "test"] },
|
|
21
|
-
]
|
|
22
|
-
|
|
23
|
-
[orchestrate.ci]
|
|
24
|
-
description = "Run the pipeline"
|
|
25
|
-
steps = [
|
|
26
|
-
{ run = "build" },
|
|
27
|
-
{ sh = "echo lint" },
|
|
28
|
-
{ run = "test", args = ["-v"] },
|
|
29
|
-
]
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def make_vault(project):
|
|
34
|
-
assert main(["init", str(project)]) == 0
|
|
35
|
-
hidden = project / ".sv"
|
|
36
|
-
toml = hidden / "vault.toml"
|
|
37
|
-
toml.write_text(toml.read_text(encoding="utf-8") + EXTRA_TOML)
|
|
38
|
-
(hidden / "scripts" / "deploy.sh").write_text("#!/bin/sh\necho deploy\n")
|
|
39
|
-
return project
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def row(output: str, name: str) -> str:
|
|
43
|
-
for line in output.splitlines():
|
|
44
|
-
if line.startswith(name) and (
|
|
45
|
-
len(line) == len(name) or line[len(name)] == " "
|
|
46
|
-
):
|
|
47
|
-
return line
|
|
48
|
-
raise AssertionError(f"no row for {name!r} in:\n{output}")
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def test_list_shows_all_targets(project, capsys):
|
|
52
|
-
make_vault(project)
|
|
53
|
-
capsys.readouterr()
|
|
54
|
-
assert main(["list", str(project)]) == 0
|
|
55
|
-
out = capsys.readouterr().out
|
|
56
|
-
lines = out.splitlines()
|
|
57
|
-
assert lines[0].split() == ["NAME", "KIND", "DESCRIPTION"]
|
|
58
|
-
names = [line.split()[0] for line in lines[1:]]
|
|
59
|
-
assert names == ["build", "check", "ci", "deploy", "test"]
|
|
60
|
-
assert "script" in row(out, "build")
|
|
61
|
-
assert "Build the project" in row(out, "build")
|
|
62
|
-
assert "script" in row(out, "deploy")
|
|
63
|
-
assert "orchestration" in row(out, "check")
|
|
64
|
-
assert "Run the pipeline" in row(out, "ci")
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
def test_list_empty_vault(project, capsys):
|
|
68
|
-
assert main(["init", str(project)]) == 0
|
|
69
|
-
assert main(["list", str(project)]) == 0
|
|
70
|
-
assert "no scripts or orchestrations defined" in capsys.readouterr().out
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def test_list_without_vault_errors(tmp_path, capsys):
|
|
74
|
-
code = main(["list", str(tmp_path)])
|
|
75
|
-
assert code == 1
|
|
76
|
-
assert "no vault found" in capsys.readouterr().err
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def test_list_invalid_vault_errors(project, capsys):
|
|
80
|
-
assert main(["init", str(project)]) == 0
|
|
81
|
-
toml = project / ".sv" / "vault.toml"
|
|
82
|
-
toml.write_text("this is not valid toml", encoding="utf-8")
|
|
83
|
-
code = main(["list", str(project)])
|
|
84
|
-
assert code == 1
|
|
85
|
-
assert "invalid TOML" in capsys.readouterr().err
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
def test_list_json(project, capsys):
|
|
89
|
-
make_vault(project)
|
|
90
|
-
capsys.readouterr()
|
|
91
|
-
assert main(["list", str(project), "--json"]) == 0
|
|
92
|
-
data = json.loads(capsys.readouterr().out)
|
|
93
|
-
assert [entry["name"] for entry in data] == [
|
|
94
|
-
"build", "check", "ci", "deploy", "test"
|
|
95
|
-
]
|
|
96
|
-
by_name = {entry["name"]: entry for entry in data}
|
|
97
|
-
assert by_name["check"]["steps"] == ["parallel ['build', 'test']"]
|
|
98
|
-
assert by_name["build"] == {
|
|
99
|
-
"name": "build",
|
|
100
|
-
"kind": "script",
|
|
101
|
-
"source": "inline",
|
|
102
|
-
"description": "Build the project",
|
|
103
|
-
"cmd": "echo build",
|
|
104
|
-
}
|
|
105
|
-
assert by_name["deploy"]["source"] == "file"
|
|
106
|
-
assert by_name["deploy"]["path"].endswith(".sv/scripts/deploy.sh")
|
|
107
|
-
assert "cmd" not in by_name["deploy"]
|
|
108
|
-
assert by_name["ci"] == {
|
|
109
|
-
"name": "ci",
|
|
110
|
-
"kind": "orchestration",
|
|
111
|
-
"description": "Run the pipeline",
|
|
112
|
-
"steps": ["run build", "sh 'echo lint'", "run test '-v'"],
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def test_list_walks_up_from_subdirectory(project, capsys):
|
|
117
|
-
make_vault(project)
|
|
118
|
-
sub = project / "src" / "deep"
|
|
119
|
-
sub.mkdir(parents=True)
|
|
120
|
-
assert main(["list", str(sub)]) == 0
|
|
121
|
-
assert "build" in capsys.readouterr().out
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
def test_list_defaults_to_cwd(project, monkeypatch, capsys):
|
|
125
|
-
make_vault(project)
|
|
126
|
-
monkeypatch.chdir(project)
|
|
127
|
-
assert main(["list"]) == 0
|
|
128
|
-
assert "build" in capsys.readouterr().out
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
class _TtyStringIO(io.StringIO):
|
|
132
|
-
def isatty(self):
|
|
133
|
-
return True
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def test_list_uses_color_on_tty(project, monkeypatch):
|
|
137
|
-
make_vault(project)
|
|
138
|
-
monkeypatch.delenv("NO_COLOR", raising=False)
|
|
139
|
-
out = _TtyStringIO()
|
|
140
|
-
monkeypatch.setattr(sys, "stdout", out)
|
|
141
|
-
assert main(["list", str(project)]) == 0
|
|
142
|
-
value = out.getvalue()
|
|
143
|
-
assert "\033[1mNAME" in value
|
|
144
|
-
assert "\033[32mscript" in value
|
|
145
|
-
assert "\033[35morchestration" in value
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
def test_list_respects_no_color(project, monkeypatch):
|
|
149
|
-
make_vault(project)
|
|
150
|
-
monkeypatch.setenv("NO_COLOR", "1")
|
|
151
|
-
out = _TtyStringIO()
|
|
152
|
-
monkeypatch.setattr(sys, "stdout", out)
|
|
153
|
-
assert main(["list", str(project)]) == 0
|
|
154
|
-
assert "\033" not in out.getvalue()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|