Skip to content

MkInstallGuide

Show source on GitHub

Node to display an install guide.

Example: Regular

Jinja

{{ mk.MkInstallGuide() }}

Python

MkInstallGuide()

pip

The latest released version is available at the Python package index.

pip install mknodes

pipx

pipx allows for the global installation of Python applications in isolated environments.

pipx install mknodes
### pip

The latest released version is available at the [Python package index](https://pypi.org/project/mknodes).

```` {.python }
pip install mknodes
````
### pipx

[pipx](https://github.com/pypa/pipx) allows for the global installation of Python applications in isolated environments.

```` {.python }
pipx install mknodes
````

Example: Explicit

Jinja

{{ "mkdocs" | MkInstallGuide(package_repos=["pip", "pipx"]) }}

Python

MkInstallGuide('mkdocs', package_repos=['pip', 'pipx'])

pip

The latest released version is available at the Python package index.

pip install mkdocs

pipx

pipx allows for the global installation of Python applications in isolated environments.

pipx install mkdocs
### pip

The latest released version is available at the [Python package index](https://pypi.org/project/mkdocs).

```` {.python }
pip install mkdocs
````
### pipx

[pipx](https://github.com/pypa/pipx) allows for the global installation of Python applications in isolated environments.

```` {.python }
pipx install mkdocs
````
<h3 id="pip">pip</h3>
<p>The latest released version is available at the <a href="https://pypi.org/project/mkdocs">Python package index</a>.</p>
<div class="language-python highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="n">pip</span> <span class="n">install</span> <span class="n">mkdocs</span>
</span></code></pre></div>
<h3 id="pipx">pipx</h3>
<p><a href="https://github.com/pypa/pipx">pipx</a> allows for the global installation of Python applications in isolated environments.</p>
<div class="language-python highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="n">pipx</span> <span class="n">install</span> <span class="n">mkdocs</span>
</span></code></pre></div>
MkInstallGuide
├── MkHeader('pip', level=3)
├── MkCode('pip install mkdocs')
│   ╰── MkText('pip install mkdocs')
├── MkHeader('pipx', level=3)
╰── MkCode('pipx install mkdocs')
    ╰── MkText('pipx install mkdocs')

Bases: MkTemplate

__init__

__init__(
    distribution: str | None = None,
    *,
    package_repos: list[InstallMethodStr] | None = None,
    header_level: int = 3,
    **kwargs: Any
)

Parameters:

Name Type Description Default
distribution str | None

name of the distribution to install

None
package_repos list[InstallMethodStr] | None

package repositories the project is available on

None
header_level int

Header level for each section

3
kwargs Any

Keyword arguments passed to parent

{}
graph TD
  94721312453024["mkinstallguide.MkInstallGuide"]
  94721308869584["mktemplate.MkTemplate"]
  94721311697232["mkcontainer.MkContainer"]
  94721308848336["mknode.MkNode"]
  94721311766592["node.Node"]
  140564252373184["builtins.object"]
  94721308869584 --> 94721312453024
  94721311697232 --> 94721308869584
  94721308848336 --> 94721311697232
  94721311766592 --> 94721308848336
  140564252373184 --> 94721311766592
/home/runner/work/mknodes/mknodes/mknodes/templatenodes/mkinstallguide/metadata.toml
[metadata]
name = "MkInstallGuide"
icon = "mdi:help"
group = "documentation"
virtual_children = true

[examples.regular]
title = "Regular"
jinja = """
{{ mk.MkInstallGuide() }}
"""

[examples.explicit]
title = "Explicit"
jinja = """
{{ "mkdocs" | MkInstallGuide(package_repos=["pip", "pipx"]) }}
"""

[output.markdown]
template = """
{% for method in node.package_repos %}
{{ method.ID | MkHeader(level=node.header_level) }}

{{ method.info_text() }}

{{ method.install_instructions() | MkCode }}
{% endfor %}
"""

# proj = self.associated_distribution
# if method.ID == "pip" and proj and (extras := proj.info.extras):
#     extras_str = ",".join(extras)
#     text = f"{method.install_instructions()}[{extras_str}]"
#     code = mkcode.MkCode(text)
#     items.append(code)
mknodes.templatenodes.mkinstallguide.MkInstallGuide
class MkInstallGuide(mktemplate.MkTemplate):
    """Node to display an install guide."""

    ICON = "material/help"
    VIRTUAL_CHILDREN = True

    def __init__(
        self,
        distribution: str | None = None,
        *,
        package_repos: list[installmethods.InstallMethodStr] | None = None,
        header_level: int = 3,
        **kwargs: Any,
    ):
        """Constructor.

        Args:
            distribution: name of the distribution to install
            package_repos: package repositories the project is available on
            header_level: Header level for each section
            kwargs: Keyword arguments passed to parent
        """
        super().__init__("output/markdown/template", **kwargs)
        self._distribution = distribution
        self.header_level = header_level
        self._package_repos = package_repos

    @property
    def package_repos(self) -> list[installmethods.InstallMethod]:
        if self._package_repos:
            return [
                installmethods.InstallMethod.by_id(i)(self.distribution)
                for i in self._package_repos
            ]
        return self.ctx.metadata.package_repos or []

    @property
    def distribution(self):
        return self._distribution or self.ctx.metadata.distribution_name

    @distribution.setter
    def distribution(self, value):
        self._distribution = value