sigil-cli 1.4.2__tar.gz → 1.5.1__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.
- {sigil_cli-1.4.2/src/sigil_cli.egg-info → sigil_cli-1.5.1}/PKG-INFO +1 -1
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/pyproject.toml +3 -1
- sigil_cli-1.5.1/src/sigil/datasource/__init__.py +15 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/datasource/datasource.py +3 -2
- sigil_cli-1.5.1/src/sigil/datasource/helper.py +35 -0
- sigil_cli-1.5.1/src/sigil/datasource/json_source.py +45 -0
- sigil_cli-1.5.1/src/sigil/datasource/yml_source.py +45 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/entrypoint.py +3 -2
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/stages/parser.py +2 -2
- {sigil_cli-1.4.2 → sigil_cli-1.5.1/src/sigil_cli.egg-info}/PKG-INFO +1 -1
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil_cli.egg-info/SOURCES.txt +2 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_integration.py +4 -3
- sigil_cli-1.4.2/src/sigil/datasource/__init__.py +0 -7
- sigil_cli-1.4.2/src/sigil/datasource/yml_source.py +0 -35
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/LICENSE +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/README.md +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/setup.cfg +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/__init__.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/__main__.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/cli_tools/__init__.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/cli_tools/init.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/cli_tools/tree.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/cli_tools/validate.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/models/__init__.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/models/argparser.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/models/argument.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/models/command.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/models/script.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/stages/__init__.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/stages/builder.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/stages/resolver.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil/stages/script_loader.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil_cli.egg-info/dependency_links.txt +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil_cli.egg-info/entry_points.txt +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil_cli.egg-info/requires.txt +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/src/sigil_cli.egg-info/top_level.txt +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_builder.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_cli_init.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_cli_tree.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_cli_validate.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_reader.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_resolver.py +0 -0
- {sigil_cli-1.4.2 → sigil_cli-1.5.1}/tests/test_scriptloader.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sigil-cli"
|
|
7
|
-
version = "1.
|
|
7
|
+
version = "1.5.1"
|
|
8
8
|
description = "Configuration driven CLI builder with subcommands and script loading"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -28,6 +28,7 @@ dependencies = [
|
|
|
28
28
|
[project.optional-dependencies]
|
|
29
29
|
completion = ["argcomplete>=3.0"]
|
|
30
30
|
dev = ["pytest", "pytest-cov", "ruff"]
|
|
31
|
+
# yaml = ["pyyaml>=6.0"] # planned default for PEP 771
|
|
31
32
|
|
|
32
33
|
[project.urls]
|
|
33
34
|
Homepage = "https://github.com/kenzo-staelens/sigil"
|
|
@@ -43,6 +44,7 @@ where = ["src"]
|
|
|
43
44
|
[tool.coverage.run]
|
|
44
45
|
omit = [
|
|
45
46
|
"src/sigil/__main__.py",
|
|
47
|
+
"src/sigil/datasource/json_source.py", # nearly 1:1 with yml source
|
|
46
48
|
"tests/*",
|
|
47
49
|
"*/scripts/*"
|
|
48
50
|
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from .datasource import DataSource
|
|
2
|
+
from .json_source import JSONSource
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
'DataSource',
|
|
6
|
+
'JSONSource',
|
|
7
|
+
]
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
# preparation for PEP 771 or conversion to `pip install sigil-cli[yaml]` install
|
|
11
|
+
# any datasources with dependencies should import like this
|
|
12
|
+
from .yml_source import YmlSource # noqa: F401
|
|
13
|
+
__all__.append('YmlSource')
|
|
14
|
+
except ImportError:
|
|
15
|
+
pass
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
from abc import ABC, abstractmethod
|
|
2
2
|
from pathlib import Path
|
|
3
|
+
from typing import Any
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
# currently network based datasources are not planned
|
|
6
7
|
# but if you do *need* one for some reason, feel free to make a PR
|
|
7
8
|
class DataSource(ABC):
|
|
8
9
|
@abstractmethod
|
|
9
|
-
def read_manifest(self, target:
|
|
10
|
+
def read_manifest(self, root_path: Path, target: Any) -> list | None:
|
|
10
11
|
# current implementation expects a list of files, or none on error
|
|
11
12
|
...
|
|
12
13
|
|
|
13
14
|
@abstractmethod
|
|
14
|
-
def read_configuration(self, target:
|
|
15
|
+
def read_configuration(self, root_path: Path, target: Any) -> dict | None:
|
|
15
16
|
# raw data roughly mapping to internal models
|
|
16
17
|
# validation happens in a later stage
|
|
17
18
|
# datasources shouldn't need to validate
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def _expandpath(config_root: Path, path_pattern: Path) -> Iterable[Path]:
|
|
6
|
+
_has_glob = lambda part: any(ch in part for ch in "*?[") # noqa: E731
|
|
7
|
+
p: Path = (config_root/path_pattern).resolve()
|
|
8
|
+
str_p = str(p)
|
|
9
|
+
|
|
10
|
+
# Quick check: does this path contain any glob pattern at all?
|
|
11
|
+
if not _has_glob(str_p):
|
|
12
|
+
yield p.resolve()
|
|
13
|
+
return # is this cursed? yes, does it work somehow? also yes
|
|
14
|
+
parts = p.parts
|
|
15
|
+
|
|
16
|
+
# Find the first part that contains a wildcard
|
|
17
|
+
first_glob_idx = 0
|
|
18
|
+
for i, part in enumerate(parts):
|
|
19
|
+
if _has_glob(part):
|
|
20
|
+
first_glob_idx = i
|
|
21
|
+
break
|
|
22
|
+
|
|
23
|
+
# Build the literal base directory and the relative glob pattern
|
|
24
|
+
if first_glob_idx == 0:
|
|
25
|
+
base = Path('.')
|
|
26
|
+
if parts[0] == '/': # pesky absolute paths
|
|
27
|
+
base = Path('/')
|
|
28
|
+
parts = parts[1:]
|
|
29
|
+
else:
|
|
30
|
+
base = Path(*parts[:first_glob_idx])
|
|
31
|
+
|
|
32
|
+
pattern = "/".join(parts[first_glob_idx:])
|
|
33
|
+
# Expand the pattern relative to the base, and resolve each match
|
|
34
|
+
for match in base.glob(pattern):
|
|
35
|
+
yield match.resolve()
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
import json
|
|
3
|
+
import logging
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from .datasource import DataSource
|
|
7
|
+
from .helper import _expandpath
|
|
8
|
+
|
|
9
|
+
_logger = logging.getLogger(__name__)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# base defines abstract as not-classmethod
|
|
13
|
+
# though instantiation is not a requirement
|
|
14
|
+
# if you don't need instance data, classmethods are fine too
|
|
15
|
+
class JSONSource(DataSource):
|
|
16
|
+
def read(self, root_path: Path, filename: str) -> dict:
|
|
17
|
+
try:
|
|
18
|
+
target = root_path/filename
|
|
19
|
+
with open(target) as f:
|
|
20
|
+
return json.load(f)
|
|
21
|
+
# return yaml.load(f.read(), Loader=yaml.SafeLoader)
|
|
22
|
+
except FileNotFoundError:
|
|
23
|
+
_logger.error(f"file '{target}' not found")
|
|
24
|
+
return
|
|
25
|
+
except json.JSONDecodeError as e:
|
|
26
|
+
_logger.error(f"malformed json file ({target})\n {e}")
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def read_manifest(self, root_path: Path, filename: str) -> list | None:
|
|
31
|
+
# indirection? yes
|
|
32
|
+
# can new datasources implement a better manifest vs data? also yes
|
|
33
|
+
raw_manifest = self.read(root_path, filename)
|
|
34
|
+
res_manifest = []
|
|
35
|
+
for line in raw_manifest:
|
|
36
|
+
res_manifest = itertools.chain(
|
|
37
|
+
res_manifest,
|
|
38
|
+
_expandpath(root_path, Path(line))
|
|
39
|
+
)
|
|
40
|
+
return res_manifest
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def read_configuration(self, root_path: Path, filename: str) -> dict | None:
|
|
44
|
+
return self.read(root_path, filename)
|
|
45
|
+
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import itertools
|
|
2
|
+
import logging
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import yaml
|
|
6
|
+
|
|
7
|
+
from .datasource import DataSource
|
|
8
|
+
from .helper import _expandpath
|
|
9
|
+
|
|
10
|
+
_logger = logging.getLogger(__name__)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# base defines abstract as not-classmethod
|
|
14
|
+
# though instantiation is not a requirement
|
|
15
|
+
# if you don't need instance data, classmethods are fine too
|
|
16
|
+
class YmlSource(DataSource):
|
|
17
|
+
def read(self, root_path: Path, filename: str) -> dict:
|
|
18
|
+
try:
|
|
19
|
+
target = root_path/filename
|
|
20
|
+
with open(target) as f:
|
|
21
|
+
return yaml.load(f.read(), Loader=yaml.SafeLoader)
|
|
22
|
+
except FileNotFoundError:
|
|
23
|
+
_logger.error(f"file '{target}' not found")
|
|
24
|
+
return
|
|
25
|
+
except yaml.error.YAMLError as e:
|
|
26
|
+
_logger.error(f"malformed yaml file ({target})\n {e}")
|
|
27
|
+
return
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def read_manifest(self, root_path: Path, filename: str) -> list | None:
|
|
31
|
+
# indirection? yes
|
|
32
|
+
# can new datasources implement a better manifest vs data? also yes
|
|
33
|
+
raw_manifest = self.read(root_path, filename)
|
|
34
|
+
res_manifest = []
|
|
35
|
+
for line in raw_manifest:
|
|
36
|
+
res_manifest = itertools.chain(
|
|
37
|
+
res_manifest,
|
|
38
|
+
_expandpath(root_path, Path(line))
|
|
39
|
+
)
|
|
40
|
+
return res_manifest
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def read_configuration(self, root_path: Path, filename: str) -> dict | None:
|
|
44
|
+
return self.read(root_path, filename)
|
|
45
|
+
|
|
@@ -11,9 +11,10 @@ _logger = logging.getLogger(__name__)
|
|
|
11
11
|
# default to yamlloader, use whatever datastore you feel like
|
|
12
12
|
def run_from_config(
|
|
13
13
|
config_root: str | Path,
|
|
14
|
-
datasource: DataSource | type[DataSource] = YmlSource
|
|
14
|
+
datasource: DataSource | type[DataSource] = YmlSource,
|
|
15
|
+
manifest_target='manifest.yml',
|
|
15
16
|
) -> None:
|
|
16
|
-
raw_data = Parser(datasource).load(config_root)
|
|
17
|
+
raw_data = Parser(datasource).load(config_root, manifest_target)
|
|
17
18
|
resolved = Resolver.resolve_inheritance(raw_data)
|
|
18
19
|
# parser beyond here is an argparser
|
|
19
20
|
parser = Builder.build(resolved)
|
|
@@ -35,14 +35,14 @@ class Parser:
|
|
|
35
35
|
) -> dict[str, ParserConfig]:
|
|
36
36
|
config_root_path = Path(config_root)
|
|
37
37
|
|
|
38
|
-
manifest = self.datasource.read_manifest(config_root_path
|
|
38
|
+
manifest = self.datasource.read_manifest(config_root_path, manifest_file)
|
|
39
39
|
if not manifest:
|
|
40
40
|
_logger.critical("could not load manifest, aborting")
|
|
41
41
|
sys.exit(1)
|
|
42
42
|
loaded_config = {}
|
|
43
43
|
|
|
44
44
|
for entry in manifest:
|
|
45
|
-
loaded_entry = self.datasource.read_configuration(config_root_path
|
|
45
|
+
loaded_entry = self.datasource.read_configuration(config_root_path, entry)
|
|
46
46
|
if not loaded_entry:
|
|
47
47
|
continue
|
|
48
48
|
tmp = {}
|
|
@@ -10,6 +10,8 @@ src/sigil/cli_tools/tree.py
|
|
|
10
10
|
src/sigil/cli_tools/validate.py
|
|
11
11
|
src/sigil/datasource/__init__.py
|
|
12
12
|
src/sigil/datasource/datasource.py
|
|
13
|
+
src/sigil/datasource/helper.py
|
|
14
|
+
src/sigil/datasource/json_source.py
|
|
13
15
|
src/sigil/datasource/yml_source.py
|
|
14
16
|
src/sigil/models/__init__.py
|
|
15
17
|
src/sigil/models/argparser.py
|
|
@@ -18,10 +18,11 @@ def test_integration_run_from_config_with_capsys(tmp_path, capsys):
|
|
|
18
18
|
"""Test run_from_config and capture output."""
|
|
19
19
|
# Same setup as above
|
|
20
20
|
manifest = tmp_path / "manifest.yml"
|
|
21
|
-
|
|
21
|
+
(tmp_path/'yml').mkdir()
|
|
22
|
+
manifest.write_text("- yml/*.yml\n")
|
|
22
23
|
|
|
23
24
|
root_data = {"root": {"name": "hello", "script_dir": "scripts"}}
|
|
24
|
-
(tmp_path / "root.yml").write_text(yaml.dump(root_data))
|
|
25
|
+
(tmp_path / "yml/root.yml").write_text(yaml.dump(root_data))
|
|
25
26
|
|
|
26
27
|
hello_data = {
|
|
27
28
|
"hello_cmd": {
|
|
@@ -31,7 +32,7 @@ def test_integration_run_from_config_with_capsys(tmp_path, capsys):
|
|
|
31
32
|
"args": [{"name": "--name", "default": "world"}],
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
|
-
(tmp_path / "hello.yml").write_text(yaml.dump(hello_data))
|
|
35
|
+
(tmp_path / "yml/hello.yml").write_text(yaml.dump(hello_data))
|
|
35
36
|
|
|
36
37
|
script_dir = tmp_path / "scripts"
|
|
37
38
|
script_dir.mkdir()
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
|
|
4
|
-
import yaml
|
|
5
|
-
|
|
6
|
-
from .datasource import DataSource
|
|
7
|
-
|
|
8
|
-
_logger = logging.getLogger(__name__)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
# base defines abstract as not-classmethod
|
|
12
|
-
# though instantiation is not a requirement
|
|
13
|
-
# if you don't need instance data, classmethods are fine too
|
|
14
|
-
class YmlSource(DataSource):
|
|
15
|
-
def read(self, target):
|
|
16
|
-
try:
|
|
17
|
-
with open(target) as f:
|
|
18
|
-
return yaml.load(f.read(), Loader=yaml.SafeLoader)
|
|
19
|
-
except FileNotFoundError:
|
|
20
|
-
_logger.error(f"file '{target}' not found")
|
|
21
|
-
return
|
|
22
|
-
except yaml.error.YAMLError:
|
|
23
|
-
_logger.error(f"malformed yaml file ({target})")
|
|
24
|
-
return
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def read_manifest(self, target: Path) -> list | None:
|
|
28
|
-
# indirection? yes
|
|
29
|
-
# can new datasources implement a better manifest vs data? also yes
|
|
30
|
-
return self.read(target)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def read_configuration(self, target: Path) -> dict | None:
|
|
34
|
-
return self.read(target)
|
|
35
|
-
|
|
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
|
|
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
|