From a88276143c1e87831faec46afb97d0133c60107e Mon Sep 17 00:00:00 2001 From: phil65 Date: Mon, 25 Sep 2023 23:46:50 +0200 Subject: [PATCH] chore: cleanup --- mknodes/basenodes/mktimeline.py | 2 +- mknodes/info/yamlfile.py | 6 +++--- mknodes/manual/internals_section.py | 10 ++-------- mknodes/utils/superdict.py | 4 ++-- mknodes/utils/yamlhelpers.py | 8 +++++--- 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/mknodes/basenodes/mktimeline.py b/mknodes/basenodes/mktimeline.py index eb5ccb5f..ccf4bae1 100644 --- a/mknodes/basenodes/mktimeline.py +++ b/mknodes/basenodes/mktimeline.py @@ -113,7 +113,7 @@ def __repr__(self): def _to_markdown(self) -> str: root = xml.Section("timeline") - div = xml.Div("container", parent=root) + div = xml.Div(parent=root) for i, item in enumerate(self.items): item.fade_direction = "left" if i % 2 == 0 else "right" elem = item.get_element() diff --git a/mknodes/info/yamlfile.py b/mknodes/info/yamlfile.py index bc979d9f..efc7d7bb 100644 --- a/mknodes/info/yamlfile.py +++ b/mknodes/info/yamlfile.py @@ -14,14 +14,14 @@ class YamlFile(configfile.ConfigFile): def __init__( self, path: str | os.PathLike | None = None, - mode: str = "unsafe", + mode: yamlhelpers.LoaderStr = "unsafe", inherit_from: str | os.PathLike | None = None, ): super().__init__(path) if inherit_from: self.resolve_inherit_tag(inherit_from, mode) - def resolve_inherit_tag(self, parent_path: str | os.PathLike, mode: str = "unsafe"): + def resolve_inherit_tag(self, parent_path: str | os.PathLike, mode: yamlhelpers.LoaderStr = "unsafe"): """Merge the current data with data of of given parent_path file. Arguments: @@ -48,7 +48,7 @@ def _dump(cls, data: dict) -> str: return yamlhelpers.dump_yaml(data) @classmethod - def _load(cls, data: str, mode: str = "unsafe") -> dict | list: + def _load(cls, data: str, mode: yamlhelpers.LoaderStr = "unsafe") -> dict | list: return yamlhelpers.load_yaml(data, mode) diff --git a/mknodes/manual/internals_section.py b/mknodes/manual/internals_section.py index a6310f0a..8aa2ff45 100644 --- a/mknodes/manual/internals_section.py +++ b/mknodes/manual/internals_section.py @@ -3,13 +3,11 @@ nav = mk.MkNav("Internals") -# - Clone repository (in case it is a remote one) -# - Aggregate information about repository from: STEP_1 = ( "### Set up the working directory\nClone the repository (in case it is a remote one)" ) -STEP_2 = "Aggregate information about the repository from:" +STEP_2 = "### Aggregate info\nAggregate information about the repository from:" INFO_PROVIDERS = [ "metadata.Distribution", "PyProject File", @@ -53,10 +51,7 @@ def create_internals_section(root_nav: mk.MkNav): node = mk.MkTimeline() node.add_item(date="Step 1", content=STEP_1) ls = mk.MkList(INFO_PROVIDERS) - node.add_item( - date="Step 2", - content=mk.MkContainer([STEP_2, ls], header="### Aggregate info"), - ) + node.add_item(date="Step 2", content=mk.MkContainer([STEP_2, ls])) node.add_item(date="Step 3", content=STEP_3) node.add_item(date="Step 4", content=STEP_4) node.add_item(date="Step 5", content=STEP_5) @@ -68,7 +63,6 @@ def create_internals_section(root_nav: mk.MkNav): page += node page.created_by = create_internals_section - # @nav.route.page("Tree", hide="toc", icon="graph") # def create_tree_page(page: mk.MkPage): # page += mk.MkHeader("This is the tree we built up to now.", level=3) diff --git a/mknodes/utils/superdict.py b/mknodes/utils/superdict.py index bc789f2e..87dcb09e 100644 --- a/mknodes/utils/superdict.py +++ b/mknodes/utils/superdict.py @@ -41,7 +41,7 @@ def __len__(self): return len(self._data) def get_section(self, *sections: str, keep_path: bool = False) -> Any: - """Try to get data[sections[0]][sections[1]]... + """Try to get data with given section path. If Key path does not exist, return None. @@ -75,7 +75,7 @@ def get_section(self, *sections: str, keep_path: bool = False) -> Any: result = result[sect] return SuperDict(new) if isinstance(new, dict) else new - def serialize(self, mode: MarkupTypeStr | None): + def serialize(self, mode: MarkupTypeStr | None) -> str: # type: ignore[return] match mode: case None | "yaml": from mknodes.utils import yamlhelpers diff --git a/mknodes/utils/yamlhelpers.py b/mknodes/utils/yamlhelpers.py index 44f263da..3d12c938 100644 --- a/mknodes/utils/yamlhelpers.py +++ b/mknodes/utils/yamlhelpers.py @@ -13,6 +13,8 @@ logger = log.get_logger(__name__) YAMLError = yaml.YAMLError +LoaderStr = Literal["unsafe", "full", "safe"] + def patch_dumper_to_not_order(dumper_cls): def map_representer(dumper_cls_, data): @@ -34,7 +36,7 @@ def patch_pyyaml_to_not_order_dicts(): # patch_pyyaml_to_not_order_dicts() -def get_safe_loader(base_loader_cls): +def get_safe_loader(base_loader_cls: type): class SafeLoader(base_loader_cls): """Safe Loader.""" @@ -50,7 +52,7 @@ class SafeLoader(base_loader_cls): return SafeLoader -def get_default_loader(base_loader_cls): +def get_default_loader(base_loader_cls: type): # Attach Environment Variable constructor. # See https://github.com/waylan/pyyaml-env-tag @@ -68,7 +70,7 @@ class DefaultLoader(base_loader_cls): return DefaultLoader -def load_yaml(text: str, mode="unsafe"): +def load_yaml(text: str, mode: LoaderStr = "unsafe"): """Wrap PyYaml's loader so we can extend it to suit our needs.""" match mode: case "unsafe":