Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Sep 27, 2023
1 parent 936e824 commit 04162da
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 26 deletions.
13 changes: 5 additions & 8 deletions mknodes/basenodes/mkcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"}):
Expand Down
11 changes: 8 additions & 3 deletions mknodes/info/folderinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions mknodes/info/packageinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion mknodes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions mknodes/utils/packagehelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 04162da

Please sign in to comment.