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 Oct 28, 2024
2 parents 16d752a + d360d3d commit 90e7517
Show file tree
Hide file tree
Showing 22 changed files with 419 additions and 461 deletions.
14 changes: 7 additions & 7 deletions nutree/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# flake8: noqa
__version__ = "0.9.1-a1"

from .common import (
from nutree.common import (
AmbiguousMatchError,
DictWrapper,
IterMethod,
Expand All @@ -28,13 +28,13 @@
TreeError,
UniqueConstraintError,
)
from .diff import DiffClassification, diff_node_formatter
from .fs import load_tree_from_fs
from .node import Node
from .tree import Tree
from .typed_tree import TypedNode, TypedTree
from nutree.diff import DiffClassification, diff_node_formatter
from nutree.fs import load_tree_from_fs
from nutree.node import Node
from nutree.tree import Tree
from nutree.typed_tree import TypedNode, TypedTree

__all__ = [
__all__ = [ # pyright: ignore[reportUnsupportedDunderAll]
Tree,
Node,
AmbiguousMatchError,
Expand Down
21 changes: 16 additions & 5 deletions nutree/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import io
import sys
import unittest.mock
import warnings
import zipfile
from contextlib import contextmanager
Expand All @@ -28,11 +29,21 @@
Union,
)

try:
from typing import Self
except ImportError:
from typing_extensions import Self # noqa


if TYPE_CHECKING: # Imported by type checkers, but prevent circular includes
from .node import Node
from .tree import Tree
from nutree.node import Node
from nutree.tree import Tree

TTree = TypeVar("TTree", bound=Tree)
TNode = TypeVar("TNode", bound=Node)

#: A sentinel object that can be used to detect if a parameter was passed.
sentinel = unittest.mock.sentinel

#: Used as ID for the system root node
ROOT_DATA_ID: str = "__root__"
Expand Down Expand Up @@ -122,9 +133,6 @@ def __init__(self, value=None):
#: Type of ``format(..., repr=)```
ReprArgType = Union[str, Callable[["Node"], str]]

#: Type of ``Tree(..., factory)```
NodeFactoryType = Type["Node"]

#: A dict of scalar values
FlatJsonDictType = Dict[str, Union[str, int, float, bool, None]]

Expand Down Expand Up @@ -152,6 +160,9 @@ def __init__(self, value=None):
["Node"], Union[None, bool, IterationControl, Type[IterationControl]]
]

#:
MatchArgumentType = Union[str, PredicateCallbackType, list, tuple, Any]

#:
TraversalCallbackType = Callable[
["Node", Any],
Expand Down
2 changes: 1 addition & 1 deletion nutree/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING: # Imported by type checkers, but prevent circular includes
from .tree import Node, Tree
from nutree.tree import Node, Tree

from enum import Enum

Expand Down
6 changes: 3 additions & 3 deletions nutree/dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from pathlib import Path
from typing import IO, TYPE_CHECKING, Iterator

from .common import MapperCallbackType, call_mapper
from nutree.common import MapperCallbackType, call_mapper

if TYPE_CHECKING: # Imported by type checkers, but prevent circular includes
from .node import Node
from .tree import Tree
from nutree.node import Node
from nutree.tree import Tree

try:
import pydot
Expand Down
9 changes: 5 additions & 4 deletions nutree/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
Methods and classes to support file system related functionality.
"""

from __future__ import annotations

from datetime import datetime
from operator import attrgetter, itemgetter
from pathlib import Path
from typing import Optional, Union

from nutree.tree import Node, Tree

Expand All @@ -18,8 +19,8 @@ def __init__(
name: str,
*,
is_dir: bool = False,
size: Optional[int] = None,
mdate: Optional[float] = None,
size: int | None = None,
mdate: float | None = None,
):
self.name = name
self.is_dir = is_dir
Expand Down Expand Up @@ -61,7 +62,7 @@ def deserialize_mapper(cls, parent: Node, data: dict):
return FileSystemEntry(data["n"], size=data["s"], mdate=data["m"])


def load_tree_from_fs(path: Union[str, Path], *, sort: bool = True) -> FileSystemTree:
def load_tree_from_fs(path: str | Path, *, sort: bool = True) -> FileSystemTree:
"""Scan a filesystem folder and store as tree.
Args:
Expand Down
4 changes: 2 additions & 2 deletions nutree/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from subprocess import CalledProcessError, check_output
from typing import IO, TYPE_CHECKING, Callable, Iterable, Iterator, Literal

from .common import DataIdType
from nutree.common import DataIdType

if TYPE_CHECKING: # Imported by type checkers, but prevent circular includes
from .node import Node
from nutree.node import Node

MermaidDirectionType = Literal["LR", "RL", "TB", "TD", "BT"]
MermaidFormatType = Literal["svg", "pdf", "png"]
Expand Down
Loading

0 comments on commit 90e7517

Please sign in to comment.