Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/mar10/nutree
Browse files Browse the repository at this point in the history
  • Loading branch information
mar10 committed Sep 12, 2024
2 parents 3b9841a + 0a29306 commit bad700c
Show file tree
Hide file tree
Showing 46 changed files with 2,135 additions and 869 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Changelog

## 0.8.1 (unreleased)
## 0.9.1 (unreleased)

## 0.9.0 (2024-09-12)

- Add `Tree.build_random_tree()` (experimental).
- Add `GenericNodeData` as wrapper for `dict` data.
- Fixed #7 Tree.from_dict failing to recreate an arbitrary object tree with a mapper.

## 0.8.0 (2024-03-29)

- BREAKING: Drop Python 3.7 support (EoL 2023-06-27).
- `Tree.save()` accepts a `compression` argument that will enable compression.
`Tree.load()` can detect if the input file has a compression header and will
decompress automatically.
- New traversal methods `LEVEL_ORDER`, `LEVEL_ORDER_RTL`, `ZIGZAG`, `ZIGZAG_RTL`.
decompress transparently.
- New traversal methods `LEVEL_ORDER`, `LEVEL_ORDER_RTL`, `ZIGZAG`, `ZIGZAG_RTL`.
- New compact connector styles `'lines32c'`, `'round43c'`, ...
- Save as mermaid flow diagram.

Expand Down
8 changes: 3 additions & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ name = "pypi"

[dev-packages]
black = { version = "~=24.3", extras = ["jupyter"] }
# coverage = "*"
fabulist="*"
isort = "*"
# pylint = "*"
# TODO: remove this line:
# pytest-html = "!=3.2.0" # wait for https://github.com/pytest-dev/pytest-html/pull/583
pytest = "*"
pytest-cov = "*"
PyYAML = "*"
Expand All @@ -22,14 +21,13 @@ tox = "*"
twine = "*"
wheel = "*"
yabs = "*"
nutree = {path = ".",editable = true}
ipykernel = "*"
notebook = "*"
nutree = {path = ".",editable = true}

[packages]

[requires]
python_version = "3.12"

[pipenv]
# allow_prereleases = true
1,567 changes: 796 additions & 771 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Nodes can be plain strings or objects <br>
(De)Serialize to (compressed) JSON <br>
Save as Mermaid flow diagram <br>
Different traversal methods <br>
Generate random trees <br>
Fully type annotated <br>
Convert to RDF graph <br>
Typed child nodes <br>
Expand Down
24 changes: 15 additions & 9 deletions docs/sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

# General information about the project.
project = u'nutree'
copyright = u'2021-2023, <a href="https://wwwendt.de">Martin Wendt</a>'
copyright = u'2021-2024, <a href="https://wwwendt.de">Martin Wendt</a>'
author = u'Martin Wendt'

# The version info for the project you're documenting, acts as replacement for
Expand All @@ -130,19 +130,25 @@
#version = '1.0'
# The full version, including alpha/beta/rc tags.
#release = '1.0'
import pkg_resources
import importlib

try:
release = pkg_resources.get_distribution('nutree').version
# print( "release", release)
del pkg_resources
except pkg_resources.DistributionNotFound:
print('To build the documentation, The distribution information')
print('Has to be available. Either install the package into your')
# release = pkg_resources.get_distribution("nutree").version
release = importlib.metadata.version("nutree")
except importlib.metadata.PackageNotFoundError:
print("To build the documentation, The distribution information")
print("has to be available. Either install the package into your")
print('development environment or run "setup.py develop" to setup the')
print('metadata. A virtualenv is recommended!')
print("metadata. A virtualenv is recommended!")

print(f"sys.path: {sys.path}")
print(f"package_root: {package_root}")
for fn in os.listdir(package_root):
print("-", fn)
sys.exit(1)

del importlib.metadata

version = '.'.join(release.split('.')[:2])

# The language for content autogenerated by Sphinx. Refer to documentation
Expand Down
7 changes: 4 additions & 3 deletions docs/sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ nutree

$ pip install nutree

**Note:** Run ``pip install nutree[graph]`` instead, in order to install
additional graph support.
**Note:** Run ``pip install "nutree[graph]"`` or ``pip install "nutree[all]"``
instead, in order to install additional graph support.

::

Expand Down Expand Up @@ -96,8 +96,9 @@ Nutree Facts
* :ref:`(De)Serialize to (compressed) JSON <serialize>`
* :ref:`Save as Mermaid flow diagram <save-mermaid>`
* :ref:`Different traversal methods <traversal>`
* :ref:`Fully type annotated <api-reference>`
* :ref:`Generate random trees <randomize>`
* :ref:`Convert to RDF graph <save-rdf>`
* :ref:`Fully type annotated <api-reference>`
* :ref:`Typed child nodes <typed-tree>`
* :ref:`Pretty print <pretty-print>`
* :ref:`Navigation <navigate>`
Expand Down
4 changes: 2 additions & 2 deletions docs/sphinx/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ Installation is straightforward::

$ pip install nutree

**Note:** Run ``pip install nutree[graph]`` instead, in order to install
additional graph support.
**Note:** Run ``pip install "nutree[graph]"`` or ``pip install "nutree[all]"``
instead, in order to install additional graph support.

Installing `nutree` and its dependencies into a 'sandbox' will help to keep
your system Python clean, but requires to activate the virtual environment::
Expand Down
10 changes: 9 additions & 1 deletion docs/sphinx/reference_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ Reference Guide
Class Overview
==============

Nutree Classes
--------------

.. inheritance-diagram:: nutree.tree nutree.node nutree.typed_tree nutree.common
:parts: 2
:private-bases:
:caption: nutree classes

Random Tree Generator
---------------------

.. inheritance-diagram:: nutree.tree_generator
:parts: 2


.. API
Expand Down
9 changes: 9 additions & 0 deletions docs/sphinx/rg_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ nutree.common module
:show-inheritance:
:inherited-members:

nutree.tree_generator module
----------------------------

.. automodule:: nutree.tree_generator
:members:
:undoc-members:
:show-inheritance:
:inherited-members:

10 changes: 8 additions & 2 deletions docs/sphinx/ug_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Basics

.. py:currentmodule:: nutree
.. admonition:: TL;DR

Nutree is a Python library for managing hierarchical data structures.
It stores arbitrary data objects in nodes and provides methods for
navigation, searching, and iteration.


Adding Nodes
------------
Expand Down Expand Up @@ -35,8 +41,8 @@ Nodes are usually created by adding a new data instance to a parent::

.. seealso::

See :doc:`ug_objects` for details on how to manage arbitrary objects instead
of plain strings.
See :doc:`ug_objects` for details on how to manage arbitrary objects, dicts,
etc. instead of plain strings.


Info and Navigation
Expand Down
4 changes: 4 additions & 0 deletions docs/sphinx/ug_clones.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Multiple Instances ('Clones')

.. py:currentmodule:: nutree
.. admonition:: TL;DR

Nutree allows to store multiple references to the same data object in a tree.

Every :class:`~nutree.node.Node` instance is unique within the tree and
also has a unique `node.node_id` value.

Expand Down
4 changes: 4 additions & 0 deletions docs/sphinx/ug_diff.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Diff and Merge

.. py:currentmodule:: nutree
.. admonition:: TL;DR

Nutree provides a `diff` method to compare two trees and calculate the differences.

The :meth:`~nutree.tree.Tree.diff` method compares a tree (`T0`) against another
one (`T1`) and returns a merged, annotated copy.

Expand Down
15 changes: 12 additions & 3 deletions docs/sphinx/ug_graphs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Graphs

.. py:currentmodule:: nutree
.. admonition:: TL;DR

Nutree implements conversion to `DOT <https://en.wikipedia.org/wiki/DOT_(graph_description_language)>`_
and `Mermaid <https://mermaid.js.org>`_ formats. |br|
This allows to visualize trees as graphs in various formats like `png`, `svg`, etc. |br|
The :class:`~nutree.typed_tree.TypedTree` class introduces the concept of
`typed nodes`, which allows to generate labelled edges in the graph representation.


.. note::
:class:`~nutree.tree.Tree` (and :class:`~nutree.typed_tree.TypedTree` even
more so) has features that make mapping to a graph easy.
Expand Down Expand Up @@ -166,7 +175,7 @@ Let's visualize the result of the :ref:`diff-and-merge` example::
of `pydot <https://github.com/pydot/pydot>`_
and `Graphwiz <https://www.graphviz.org>`_. |br|
Either install them separately or install nutree with extras:
``pip install nutree[graph]``.
``pip install "nutree[graph]"`` or ``pip install "nutree[all]"``.

.. _save-mermaid:

Expand Down Expand Up @@ -452,5 +461,5 @@ This would be the 'turtle' formatted serialization::

.. note::
Converting to RDF requires an installation of `rdflib <https://rdflib.readthedocs.io/>`_ |br|
Either install it separately or install nutree with extras:
``pip install nutree[graph]``.
Either install them separately or install nutree with extras:
``pip install "nutree[graph]"`` or ``pip install "nutree[all]"``.
6 changes: 6 additions & 0 deletions docs/sphinx/ug_mutation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Mutation

.. py:currentmodule:: nutree
.. admonition:: TL;DR

Nutree provides methods to modify the tree structure in-place. |br|
This includes adding, moving, and deleting nodes, as well as filtering and sorting.


Some in-place modifications are available::

# Tree
Expand Down
Loading

0 comments on commit bad700c

Please sign in to comment.