bst-docs 0.0.3__tar.gz → 0.0.4__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.
- {bst_docs-0.0.3 → bst_docs-0.0.4}/PKG-INFO +1 -1
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs/build.py +9 -6
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs/element.py +21 -3
- bst_docs-0.0.4/bst_docs/includes.py +47 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs/load_contents.py +6 -4
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs/render.py +3 -3
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs.egg-info/PKG-INFO +1 -1
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs.egg-info/SOURCES.txt +1 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/pyproject.toml +1 -1
- {bst_docs-0.0.3 → bst_docs-0.0.4}/LICENSE +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/README.md +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs/__init__.py +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs/__main__.py +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs.egg-info/dependency_links.txt +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs.egg-info/entry_points.txt +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs.egg-info/requires.txt +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/bst_docs.egg-info/top_level.txt +0 -0
- {bst_docs-0.0.3 → bst_docs-0.0.4}/setup.cfg +0 -0
|
@@ -30,6 +30,12 @@ from bst_docs.render import RenderConfig
|
|
|
30
30
|
required=False,
|
|
31
31
|
help="Remove all files from cache & output directories",
|
|
32
32
|
)
|
|
33
|
+
@click.option(
|
|
34
|
+
"--load-includes",
|
|
35
|
+
default=True,
|
|
36
|
+
required=False,
|
|
37
|
+
help="Load content from file includes",
|
|
38
|
+
)
|
|
33
39
|
@click.option(
|
|
34
40
|
"--html-elements",
|
|
35
41
|
default=True,
|
|
@@ -64,10 +70,7 @@ def build(
|
|
|
64
70
|
**kwargs: str,
|
|
65
71
|
) -> None:
|
|
66
72
|
"""Generate documentation for a BuildStream project."""
|
|
67
|
-
config = RenderConfig(
|
|
68
|
-
**kwargs,
|
|
69
|
-
)
|
|
70
|
-
|
|
73
|
+
config = RenderConfig(**kwargs)
|
|
71
74
|
if kwargs.get("clean"):
|
|
72
75
|
shutil.rmtree(".cache")
|
|
73
76
|
logging.warning("Nuking cache: %s", ".cache")
|
|
@@ -79,12 +82,12 @@ def build(
|
|
|
79
82
|
logging.warning("Overwriting %s", dst)
|
|
80
83
|
shutil.rmtree(dst)
|
|
81
84
|
dst.mkdir()
|
|
82
|
-
files, _config = load_project(path)
|
|
85
|
+
files, _config = load_project(path, bool(kwargs.get("load_includes")))
|
|
83
86
|
|
|
84
87
|
for f in tqdm.tqdm(files, "Finding dependants"):
|
|
85
88
|
for kind, dependencies in f.all_dependencies().items():
|
|
86
89
|
for dep in dependencies:
|
|
87
|
-
dep = dep if isinstance(dep, str) else dep
|
|
90
|
+
dep = dep if isinstance(dep, str) else dep.get("filename", "")
|
|
88
91
|
try:
|
|
89
92
|
element_dep = next(x for x in files if x.bst_name == dep)
|
|
90
93
|
element_dep.dependants[kind].append(f.bst_name)
|
|
@@ -8,6 +8,7 @@ from pathlib import Path
|
|
|
8
8
|
|
|
9
9
|
import mdformat
|
|
10
10
|
|
|
11
|
+
from bst_docs.includes import INCLUDE_KEY, load_include, meld_confs
|
|
11
12
|
from bst_docs.render import (
|
|
12
13
|
RenderConfig,
|
|
13
14
|
add_summary_block,
|
|
@@ -24,7 +25,7 @@ class Element:
|
|
|
24
25
|
_conf: dict
|
|
25
26
|
raw: str
|
|
26
27
|
|
|
27
|
-
def __init__(self, _conf: dict, raw: str) -> None:
|
|
28
|
+
def __init__(self, _conf: dict, raw: str, load_includes: bool) -> None:
|
|
28
29
|
"""Initialize Element."""
|
|
29
30
|
self._conf = _conf
|
|
30
31
|
self.raw = raw
|
|
@@ -33,6 +34,17 @@ class Element:
|
|
|
33
34
|
"build-depends": [],
|
|
34
35
|
"runtime-depends": [],
|
|
35
36
|
}
|
|
37
|
+
if load_includes:
|
|
38
|
+
self.load_includes()
|
|
39
|
+
|
|
40
|
+
def load_includes(self) -> None:
|
|
41
|
+
"""Import all includes into element conf."""
|
|
42
|
+
if includes := self._conf.get(INCLUDE_KEY):
|
|
43
|
+
includes = [includes] if not isinstance(includes, list) else includes
|
|
44
|
+
self._conf.pop(INCLUDE_KEY)
|
|
45
|
+
for file in includes:
|
|
46
|
+
include_conf = load_include(self.project_base, file)
|
|
47
|
+
self._conf = meld_confs(self._conf, include_conf)
|
|
36
48
|
|
|
37
49
|
@property
|
|
38
50
|
def name(self) -> str:
|
|
@@ -124,10 +136,15 @@ class Element:
|
|
|
124
136
|
output[depend_kind] = self._conf.get(depend_kind, [])
|
|
125
137
|
return output
|
|
126
138
|
|
|
127
|
-
def _render_field(
|
|
139
|
+
def _render_field(
|
|
140
|
+
self,
|
|
141
|
+
element: str,
|
|
142
|
+
config: RenderConfig,
|
|
143
|
+
title: str | None = None,
|
|
144
|
+
) -> str:
|
|
128
145
|
"""Render a named configuration field as a section."""
|
|
129
146
|
return (
|
|
130
|
-
f"## {element.title()}\n\n"
|
|
147
|
+
f"## {title.title() if title else element.title()}\n\n"
|
|
131
148
|
+ render_value(self._conf.get(element, {}), config)
|
|
132
149
|
if self._conf.get(element, {})
|
|
133
150
|
else ""
|
|
@@ -141,6 +158,7 @@ class Element:
|
|
|
141
158
|
`{self._conf.get("kind", "Unknown")}`
|
|
142
159
|
{self.description or "--"}
|
|
143
160
|
|
|
161
|
+
|
|
144
162
|
## Dependencies
|
|
145
163
|
|
|
146
164
|
{self._format_link_list("depends", config, self._conf)}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Handle loading configurations from includes."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from yaml import safe_load
|
|
6
|
+
|
|
7
|
+
INCLUDE_KEY = "(@)"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def meld_confs(conf1: dict, conf2: dict) -> dict:
|
|
11
|
+
"""Merge two configuration dictionaries together."""
|
|
12
|
+
output = {}
|
|
13
|
+
for key in list(conf1.keys()) + list(conf2.keys()):
|
|
14
|
+
v1 = conf1.get(key)
|
|
15
|
+
v2 = conf2.get(key)
|
|
16
|
+
if v1 is None or v2 is None:
|
|
17
|
+
output[key] = v1 or v2
|
|
18
|
+
continue
|
|
19
|
+
if v1 == v2:
|
|
20
|
+
output[key] = v1
|
|
21
|
+
continue
|
|
22
|
+
match (v1, v2):
|
|
23
|
+
case (dict(), dict()):
|
|
24
|
+
output[key] = v1 | v2
|
|
25
|
+
case (list(), list()):
|
|
26
|
+
output[key] = v1 + v2
|
|
27
|
+
case (dict(), list()) | (list(), dict()):
|
|
28
|
+
list_el = v1 if isinstance(v1, list) else v2
|
|
29
|
+
dict_el = v1 if isinstance(v1, dict) else v2
|
|
30
|
+
output[key] = [*list_el, dict_el]
|
|
31
|
+
|
|
32
|
+
case _others:
|
|
33
|
+
raise TypeError(f"{type(v1), type(v2)}")
|
|
34
|
+
return output
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def load_include(project_base: Path, include_name: str) -> dict:
|
|
38
|
+
"""Load an include and all of it's includes."""
|
|
39
|
+
real_path = project_base / include_name
|
|
40
|
+
output = safe_load((real_path).read_text())
|
|
41
|
+
if includes := output.get(INCLUDE_KEY):
|
|
42
|
+
output.pop(INCLUDE_KEY)
|
|
43
|
+
includes = [includes] if not isinstance(includes, list) else includes
|
|
44
|
+
for i in includes:
|
|
45
|
+
conf = load_include(project_base, i)
|
|
46
|
+
output = meld_confs(output, conf)
|
|
47
|
+
return output
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import logging
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
|
|
6
|
+
import tqdm
|
|
6
7
|
import validators
|
|
7
8
|
from git import Repo
|
|
8
9
|
from yaml import safe_load
|
|
@@ -13,7 +14,7 @@ DEFAULT_PROJECT_CONF = "project.conf"
|
|
|
13
14
|
CACHE_DIR = Path("./.cache")
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
def load_project(path: str | Path) -> tuple[list[Element], dict]:
|
|
17
|
+
def load_project(path: str | Path, load_includes: bool) -> tuple[list[Element], dict]:
|
|
17
18
|
"""Load a BuildStream project from a URL or local path."""
|
|
18
19
|
output = ([], {})
|
|
19
20
|
if validators.url(path):
|
|
@@ -25,11 +26,11 @@ def load_project(path: str | Path) -> tuple[list[Element], dict]:
|
|
|
25
26
|
logging.info("Using cached %s", git_repo_name)
|
|
26
27
|
path = CACHE_DIR / git_repo_name
|
|
27
28
|
if Path(path).resolve().exists():
|
|
28
|
-
output = load_local_project(Path(path).resolve())
|
|
29
|
+
output = load_local_project(Path(path).resolve(), load_includes)
|
|
29
30
|
return output
|
|
30
31
|
|
|
31
32
|
|
|
32
|
-
def load_local_project(path: Path) -> tuple[list[Element], dict]:
|
|
33
|
+
def load_local_project(path: Path, load_includes: bool) -> tuple[list[Element], dict]:
|
|
33
34
|
"""Load a BuildStream project from a local filesystem path."""
|
|
34
35
|
conf_path: Path = path / DEFAULT_PROJECT_CONF
|
|
35
36
|
assert (conf_path).exists(), "Project could not be loaded (no configuration file)"
|
|
@@ -37,7 +38,7 @@ def load_local_project(path: Path) -> tuple[list[Element], dict]:
|
|
|
37
38
|
element_path: Path = path / conf.get("element-path", "elements")
|
|
38
39
|
assert (conf_path).exists(), "Project could not be loaded (no element path)"
|
|
39
40
|
elements: list[Element] = []
|
|
40
|
-
for f in element_path.glob("**/*.bst"):
|
|
41
|
+
for f in tqdm.tqdm(list(element_path.glob("**/*.bst")), "Loading Elements"):
|
|
41
42
|
raw = f.read_text("utf-8")
|
|
42
43
|
yml = safe_load(raw)
|
|
43
44
|
elements.append(
|
|
@@ -49,6 +50,7 @@ def load_local_project(path: Path) -> tuple[list[Element], dict]:
|
|
|
49
50
|
"element_path": element_path.relative_to(path),
|
|
50
51
|
},
|
|
51
52
|
raw,
|
|
53
|
+
load_includes=load_includes,
|
|
52
54
|
),
|
|
53
55
|
)
|
|
54
56
|
return elements, conf
|
|
@@ -14,12 +14,12 @@ class RenderConfig:
|
|
|
14
14
|
|
|
15
15
|
def __init__(self, **kwargs: str) -> None:
|
|
16
16
|
"""Initialize RenderConfig."""
|
|
17
|
-
self.all_html_fixes = bool(kwargs.get("
|
|
17
|
+
self.all_html_fixes = bool(kwargs.get("all_html_fixes", False))
|
|
18
18
|
self.use_html_exts = self.all_html_fixes or bool(
|
|
19
|
-
kwargs.get("
|
|
19
|
+
kwargs.get("use_html_exts", False),
|
|
20
20
|
)
|
|
21
21
|
self.use_html = self.all_html_fixes or bool(
|
|
22
|
-
kwargs.get("
|
|
22
|
+
kwargs.get("html_elements", False),
|
|
23
23
|
)
|
|
24
24
|
|
|
25
25
|
|
|
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
|