Skip to content

MkPipDepTree

Show source on GitHub

Node to display a mermaid diagram for the dependencies.

Example: Regular

Jinja

{{ "jinja2" | MkPipDepTree }}

Python

MkPipDepTree('jinja2')
graph TD
    classDef missing stroke-dasharray: 5
    jinja2["Jinja2\n3.1.2"]
    markupsafe["MarkupSafe\n2.1.3"]
    jinja2 -- ">=2.0" --> markupsafe
```` mermaid
graph TD
    classDef missing stroke-dasharray: 5
    jinja2["Jinja2\n3.1.2"]
    markupsafe["MarkupSafe\n2.1.3"]
    jinja2 -- ">=2.0" --> markupsafe
````
<pre class="mermaid"><code>graph TD
    classDef missing stroke-dasharray: 5
    jinja2["Jinja2\n3.1.2"]
    markupsafe["MarkupSafe\n2.1.3"]
    jinja2 -- "&gt;=2.0" --&gt; markupsafe</code></pre>

Bases: MkDiagram

__init__

__init__(
    package: types.ModuleType | str | None = None,
    *,
    direction: Literal["TD", "DT", "LR", "RL"] = "TD",
    local_only: bool = False,
    user_only: bool = False,
    include_editables: bool = True,
    editables_only: bool = False,
    **kwargs: Any
)

Parameters:

Name Type Description Default
package ModuleType | str | None

Package to show a dependency diagram for

None
direction Literal['TD', 'DT', 'LR', 'RL']

diagram direction

'TD'
local_only bool

Show ony local packages

False
user_only bool

Show only user packages

False
include_editables bool

Whether to include editable installs

True
editables_only bool

Only return editable installs

False
kwargs Any

Keyword arguments passed to parent

{}
Name Children Inherits
MkDiagram
mknodes.basenodes.mkdiagram
Class representing a mermaid diagram.
graph TD
  94854583661264["mkpipdeptree.MkPipDepTree"]
  94854574620240["mkdiagram.MkDiagram"]
  94854582908560["mkcode.MkCode"]
  94854582919984["mkcontainer.MkContainer"]
  94854582916880["mknode.MkNode"]
  94854582838576["node.Node"]
  140544995341632["builtins.object"]
  94854574620240 --> 94854583661264
  94854582908560 --> 94854574620240
  94854582919984 --> 94854582908560
  94854582916880 --> 94854582919984
  94854582838576 --> 94854582916880
  140544995341632 --> 94854582838576
/home/runner/work/mknodes/mknodes/mknodes/templatenodes/mkpipdeptree/metadata.toml
[metadata]
name = "MkPipDepTree"
icon = "mdi:dependency"
status = "new"
group = "documentation"

[requirements.package.pipdeptree]

[examples.regular]
title = "Regular"
jinja = """
{{ "jinja2" | MkPipDepTree }}
"""

# [examples.direction]
# title = "Directed"
# jinja = """
# {{ mk.MkPipDepTree(direction="LR") }}
# """

[output.markdown]
template = """
{{ node.fence_boundary }} mermaid
{{ node.text }}
{{ node.fence_boundary }}
"""
mknodes.templatenodes.mkpipdeptree.MkPipDepTree
class MkPipDepTree(mkdiagram.MkDiagram):
    """Node to display a mermaid diagram for the dependencies."""

    REQUIRED_PACKAGES = [resources.Package("pipdeptree")]
    ICON = "material/dependency"

    def __init__(
        self,
        package: types.ModuleType | str | None = None,
        *,
        direction: Literal["TD", "DT", "LR", "RL"] = "TD",
        local_only: bool = False,
        user_only: bool = False,
        include_editables: bool = True,
        editables_only: bool = False,
        **kwargs: Any,
    ):
        """Constructor.

        Arguments:
            package: Package to show a dependency diagram for
            direction: diagram direction
            local_only: Show ony local packages
            user_only: Show only user packages
            include_editables: Whether to include editable installs
            editables_only: Only return editable installs
            kwargs: Keyword arguments passed to parent
        """
        self._package = package
        self.local_only = local_only
        self.user_only = user_only
        self.include_editables = include_editables
        self.editables_only = editables_only
        super().__init__(direction=direction, **kwargs)

    @property
    def package(self) -> str:
        match self._package:
            case None:
                return self.ctx.metadata.distribution_name
            case types.ModuleType():
                return self._package.__name__
            case _:
                return self._package

    @property
    def mermaid_code(self) -> str:
        return get_mermaid(
            self.package,
            local_only=self.local_only,
            user_only=self.user_only,
            include_editables=self.include_editables,
            editables_only=self.editables_only,
        )