A quick node tour¶
def a_quick_tour(page: mk.MkPage) -> None:
This will be a quick, short random introduction of some of the nodes included in MkNodes. The selection of nodes is totally random, this should just provide a quick overview how to interact with the nodes.
Let the tour begin!
Our first MkNode is very clever. You just show him a node and he will tell you all you need to know about him. It’s MkDocStrings! Lets check what he knows about MkPage:
node = mk.MkDocStrings(mk.MkPage)
MkDocStrings sometimes really writes long stories, so we will put everything into a collapsed MkAdmonition box, so we dont need that much space:
admonition = mk.MkAdmonition(node, collapsible=True)
str(admonition)
Here is the result:
Info
MkDocStrings can even show information about himself. Very talented!
node = mk.MkDocStrings(mk.MkDocStrings)
admonition = mk.MkAdmonition(node, collapsible=True)
str(admonition)
Okay, that’s enough DocStrings for today. You can find more of MkDocStrings work on the node pages (he tells you something about every MkNode there) and in the Core API.
Another MkNode who is displaying his skills on the node pages is MkClassDiagram.
He’s a very talented painter. Perhaps he can draw us something about MkPage!
diagram = mk.MkClassDiagram(mk.MkPage)
str(diagram)
graph TD
1511245065["mkpage.MkPage"]
835538629["mkcontainer.MkContainer"]
1956333208["mkcontainer.MkContainerBase"]
1359323199["mknode.MkNode"]
2751680898["builtins.object"]
835538629 --> 1511245065
1956333208 --> 835538629
1359323199 --> 1956333208
2751680898 --> 1359323199
MkClassDiagram can draw different kind of graphs. The first picture MkClassDiagram has painted was about base classes. Lets check out the subclasses:
diagram = mk.MkClassDiagram(mk.MkPage, mode="subclasses")
str(diagram)
graph TD
1511245065["mkpage.MkPage"]
2403743895["mktemplatepage.MkTemplatePage"]
957393682["mkclasspage.MkClassPage"]
2767653079["mkmodulepage.MkModulePage"]
1511245065 --> 2403743895
2403743895 --> 957393682
2403743895 --> 2767653079
There are multiple talented drawers among the MkNodes. MkPipDepTree is known for his dependency drawings, we can ask him to draw a graph for one of our dependencies.
To not overboard him, lets pick a package without too many dependencies:
node_1 = mk.MkPipDepTree("gitpython", direction="LR")
str(node_1)
graph LR
classDef missing stroke-dasharray: 5
gitdb["gitdb<br/>4.0.12"]
gitpython["GitPython<br/>3.2.1"]
smmap["smmap<br/>5.0.3"]
gitdb -- ">=3.0.1,<6" --> smmap
gitpython -- ">=4.0.1,<5" --> gitdb
We now come to the last MkNode of our quick tour.
Let’s introduce MkMetadataBadges!
MkMetadataBadges just loves Badges. He creates them himself and doesnt rely on webservies.
node_2 = mk.MkMetadataBadges("classifiers", package="mkdocstrings")
str(node_2)
Looks neat, right?
This is also a good chance to explain how nodes can get their information
from the context. Let me explain:
If we instanciate MkNodes and dont add them to the tree, then the nodes are clueless. They dont know who they belong to.
To make them part of the tree, we either add them for example to a page
(like this: page += node)
or we pass them a parent on instantiation.
In this example, once we add MkMetadataBadges to the tree, that node knows that he should create badges for our very own package, mknodes, unless we explicitely tell him to do otherwise. It will become his new “default”.
You dont believe me? Let me show you:
node_3 = mk.MkMetadataBadges("websites", parent=page)
Now that node is connected. If we ask him to draw now, he will create website badges for mknodes!
str(node_3)
This mechanism is the same for many MkNodes. For example, our earlier guest
MkPipDepTree behaves the same. Once connected,
he will want to paint mknodes dependency graphs without us telling him to do so!
Interesting, right?
That’s it for a first quick look at the nodes. There are about 70 different ones available in this package. Some are exciting, some are boring. It’s no difference to humans.
Oh, and if you wonder how this tour was done: I got help from MkCommentedCode!
page += mk.MkCommentedCode(a_quick_tour, style="text", render_comments=True)
MkCommentedCode parses a function and separates comments from code. These chunks are displayed on a rotating basis then.
Before we end the tour, let’s take a look at the raw material. We can use the MkCode node for that.
page += mk.MkCode.for_object(a_quick_tour)
As you can see, we added the MkCode node to the page. It will be displayed right after the MkCommentedCode block. You will see it right below.
Oh, and render_comments=True renders the jinja2 expressions in the
comments above. The page itself is not rendered with Jinja, so the expressions
in the raw code below stay as they are.
That’s it. The rest of the nodes you need to check out yourself. Have fun!
4def a_quick_tour(page: mk.MkPage) -> None:
5 # This will be a quick, short random introduction of some of the nodes
6 # included in **MkNodes**.
7 # The selection of nodes is totally random, this should just provide a quick overview
8 # how to interact with the nodes.
9 #
10 # Let the tour begin!
11 #
12 # Our first [MkNode][mknodes.MkNode] is very clever. You just show him a node and he
13 # will tell you all you need to know about him.
14 # It's [MkDocStrings][mknodes.MkDocStrings]!
15 # Lets check what he knows about [MkPage][mknodes.MkPage]:
16 node = mk.MkDocStrings(mk.MkPage)
17 # [MkDocStrings][mknodes.MkDocStrings] sometimes really writes long stories,
18 # so we will put everything into
19 # a collapsed [MkAdmonition][mknodes.MkAdmonition] box,
20 # so we dont need that much space:
21 admonition = mk.MkAdmonition(node, collapsible=True)
22 str(admonition)
23 # Here is the result:
24 # {{ "mknodes.MkPage" | MkDocStrings | MkAdmonition(collapsible=True) }}
25
26 # [MkDocStrings][mknodes.MkDocStrings] can even show information about himself.
27 # Very talented!
28 node = mk.MkDocStrings(mk.MkDocStrings)
29 admonition = mk.MkAdmonition(node, collapsible=True)
30 str(admonition)
31 # {{ "mknodes.MkDocStrings" | MkDocStrings | MkAdmonition(collapsible=True)}}
32
33 # Okay, that's enough DocStrings for today. You can find more of
34 # [MkDocStrings][mknodes.MkDocStrings] work
35 # on the [node pages](<../The nodes/index.md>) (he tells you something about every
36 # [MkNode][mknodes.MkNode] there) and in the [Core API](<../Core API/index.md>).
37 #
38 # Another [MkNode][mknodes.MkNode] who is displaying his skills on the node pages is
39 # [MkClassDiagram][mknodes.MkClassDiagram].
40 #
41 # He's a very talented painter. Perhaps he can draw us something about
42 # [MkPage][mknodes.MkPage]!
43 #
44 diagram = mk.MkClassDiagram(mk.MkPage)
45 str(diagram)
46 # {{ "mknodes.MkPage" | MkClassDiagram }}
47
48 # [MkClassDiagram][mknodes.MkClassDiagram] can draw different kind of graphs.
49 # The first picture [MkClassDiagram][mknodes.MkClassDiagram] has painted was about
50 # base classes. Lets check out the subclasses:
51 diagram = mk.MkClassDiagram(mk.MkPage, mode="subclasses")
52 str(diagram)
53 # {{ "mknodes.MkPage" | MkClassDiagram(mode="subclasses") }}
54
55 # There are multiple talented drawers among the **MkNodes**.
56 # [MkPipDepTree][mknodes.MkPipDepTree] is known for his dependency drawings,
57 # we can ask him to draw a graph for one of our dependencies.
58 #
59 # To not overboard him, lets pick a package without too many dependencies:
60
61 node_1 = mk.MkPipDepTree("gitpython", direction="LR")
62 str(node_1)
63 # {{ "gitpython" | MkPipDepTree(direction="LR") }}
64
65 # We now come to the last [MkNode][mknodes.MkNode] of our quick tour.
66 #
67 # Let's introduce [MkMetadataBadges][mknodes.MkMetadataBadges]!
68 #
69 # [MkMetadataBadges][mknodes.MkMetadataBadges] just loves Badges. He creates them
70 # himself and doesnt rely on webservies.
71 node_2 = mk.MkMetadataBadges("classifiers", package="mkdocstrings")
72 str(node_2)
73 # {{ "classifiers" | MkMetadataBadges(package="mkdocstrings") }}
74
75 # Looks neat, right?
76 # This is also a good chance to explain how nodes can get their information
77 # from the context. Let me explain:
78 #
79 # If we instanciate **MkNodes** and dont add them to the tree,
80 # then the nodes are clueless. They dont know who they belong to.
81 #
82 # To make them part of the tree, we either add them for example to a page
83 #
84 # (like this: `page += node`)
85 #
86 # or we pass them a parent on instantiation.
87 #
88 # In this example, once we add [MkMetadataBadges][mknodes.MkMetadataBadges]
89 # to the tree, that node knows
90 # that he should create badges for our very own package, **mknodes**,
91 # unless we explicitely tell him to do otherwise. It will become his new "default".
92 #
93 # You dont believe me? Let me show you:
94 node_3 = mk.MkMetadataBadges("websites", parent=page)
95
96 # Now that node is connected. If we ask him to draw now, he will create website
97 # badges for **mknodes**!
98
99 str(node_3)
100 # {{ "websites" | MkMetadataBadges }}
101
102 # This mechanism is the same for many **MkNodes**. For example, our earlier guest
103 # [MkPipDepTree][mknodes.MkPipDepTree] behaves the same. Once connected,
104 # he will want to paint **mknodes** dependency graphs without us telling him to do so!
105 #
106 # Interesting, right?
107 #
108 # That's it for a first quick look at the nodes.
109 # There are about 70 different ones available in this package.
110 # Some are exciting, some are boring. It's no difference to humans.
111 #
112 # Oh, and if you wonder how this tour was done: I got help from
113 # [MkCommentedCode][mknodes.MkCommentedCode]!
114 #
115 page += mk.MkCommentedCode(a_quick_tour, style="text", render_comments=True)
116
117 # [MkCommentedCode][mknodes.MkCommentedCode] parses a function and separates comments
118 # from code. These chunks are displayed on a rotating basis then.
119 #
120 # Before we end the tour, let's take a look at the raw material.
121 # We can use the [MkCode][mknodes.MkCode] node for that.
122 #
123 page += mk.MkCode.for_object(a_quick_tour)
124 # As you can see, we added the [MkCode][mknodes.MkCode] node to the page.
125 # It will be displayed right after the [MkCommentedCode][mknodes.MkCommentedCode]
126 # block. You will see it right below.
127 #
128 # Oh, and `render_comments=True` renders the **jinja2** expressions in the
129 # comments above. The page itself is not rendered with Jinja, so the expressions
130 # in the raw code below stay as they are.
131 #
132 # That's it. The rest of the nodes you need to check out yourself. Have fun!
Page info
Code for this page
43@nav.route.page("A quick node tour", hide="toc", icon="ic:outline-tour")
44def _(page: mk.MkPage) -> None:
45 # Only the commented tour renders Jinja, the raw source at the end must stay as is.
46 page.metadata.render_macros = False
47 a_quick_tour(page)
Resources
Resources(css=[],
markdown_extensions={'pymdownx.highlight': {'anchor_linenums': True,
'line_spans': '__span',
'pygments_lang_class': True},
'pymdownx.superfences': {}},
plugins=[],
js=[],
assets=[],
packages=[])
Metadata
created:
source_filename: /home/runner/work/mknodes/mknodes/src/mknodes/manual/get_started_section.py
source_function: _
source_line_no: 43
hide:
- toc
icon: ic:outline-tour
render_macros: false
title: A quick node tour