first commit to pypi
This commit is contained in:
parent
b0b07c9425
commit
307a436f4c
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2018 The Python Packaging Authority
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,5 @@
|
|||
# Nodestack
|
||||
|
||||
Nodestack is a library that allows user to build structured trees of datas.
|
||||
|
||||
Project is under active development. Have a look at the repository for usage. Feel free to push patches.
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,4 +1,4 @@
|
|||
# Sphinx build info version 1
|
||||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
|
||||
config: e4274c969fa060e752467936197fbf11
|
||||
config: 25a925c417429e586cc413008d5151c9
|
||||
tags: 645f666f9bcd5a90fca523b33c5a78b7
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Overview: module code — pynodes 0.1 documentation</title>
|
||||
<title>Overview: module code — nodestack 0.1 documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
|
||||
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=19f00094" />
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
|||
|
||||
|
||||
<a href="../index.html" class="icon icon-home">
|
||||
pynodes
|
||||
nodestack
|
||||
</a>
|
||||
<div role="search">
|
||||
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
|
||||
|
@ -49,7 +49,7 @@
|
|||
|
||||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||||
<a href="../index.html">pynodes</a>
|
||||
<a href="../index.html">nodestack</a>
|
||||
</nav>
|
||||
|
||||
<div class="wy-nav-content">
|
||||
|
@ -67,7 +67,7 @@
|
|||
<div itemprop="articleBody">
|
||||
|
||||
<h1>All modules for which code is available</h1>
|
||||
<ul><li><a href="pynodes.html">pynodes</a></li>
|
||||
<ul><li><a href="nodestack.html">nodestack</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -341,29 +341,7 @@
|
|||
|
||||
|
||||
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">"__main__"</span><span class="p">:</span>
|
||||
|
||||
<span class="c1"># while True:</span>
|
||||
<span class="c1"># master_node = Node.create_random_nodes(depth=3, type_='cmd')</span>
|
||||
<span class="c1"># node_list = [master_node, master_node.children[0],</span>
|
||||
<span class="c1"># master_node.children[0].children[0]]</span>
|
||||
<span class="c1"># random.shuffle(node_list)</span>
|
||||
<span class="c1"># print([n.name for n in node_list])</span>
|
||||
<span class="c1"># print(Node.check_lineage(node_list))</span>
|
||||
<span class="c1"># input('pause')</span>
|
||||
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">Node</span><span class="p">):</span>
|
||||
<span class="k">pass</span>
|
||||
|
||||
<span class="n">bob</span> <span class="o">=</span> <span class="n">Person</span><span class="p">(</span><span class="s1">'Bob'</span><span class="p">)</span>
|
||||
<span class="n">eve</span> <span class="o">=</span> <span class="n">Person</span><span class="p">(</span><span class="s1">'Eve'</span><span class="p">)</span>
|
||||
<span class="n">alice</span> <span class="o">=</span> <span class="n">Person</span><span class="p">(</span><span class="s1">'Alice'</span><span class="p">)</span>
|
||||
|
||||
<span class="c1"># Alice is parent of bob and eve</span>
|
||||
<span class="n">alice</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">bob</span><span class="p">)</span>
|
||||
<span class="n">alice</span><span class="o">.</span><span class="n">add_child</span><span class="p">(</span><span class="n">eve</span><span class="p">)</span>
|
||||
|
||||
<span class="n">alice</span><span class="o">.</span><span class="n">pretty_print</span><span class="p">(</span><span class="n">option</span> <span class="o">=</span> <span class="s1">'id'</span><span class="p">)</span>
|
||||
|
||||
<span class="nb">print</span><span class="p">(</span><span class="n">alice</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
API
|
||||
=====
|
||||
|
||||
**pynodes** is a Python library to manage Nodes classes.
|
||||
**nodestack** is a Python library to manage Nodes classes.
|
||||
A node is an object which is related to other nodes given a tree chart.
|
||||
|
||||
.. automodule:: pynodes
|
||||
.. automodule:: nodestack
|
||||
:members:
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
.. pynodes documentation master file, created by
|
||||
.. nodestack documentation master file, created by
|
||||
sphinx-quickstart on Sat Mar 30 18:38:12 2024.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to pynodes's documentation!
|
||||
===================================
|
||||
Welcome to nodestack's documentation!
|
||||
=====================================
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -22,18 +22,24 @@ Installation:
|
|||
-------------
|
||||
.. code-block:: console
|
||||
|
||||
(venv) $ git clone https://gitea.lutix.org/ftg/nodes.git
|
||||
(venv) $ git clone https://gitea.lutix.org/ftg/nodestack.git
|
||||
|
||||
Source code is hosted on my own instance of `gitea <https://gitea.lutix.org/ftg/nodes>`_.
|
||||
or
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
(venv) $ pip install nodestack
|
||||
|
||||
Source code is hosted on my own instance of `gitea <https://gitea.lutix.org/ftg/nodestack>`_.
|
||||
|
||||
Basic Usage:
|
||||
------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import pynodes
|
||||
import nodestack
|
||||
|
||||
class Person(pynodes.Node):
|
||||
class Person(nodestack.Node):
|
||||
pass
|
||||
|
||||
bob = Person('Bob')
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>API — pynodes 0.1 documentation</title>
|
||||
<title>API — nodestack 0.1 documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=80d5e7a1" />
|
||||
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
|||
<script src="_static/js/theme.js"></script>
|
||||
<link rel="index" title="Index" href="genindex.html" />
|
||||
<link rel="search" title="Search" href="search.html" />
|
||||
<link rel="prev" title="Welcome to pynodes’s documentation!" href="index.html" />
|
||||
<link rel="prev" title="Welcome to nodestack’s documentation!" href="index.html" />
|
||||
</head>
|
||||
|
||||
<body class="wy-body-for-nav">
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
|
||||
<a href="index.html" class="icon icon-home">
|
||||
pynodes
|
||||
nodestack
|
||||
</a>
|
||||
<div role="search">
|
||||
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||||
|
@ -43,23 +43,23 @@
|
|||
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
|
||||
<ul class="current">
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">API</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#pynodes.Node"><code class="docutils literal notranslate"><span class="pre">Node</span></code></a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.add_child"><code class="docutils literal notranslate"><span class="pre">Node.add_child()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.check_lineage"><code class="docutils literal notranslate"><span class="pre">Node.check_lineage()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.create_random_nodes"><code class="docutils literal notranslate"><span class="pre">Node.create_random_nodes()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.get_child"><code class="docutils literal notranslate"><span class="pre">Node.get_child()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.get_sibling"><code class="docutils literal notranslate"><span class="pre">Node.get_sibling()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.has_children"><code class="docutils literal notranslate"><span class="pre">Node.has_children()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.has_parent"><code class="docutils literal notranslate"><span class="pre">Node.has_parent()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.has_siblings"><code class="docutils literal notranslate"><span class="pre">Node.has_siblings()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.is_child"><code class="docutils literal notranslate"><span class="pre">Node.is_child()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.is_sibling"><code class="docutils literal notranslate"><span class="pre">Node.is_sibling()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.level"><code class="docutils literal notranslate"><span class="pre">Node.level</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.parents"><code class="docutils literal notranslate"><span class="pre">Node.parents</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.path"><code class="docutils literal notranslate"><span class="pre">Node.path</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.pretty_print"><code class="docutils literal notranslate"><span class="pre">Node.pretty_print()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.reset_stats"><code class="docutils literal notranslate"><span class="pre">Node.reset_stats()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#pynodes.Node.siblings"><code class="docutils literal notranslate"><span class="pre">Node.siblings</span></code></a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#nodestack.Node"><code class="docutils literal notranslate"><span class="pre">Node</span></code></a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.add_child"><code class="docutils literal notranslate"><span class="pre">Node.add_child()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.check_lineage"><code class="docutils literal notranslate"><span class="pre">Node.check_lineage()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.create_random_nodes"><code class="docutils literal notranslate"><span class="pre">Node.create_random_nodes()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.get_child"><code class="docutils literal notranslate"><span class="pre">Node.get_child()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.get_sibling"><code class="docutils literal notranslate"><span class="pre">Node.get_sibling()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.has_children"><code class="docutils literal notranslate"><span class="pre">Node.has_children()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.has_parent"><code class="docutils literal notranslate"><span class="pre">Node.has_parent()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.has_siblings"><code class="docutils literal notranslate"><span class="pre">Node.has_siblings()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.is_child"><code class="docutils literal notranslate"><span class="pre">Node.is_child()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.is_sibling"><code class="docutils literal notranslate"><span class="pre">Node.is_sibling()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.level"><code class="docutils literal notranslate"><span class="pre">Node.level</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.parents"><code class="docutils literal notranslate"><span class="pre">Node.parents</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.path"><code class="docutils literal notranslate"><span class="pre">Node.path</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.pretty_print"><code class="docutils literal notranslate"><span class="pre">Node.pretty_print()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.reset_stats"><code class="docutils literal notranslate"><span class="pre">Node.reset_stats()</span></code></a></li>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#nodestack.Node.siblings"><code class="docutils literal notranslate"><span class="pre">Node.siblings</span></code></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -72,7 +72,7 @@
|
|||
|
||||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||||
<a href="index.html">pynodes</a>
|
||||
<a href="index.html">nodestack</a>
|
||||
</nav>
|
||||
|
||||
<div class="wy-nav-content">
|
||||
|
@ -92,15 +92,15 @@
|
|||
|
||||
<section id="api">
|
||||
<h1>API<a class="headerlink" href="#api" title="Link to this heading">¶</a></h1>
|
||||
<p><strong>pynodes</strong> is a Python library to manage Nodes classes.
|
||||
<p><strong>nodestack</strong> is a Python library to manage Nodes classes.
|
||||
A node is an object which is related to other nodes given a tree chart.</p>
|
||||
<dl class="py class" id="module-pynodes">
|
||||
<dt class="sig sig-object py" id="pynodes.Node">
|
||||
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">pynodes.</span></span><span class="sig-name descname"><span class="pre">Node</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parent</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pynodes.html#Node"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node" title="Link to this definition">¶</a></dt>
|
||||
<dl class="py class" id="module-nodestack">
|
||||
<dt class="sig sig-object py" id="nodestack.Node">
|
||||
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">nodestack.</span></span><span class="sig-name descname"><span class="pre">Node</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">parent</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference internal" href="_modules/nodestack.html#Node"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Should be subclassed only</p>
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.add_child">
|
||||
<span class="sig-name descname"><span class="pre">add_child</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">child</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.add_child"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.add_child" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.add_child">
|
||||
<span class="sig-name descname"><span class="pre">add_child</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">child</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.add_child"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.add_child" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Add new child node to current instance</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
|
@ -110,8 +110,8 @@ A node is an object which is related to other nodes given a tree chart.</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.check_lineage">
|
||||
<em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">check_lineage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">nodes</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">list</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.check_lineage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.check_lineage" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.check_lineage">
|
||||
<em class="property"><span class="pre">static</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">check_lineage</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">nodes</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">list</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a><span class="p"><span class="pre">]</span></span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.check_lineage"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.check_lineage" title="Link to this definition">¶</a></dt>
|
||||
<dd><dl class="simple">
|
||||
<dt>check if the list of nodes is a straight lineage:</dt><dd><p>node 1 (ancestor) -> node 2 -> node 3 -> … -> node n (grand
|
||||
children)</p>
|
||||
|
@ -120,51 +120,51 @@ children)</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.create_random_nodes">
|
||||
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">create_random_nodes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">type_</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">'cmd'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">depth</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a></span></span><a class="reference internal" href="_modules/pynodes.html#Node.create_random_nodes"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.create_random_nodes" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.create_random_nodes">
|
||||
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">create_random_nodes</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">type_</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">'cmd'</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">depth</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a></span></span><a class="reference internal" href="_modules/nodestack.html#Node.create_random_nodes"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.create_random_nodes" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Creates random tree of nodes for testing purpose</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.get_child">
|
||||
<span class="sig-name descname"><span class="pre">get_child</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.get_child"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.get_child" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.get_child">
|
||||
<span class="sig-name descname"><span class="pre">get_child</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.get_child"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.get_child" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>find and returns a child with specified name. None if nothing found</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.get_sibling">
|
||||
<span class="sig-name descname"><span class="pre">get_sibling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.get_sibling"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.get_sibling" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.get_sibling">
|
||||
<span class="sig-name descname"><span class="pre">get_sibling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a><span class="w"> </span><span class="p"><span class="pre">|</span></span><span class="w"> </span><span class="pre">None</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.get_sibling"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.get_sibling" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>find and returns a sibling with specified name. None if nothing
|
||||
found</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.has_children">
|
||||
<span class="sig-name descname"><span class="pre">has_children</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.has_children"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.has_children" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.has_children">
|
||||
<span class="sig-name descname"><span class="pre">has_children</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.has_children"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.has_children" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>check if Node object has one child at least</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.has_parent">
|
||||
<span class="sig-name descname"><span class="pre">has_parent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.has_parent"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.has_parent" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.has_parent">
|
||||
<span class="sig-name descname"><span class="pre">has_parent</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.has_parent"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.has_parent" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>check if Node object has a parent or not</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.has_siblings">
|
||||
<span class="sig-name descname"><span class="pre">has_siblings</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.has_siblings"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.has_siblings" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.has_siblings">
|
||||
<span class="sig-name descname"><span class="pre">has_siblings</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.has_siblings"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.has_siblings" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>check if Node object has one sibling at least</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.is_child">
|
||||
<span class="sig-name descname"><span class="pre">is_child</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.is_child"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.is_child" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.is_child">
|
||||
<span class="sig-name descname"><span class="pre">is_child</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.is_child"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.is_child" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Check if Node object is a child of the other Node object</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.is_sibling">
|
||||
<span class="sig-name descname"><span class="pre">is_sibling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.is_sibling"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.is_sibling" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.is_sibling">
|
||||
<span class="sig-name descname"><span class="pre">is_sibling</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">bool</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.is_sibling"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.is_sibling" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Check if Node object is a sibling of the other Node object</p>
|
||||
<dl class="field-list simple">
|
||||
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
|
||||
|
@ -174,38 +174,38 @@ found</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.level">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">level</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">int</span></em><a class="headerlink" href="#pynodes.Node.level" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.level">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">level</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">int</span></em><a class="headerlink" href="#nodestack.Node.level" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Returns the level of the Node object</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.parents">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">parents</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">list</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#pynodes.Node.parents" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.parents">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">parents</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">list</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#nodestack.Node.parents" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Returns all the ancestors of the Node object</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.path">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">path</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">str</span></em><a class="headerlink" href="#pynodes.Node.path" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.path">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">path</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">str</span></em><a class="headerlink" href="#nodestack.Node.path" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Returns a representation of the ancestor lineage of self</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.pretty_print">
|
||||
<span class="sig-name descname"><span class="pre">pretty_print</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">option</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">'default'</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.pretty_print"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.pretty_print" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.pretty_print">
|
||||
<span class="sig-name descname"><span class="pre">pretty_print</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">option</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">str</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">'default'</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.pretty_print"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.pretty_print" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Print children tree from current instance</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py method">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.reset_stats">
|
||||
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">reset_stats</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/pynodes.html#Node.reset_stats"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#pynodes.Node.reset_stats" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.reset_stats">
|
||||
<em class="property"><span class="pre">classmethod</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">reset_stats</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">→</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="reference internal" href="_modules/nodestack.html#Node.reset_stats"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#nodestack.Node.reset_stats" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>reset all the ClassVar members</p>
|
||||
</dd></dl>
|
||||
|
||||
<dl class="py property">
|
||||
<dt class="sig sig-object py" id="pynodes.Node.siblings">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">siblings</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">list</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#pynodes.Node" title="pynodes.Node"><span class="pre">Node</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#pynodes.Node.siblings" title="Link to this definition">¶</a></dt>
|
||||
<dt class="sig sig-object py" id="nodestack.Node.siblings">
|
||||
<em class="property"><span class="pre">property</span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">siblings</span></span><em class="property"><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="pre">list</span><span class="p"><span class="pre">[</span></span><a class="reference internal" href="#nodestack.Node" title="nodestack.Node"><span class="pre">Node</span></a><span class="p"><span class="pre">]</span></span></em><a class="headerlink" href="#nodestack.Node.siblings" title="Link to this definition">¶</a></dt>
|
||||
<dd><p>Returns all the siblings of the Node object</p>
|
||||
</dd></dl>
|
||||
|
||||
|
@ -217,7 +217,7 @@ found</p>
|
|||
</div>
|
||||
</div>
|
||||
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
|
||||
<a href="index.html" class="btn btn-neutral float-left" title="Welcome to pynodes’s documentation!" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
||||
<a href="index.html" class="btn btn-neutral float-left" title="Welcome to nodestack’s documentation!" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Index — pynodes 0.1 documentation</title>
|
||||
<title>Index — nodestack 0.1 documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=80d5e7a1" />
|
||||
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
|||
|
||||
|
||||
<a href="index.html" class="icon icon-home">
|
||||
pynodes
|
||||
nodestack
|
||||
</a>
|
||||
<div role="search">
|
||||
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||||
|
@ -49,7 +49,7 @@
|
|||
|
||||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||||
<a href="index.html">pynodes</a>
|
||||
<a href="index.html">nodestack</a>
|
||||
</nav>
|
||||
|
||||
<div class="wy-nav-content">
|
||||
|
@ -86,7 +86,7 @@
|
|||
<h2 id="A">A</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.add_child">add_child() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.add_child">add_child() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -94,11 +94,11 @@
|
|||
<h2 id="C">C</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.check_lineage">check_lineage() (pynodes.Node static method)</a>
|
||||
<li><a href="api.html#nodestack.Node.check_lineage">check_lineage() (nodestack.Node static method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.create_random_nodes">create_random_nodes() (pynodes.Node class method)</a>
|
||||
<li><a href="api.html#nodestack.Node.create_random_nodes">create_random_nodes() (nodestack.Node class method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -106,11 +106,11 @@
|
|||
<h2 id="G">G</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.get_child">get_child() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.get_child">get_child() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.get_sibling">get_sibling() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.get_sibling">get_sibling() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -118,13 +118,13 @@
|
|||
<h2 id="H">H</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.has_children">has_children() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.has_children">has_children() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.has_parent">has_parent() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.has_parent">has_parent() (nodestack.Node method)</a>
|
||||
</li>
|
||||
<li><a href="api.html#pynodes.Node.has_siblings">has_siblings() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.has_siblings">has_siblings() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -132,11 +132,11 @@
|
|||
<h2 id="I">I</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.is_child">is_child() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.is_child">is_child() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.is_sibling">is_sibling() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.is_sibling">is_sibling() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -144,7 +144,7 @@
|
|||
<h2 id="L">L</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.level">level (pynodes.Node property)</a>
|
||||
<li><a href="api.html#nodestack.Node.level">level (nodestack.Node property)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -156,7 +156,7 @@
|
|||
module
|
||||
|
||||
<ul>
|
||||
<li><a href="api.html#module-pynodes">pynodes</a>
|
||||
<li><a href="api.html#module-nodestack">nodestack</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
</ul></td>
|
||||
|
@ -165,36 +165,38 @@
|
|||
<h2 id="N">N</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node">Node (class in pynodes)</a>
|
||||
<li><a href="api.html#nodestack.Node">Node (class in nodestack)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li>
|
||||
nodestack
|
||||
|
||||
<ul>
|
||||
<li><a href="api.html#module-nodestack">module</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
||||
<h2 id="P">P</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.parents">parents (pynodes.Node property)</a>
|
||||
</li>
|
||||
<li><a href="api.html#pynodes.Node.path">path (pynodes.Node property)</a>
|
||||
<li><a href="api.html#nodestack.Node.parents">parents (nodestack.Node property)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.pretty_print">pretty_print() (pynodes.Node method)</a>
|
||||
<li><a href="api.html#nodestack.Node.path">path (nodestack.Node property)</a>
|
||||
</li>
|
||||
<li>
|
||||
pynodes
|
||||
|
||||
<ul>
|
||||
<li><a href="api.html#module-pynodes">module</a>
|
||||
<li><a href="api.html#nodestack.Node.pretty_print">pretty_print() (nodestack.Node method)</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
||||
<h2 id="R">R</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.reset_stats">reset_stats() (pynodes.Node class method)</a>
|
||||
<li><a href="api.html#nodestack.Node.reset_stats">reset_stats() (nodestack.Node class method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -202,7 +204,7 @@
|
|||
<h2 id="S">S</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="api.html#pynodes.Node.siblings">siblings (pynodes.Node property)</a>
|
||||
<li><a href="api.html#nodestack.Node.siblings">siblings (nodestack.Node property)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Welcome to pynodes’s documentation! — pynodes 0.1 documentation</title>
|
||||
<title>Welcome to nodestack’s documentation! — nodestack 0.1 documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=80d5e7a1" />
|
||||
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
|
||||
|
||||
|
@ -31,7 +31,7 @@
|
|||
|
||||
|
||||
<a href="#" class="icon icon-home">
|
||||
pynodes
|
||||
nodestack
|
||||
</a>
|
||||
<div role="search">
|
||||
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||||
|
@ -51,7 +51,7 @@
|
|||
|
||||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||||
<a href="#">pynodes</a>
|
||||
<a href="#">nodestack</a>
|
||||
</nav>
|
||||
|
||||
<div class="wy-nav-content">
|
||||
|
@ -59,7 +59,7 @@
|
|||
<div role="navigation" aria-label="Page navigation">
|
||||
<ul class="wy-breadcrumbs">
|
||||
<li><a href="#" class="icon icon-home" aria-label="Home"></a></li>
|
||||
<li class="breadcrumb-item active">Welcome to pynodes’s documentation!</li>
|
||||
<li class="breadcrumb-item active">Welcome to nodestack’s documentation!</li>
|
||||
<li class="wy-breadcrumbs-aside">
|
||||
<a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
|
||||
</li>
|
||||
|
@ -69,8 +69,8 @@
|
|||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||||
<div itemprop="articleBody">
|
||||
|
||||
<section id="welcome-to-pynodes-s-documentation">
|
||||
<h1>Welcome to pynodes’s documentation!<a class="headerlink" href="#welcome-to-pynodes-s-documentation" title="Link to this heading">¶</a></h1>
|
||||
<section id="welcome-to-nodestack-s-documentation">
|
||||
<h1>Welcome to nodestack’s documentation!<a class="headerlink" href="#welcome-to-nodestack-s-documentation" title="Link to this heading">¶</a></h1>
|
||||
<div class="admonition note">
|
||||
<p class="admonition-title">Note</p>
|
||||
<p>This project is under active development.</p>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<div class="toctree-wrapper compound">
|
||||
<ul>
|
||||
<li class="toctree-l1"><a class="reference internal" href="api.html">API</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#pynodes.Node"><code class="docutils literal notranslate"><span class="pre">Node</span></code></a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="api.html#nodestack.Node"><code class="docutils literal notranslate"><span class="pre">Node</span></code></a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -88,16 +88,20 @@
|
|||
</section>
|
||||
<section id="installation">
|
||||
<h2>Installation:<a class="headerlink" href="#installation" title="Link to this heading">¶</a></h2>
|
||||
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span>git<span class="w"> </span>clone<span class="w"> </span>https://gitea.lutix.org/ftg/nodes.git
|
||||
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span>git<span class="w"> </span>clone<span class="w"> </span>https://gitea.lutix.org/ftg/nodestack.git
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Source code is hosted on my own instance of <a class="reference external" href="https://gitea.lutix.org/ftg/nodes">gitea</a>.</p>
|
||||
<p>or</p>
|
||||
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp gp-VirtualEnv">(venv)</span> <span class="gp">$ </span>pip<span class="w"> </span>install<span class="w"> </span>nodestack
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Source code is hosted on my own instance of <a class="reference external" href="https://gitea.lutix.org/ftg/nodestack">gitea</a>.</p>
|
||||
</section>
|
||||
<section id="basic-usage">
|
||||
<h2>Basic Usage:<a class="headerlink" href="#basic-usage" title="Link to this heading">¶</a></h2>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">pynodes</span>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">nodestack</span>
|
||||
|
||||
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">pynodes</span><span class="o">.</span><span class="n">Node</span><span class="p">):</span>
|
||||
<span class="k">class</span> <span class="nc">Person</span><span class="p">(</span><span class="n">nodestack</span><span class="o">.</span><span class="n">Node</span><span class="p">):</span>
|
||||
<span class="k">pass</span>
|
||||
|
||||
<span class="n">bob</span> <span class="o">=</span> <span class="n">Person</span><span class="p">(</span><span class="s1">'Bob'</span><span class="p">)</span>
|
||||
|
|
Binary file not shown.
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Python Module Index — pynodes 0.1 documentation</title>
|
||||
<title>Python Module Index — nodestack 0.1 documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=80d5e7a1" />
|
||||
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
|
||||
|
||||
|
@ -36,7 +36,7 @@
|
|||
|
||||
|
||||
<a href="index.html" class="icon icon-home">
|
||||
pynodes
|
||||
nodestack
|
||||
</a>
|
||||
<div role="search">
|
||||
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||||
|
@ -56,7 +56,7 @@
|
|||
|
||||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||||
<a href="index.html">pynodes</a>
|
||||
<a href="index.html">nodestack</a>
|
||||
</nav>
|
||||
|
||||
<div class="wy-nav-content">
|
||||
|
@ -77,17 +77,17 @@
|
|||
<h1>Python Module Index</h1>
|
||||
|
||||
<div class="modindex-jumpbox">
|
||||
<a href="#cap-p"><strong>p</strong></a>
|
||||
<a href="#cap-n"><strong>n</strong></a>
|
||||
</div>
|
||||
|
||||
<table class="indextable modindextable">
|
||||
<tr class="pcap"><td></td><td> </td><td></td></tr>
|
||||
<tr class="cap" id="cap-p"><td></td><td>
|
||||
<strong>p</strong></td><td></td></tr>
|
||||
<tr class="cap" id="cap-n"><td></td><td>
|
||||
<strong>n</strong></td><td></td></tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td>
|
||||
<a href="api.html#module-pynodes"><code class="xref">pynodes</code></a></td><td>
|
||||
<a href="api.html#module-nodestack"><code class="xref">nodestack</code></a></td><td>
|
||||
<em></em></td></tr>
|
||||
</table>
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Search — pynodes 0.1 documentation</title>
|
||||
<title>Search — nodestack 0.1 documentation</title>
|
||||
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=80d5e7a1" />
|
||||
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=19f00094" />
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
|||
|
||||
|
||||
<a href="index.html" class="icon icon-home">
|
||||
pynodes
|
||||
nodestack
|
||||
</a>
|
||||
<div role="search">
|
||||
<form id="rtd-search-form" class="wy-form" action="#" method="get">
|
||||
|
@ -52,7 +52,7 @@
|
|||
|
||||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
|
||||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||||
<a href="index.html">pynodes</a>
|
||||
<a href="index.html">nodestack</a>
|
||||
</nav>
|
||||
|
||||
<div class="wy-nav-content">
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,8 +1,8 @@
|
|||
API
|
||||
=====
|
||||
|
||||
**pynodes** is a Python library to manage Nodes classes.
|
||||
**nodestack** is a Python library to manage Nodes classes.
|
||||
A node is an object which is related to other nodes given a tree chart.
|
||||
|
||||
.. automodule:: pynodes
|
||||
.. automodule:: nodestack
|
||||
:members:
|
||||
|
|
|
@ -13,13 +13,13 @@
|
|||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('../..'))
|
||||
import pynodes
|
||||
import nodestack
|
||||
import sphinx_rtd_theme
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
project = 'pynodes'
|
||||
project = 'nodestack'
|
||||
copyright = '2024, fabthegreat'
|
||||
author = 'fabthegreat'
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
.. pynodes documentation master file, created by
|
||||
.. nodestack documentation master file, created by
|
||||
sphinx-quickstart on Sat Mar 30 18:38:12 2024.
|
||||
You can adapt this file completely to your liking, but it should at least
|
||||
contain the root `toctree` directive.
|
||||
|
||||
Welcome to pynodes's documentation!
|
||||
===================================
|
||||
Welcome to nodestack's documentation!
|
||||
=====================================
|
||||
|
||||
.. note::
|
||||
|
||||
|
@ -22,18 +22,24 @@ Installation:
|
|||
-------------
|
||||
.. code-block:: console
|
||||
|
||||
(venv) $ git clone https://gitea.lutix.org/ftg/nodes.git
|
||||
(venv) $ git clone https://gitea.lutix.org/ftg/nodestack.git
|
||||
|
||||
Source code is hosted on my own instance of `gitea <https://gitea.lutix.org/ftg/nodes>`_.
|
||||
or
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
(venv) $ pip install nodestack
|
||||
|
||||
Source code is hosted on my own instance of `gitea <https://gitea.lutix.org/ftg/nodestack>`_.
|
||||
|
||||
Basic Usage:
|
||||
------------
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import pynodes
|
||||
import nodestack
|
||||
|
||||
class Person(pynodes.Node):
|
||||
class Person(nodestack.Node):
|
||||
pass
|
||||
|
||||
bob = Person('Bob')
|
||||
|
|
235
pynodes.py
235
pynodes.py
|
@ -1,235 +0,0 @@
|
|||
from __future__ import annotations # for Class forward reference
|
||||
import random
|
||||
import uuid
|
||||
|
||||
from typing import ClassVar
|
||||
|
||||
class Node:
|
||||
"""
|
||||
Should be subclassed only
|
||||
"""
|
||||
# Class Var for statistics
|
||||
deepest_level: ClassVar[int] = 0
|
||||
largest_sibling_number: ClassVar[int] = 0
|
||||
all_nodes: ClassVar[list[Node]] = []
|
||||
|
||||
def __init_subclass__(cls):
|
||||
""" each subclass must define its own ClassVar """
|
||||
# TODO to be renamed for clarity
|
||||
super().__init_subclass__()
|
||||
cls.deepest_level: ClassVar[int] = 0
|
||||
cls.largest_sibling_number: ClassVar[int] = 0
|
||||
cls.all_nodes: ClassVar[list[Node]] = []
|
||||
return cls
|
||||
|
||||
def __new__(cls, name: str, parent: Node | None = None) -> None:
|
||||
"""
|
||||
prevent the user to set the same name for 2 nodes
|
||||
??? better to do it with uuid?
|
||||
"""
|
||||
for n in cls.all_nodes:
|
||||
if name == n.name:
|
||||
raise AttributeError('Node with this name already exists')
|
||||
else:
|
||||
return super().__new__(cls)
|
||||
|
||||
def __init__(self, name: str, parent: Node | None = None) -> None:
|
||||
self.name = name
|
||||
self.parent = parent # is set with add_child
|
||||
self.children: list[Node] = []
|
||||
self.id = uuid.uuid4()
|
||||
type(self).all_nodes.append(self)
|
||||
|
||||
def add_child(self, child: Node) -> None:
|
||||
"""
|
||||
Add new child node to current instance
|
||||
|
||||
:param child: Node object
|
||||
"""
|
||||
child.parent = self
|
||||
if child.name not in [c.name for c in self.children]:
|
||||
self.children.append(child)
|
||||
if child.level > type(self).deepest_level:
|
||||
type(self).deepest_level = child.level
|
||||
if len(self.children) > type(self).largest_sibling_number:
|
||||
type(self).largest_sibling_number = len(self.children)
|
||||
else:
|
||||
raise Exception('Child with same name already exists')
|
||||
|
||||
@property
|
||||
def siblings(self) -> list[Node]:
|
||||
"""
|
||||
Returns all the siblings of the Node object
|
||||
"""
|
||||
if self.has_siblings():
|
||||
return self.parent.children
|
||||
|
||||
@property
|
||||
def parents(self) -> list[Node]:
|
||||
"""
|
||||
Returns all the ancestors of the Node object
|
||||
"""
|
||||
parents = []
|
||||
p = self
|
||||
while p.has_parent():
|
||||
p = p.parent
|
||||
parents.append(p)
|
||||
return parents
|
||||
|
||||
@property
|
||||
def level(self) -> int:
|
||||
"""
|
||||
Returns the level of the Node object
|
||||
"""
|
||||
level = 0
|
||||
p = self
|
||||
while p.has_parent():
|
||||
level += 1
|
||||
p = p.parent
|
||||
return level
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
"""
|
||||
Returns a representation of the ancestor lineage of self
|
||||
"""
|
||||
path = ''
|
||||
for p in reversed(self.parents):
|
||||
path += p.name+'.'
|
||||
path += self.name
|
||||
return path
|
||||
|
||||
def is_sibling(self, other: str) -> bool:
|
||||
"""
|
||||
Check if Node object is a sibling of the other Node object
|
||||
|
||||
:param other: Other Node object to be compared with
|
||||
"""
|
||||
if other in [s.name for s in self.siblings]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def is_child(self, other: str) -> bool:
|
||||
"""
|
||||
Check if Node object is a child of the other Node object
|
||||
"""
|
||||
if other in [s.name for s in self.children]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def pretty_print(self, option: str = 'default') -> None:
|
||||
"""
|
||||
Print children tree from current instance
|
||||
"""
|
||||
dashes = ' '*self.level+'|'+'--'*self.level+' '
|
||||
if option == 'id':
|
||||
dashes += f'[{self.id}] '
|
||||
print(f'{dashes}{self.name}')
|
||||
for c in self.children:
|
||||
c.pretty_print(option)
|
||||
|
||||
def has_parent(self) -> bool:
|
||||
""" check if Node object has a parent or not """
|
||||
if self.parent is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
def has_children(self) -> bool:
|
||||
""" check if Node object has one child at least """
|
||||
if self.children is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
def has_siblings(self) -> bool:
|
||||
""" check if Node object has one sibling at least """
|
||||
if self.has_parent() and self.parent.has_children() \
|
||||
and len(self.parent.children) > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_child(self, name: str) -> Node | None:
|
||||
""" find and returns a child with specified name. None if nothing found """
|
||||
for c in self.children:
|
||||
if c.name == name:
|
||||
return c
|
||||
return None
|
||||
|
||||
def get_sibling(self, name: str) -> Node | None:
|
||||
""" find and returns a sibling with specified name. None if nothing
|
||||
found """
|
||||
for c in self.siblings:
|
||||
if c.name == name:
|
||||
return c
|
||||
return None
|
||||
|
||||
def get_children(self, name: str) -> list[Node]:
|
||||
# refactoring, recursion is not good
|
||||
results = []
|
||||
if self.name == name:
|
||||
results.append(self)
|
||||
for c in self.children:
|
||||
results += c.get_children(name)
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
def check_lineage(nodes: list[Node]) -> bool:
|
||||
"""
|
||||
check if the list of nodes is a straight lineage:
|
||||
node 1 (ancestor) -> node 2 -> node 3 -> ... -> node n (grand
|
||||
children)
|
||||
|
||||
"""
|
||||
for i in range(1, len(nodes)):
|
||||
if nodes[i].parent != nodes[i-1]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def reset_stats(cls) -> None:
|
||||
"""
|
||||
reset all the ClassVar members
|
||||
"""
|
||||
cls.deepest_level = 0
|
||||
cls.largest_sibling_number = 0
|
||||
cls.all_nodes = []
|
||||
|
||||
@classmethod
|
||||
def create_random_nodes(cls, type_: str = 'cmd', depth: int = 0) -> Node:
|
||||
"""
|
||||
Creates random tree of nodes for testing purpose
|
||||
"""
|
||||
def create_node(level, i):
|
||||
id_ = len(cls.all_nodes) + 1
|
||||
return cls(f'{type_}_'+str(id_))
|
||||
def create_node_list(level: int, width: int = 5):
|
||||
return [create_node(level, i)
|
||||
for i in range(random.randint(1, width))]
|
||||
def create_arg_tree(arg: cls):
|
||||
if arg.level < depth:
|
||||
for a in create_node_list(arg.level):
|
||||
arg.add_child(a)
|
||||
create_arg_tree(a)
|
||||
return arg
|
||||
arg = cls('parser')
|
||||
return create_arg_tree(arg)
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.level < other.level
|
||||
|
||||
def __gt__(self, other):
|
||||
return self.level > other.level
|
||||
|
||||
def __le__(self, other):
|
||||
return self.level <= other.level
|
||||
|
||||
def __ge__(self, other):
|
||||
return self.level >= other.level
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.name
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
|
@ -0,0 +1,25 @@
|
|||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[tool.hatch.build]
|
||||
exclude = ["venv"]
|
||||
|
||||
[project]
|
||||
name = "nodestack"
|
||||
version = "0.0.1"
|
||||
authors = [
|
||||
{ name="fabthegreat", email="nodestack@lutix.org" },
|
||||
]
|
||||
description = "A simple tree objects library"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.8"
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://gitea.lutix.org/ftg/nodestack"
|
||||
Issues = "https://gitea.lutix.org/ftg/nodestack/issues"
|
Binary file not shown.
Loading…
Reference in New Issue