diff --git a/mknodes/basenodes/mkcontainer.py b/mknodes/basenodes/mkcontainer.py index 71274506..80ca0d9a 100644 --- a/mknodes/basenodes/mkcontainer.py +++ b/mknodes/basenodes/mkcontainer.py @@ -31,21 +31,18 @@ def __init__( kwargs: Keyword arguments passed to parent """ super().__init__(**kwargs) - self.items: list[mknode.MkNode] = [] self.block_separator = "\n\n" if block_separator is None else block_separator match content: case None: - items: list[mknode.MkNode] = [] + self.items: list[mknode.MkNode] = [] case str(): - items = [self.to_child_node(content)] if content else [] + self.items = [self.to_child_node(content)] if content else [] case mknode.MkNode(): - items = [self.to_child_node(content)] + self.items = [self.to_child_node(content)] case list(): - items = [self.to_child_node(i) for i in content] + self.items = [self.to_child_node(i) for i in content] case _: raise TypeError(content) - for item in items: - self.append(item) def __bool__(self): return bool(self.items) @@ -63,7 +60,7 @@ def __repr__(self): @contextlib.contextmanager def in_html_tag(self, tag_name: str, **attributes: Any): - """Will wrap the content in hatml tags with tag name. + """Will wrap the content in html tags with tag name. Examples: with node.in_html_tag("div", **{"class": "css_class"}): diff --git a/mknodes/info/folderinfo.py b/mknodes/info/folderinfo.py index 613336d5..9c455706 100644 --- a/mknodes/info/folderinfo.py +++ b/mknodes/info/folderinfo.py @@ -8,6 +8,8 @@ import re import types +from typing import TYPE_CHECKING + from griffe import Module from griffe.enumerations import Parser from griffe.loader import GriffeLoader @@ -25,6 +27,9 @@ from mknodes.utils import log, packagehelpers, pathhelpers, reprhelpers, yamlhelpers +if TYPE_CHECKING: + from mknodes.info import packageinfo + logger = log.get_logger(__name__) @@ -119,7 +124,7 @@ def clone_from( return kls @functools.cached_property - def info(self): + def info(self) -> packageinfo.PackageInfo: """Return a PackageInfo object for given distribution.""" return packageregistry.get_info(self.pyproject.name or self.git.repo_name) @@ -182,7 +187,7 @@ def tools(self) -> list[tools.Tool]: return [instance for t in tools.TOOLS.values() if (instance := t(self)).used] @functools.cached_property - def docstring_style(self): + def docstring_style(self) -> str | None: """Return docstring style (google / numpy).""" if style := self.pyproject.docstring_style: return style @@ -271,7 +276,7 @@ def context(self): required_package_names=self.info.required_package_names, extras=self.info.extras, tools=self.tools, - entry_points=self.info.get_entry_points(), + entry_points=self.info.entry_points, cli=self.info.cli, mkdocs_config=self.mkdocs_config, pyproject_file=self.pyproject, diff --git a/mknodes/info/packageinfo.py b/mknodes/info/packageinfo.py index f24180ec..934f1535 100644 --- a/mknodes/info/packageinfo.py +++ b/mknodes/info/packageinfo.py @@ -195,21 +195,18 @@ def _get_dep_info(self, name: str) -> packagehelpers.Dependency: @functools.cached_property def cli(self) -> str | None: """Get the name of the CLI package being used.""" - eps = self.get_entry_points("console_scripts") + eps = self.entry_points.get("console_scripts") if not eps: return None - ep = eps["console_scripts"][0] + ep = eps[0] return "typer" if ep.obj.__class__.__qualname__ == "Typer" else "click" - def get_entry_points( - self, - group: str | None = None, - ) -> dict[str, list[packagehelpers.EntryPoint]]: + @functools.cached_property + def entry_points(self) -> dict[str, list[packagehelpers.EntryPoint]]: """Get entry points for this package.""" - return packagehelpers.get_entry_points(self.distribution, group=group) + return packagehelpers.get_entry_points(self.distribution) if __name__ == "__main__": info = PackageInfo("mknodes") - print(info.get_entry_points("mkdocs.plugins")) print(info.cli) diff --git a/mknodes/project.py b/mknodes/project.py index 3f699e97..c6b1befc 100644 --- a/mknodes/project.py +++ b/mknodes/project.py @@ -81,7 +81,6 @@ def __init__( theme=self.theme.context, links=self.linkprovider, env=self.env, - # requirements=self.get_requirements(), ) self._root: mknav.MkNav | None = None diff --git a/mknodes/utils/packagehelpers.py b/mknodes/utils/packagehelpers.py index 36961729..8581096f 100644 --- a/mknodes/utils/packagehelpers.py +++ b/mknodes/utils/packagehelpers.py @@ -114,12 +114,8 @@ def get_entry_points( else: mod_name, kls_name = ep.value, None mod = importlib.import_module(mod_name) - ep = EntryPoint( - name=ep.name, - dotted_path=ep.value, - group=ep.group, - obj=getattr(mod, kls_name) if kls_name else mod, - ) + obj = getattr(mod, kls_name) if kls_name else mod + ep = EntryPoint(name=ep.name, dotted_path=ep.value, group=ep.group, obj=obj) dct[ep.group].append(ep) return dct