Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Sep 25, 2023
1 parent 3982064 commit a882761
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mknodes/basenodes/mktimeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions mknodes/info/yamlfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)


Expand Down
10 changes: 2 additions & 8 deletions mknodes/manual/internals_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mknodes/utils/superdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions mknodes/utils/yamlhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""

Expand All @@ -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

Expand All @@ -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":
Expand Down

0 comments on commit a882761

Please sign in to comment.