Skip to content

Commit f145186

Browse files
authored
Rename the config to Globals (#418)
* docs: update horizontal line
1 parent 82d3eb9 commit f145186

18 files changed

+56
-55
lines changed

CHANGELOG.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9-
## [1.0.2] - 2025-10-23
9+
## [1.0.3] - 2025-10-30
1010
### Added:
11-
- Optional checks: Able to toggle for optional checks after importing bigtree. Previously, you can only set the
12-
environment variables before import.
11+
- Optional checks: Able to toggle for optional checks after importing bigtree. Previously, it is set at the start using
12+
environment variables before import and not able to toggle after. Implemented as a bigtree._globals.Globals class.
1313

1414
## [1.0.2] - 2025-10-23
1515
### Added:
@@ -856,7 +856,8 @@ ignore null attribute columns.
856856
- Utility Iterator: Tree traversal methods.
857857
- Workflow To Do App: Tree use case with to-do list implementation.
858858

859-
[Unreleased]: https://github.com/kayjan/bigtree/compare/1.0.2...HEAD
859+
[Unreleased]: https://github.com/kayjan/bigtree/compare/1.0.3...HEAD
860+
[1.0.3]: https://github.com/kayjan/bigtree/compare/1.0.2...1.0.3
860861
[1.0.2]: https://github.com/kayjan/bigtree/compare/1.0.1...1.0.2
861862
[1.0.1]: https://github.com/kayjan/bigtree/compare/1.0.0...1.0.1
862863
[1.0.0]: https://github.com/kayjan/bigtree/compare/0.31.2...1.0.0

bigtree/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
__version__ = "1.0.2"
1+
__version__ = "1.0.3"
22

3+
from bigtree._globals import Globals
34
from bigtree.binarytree.binarytree import BinaryTree
45
from bigtree.binarytree.construct import list_to_binarytree
56
from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag
67
from bigtree.dag.dag import DAG
78
from bigtree.dag.export import dag_to_dataframe, dag_to_dict, dag_to_dot, dag_to_list
89
from bigtree.dag.parsing import get_path_dag
9-
from bigtree.globals import ASSERTIONS
1010
from bigtree.node.basenode import BaseNode
1111
from bigtree.node.binarynode import BinaryNode
1212
from bigtree.node.dagnode import DAGNode

bigtree/_globals.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
3+
4+
class Globals:
5+
ASSERTIONS: bool = bool(os.environ.get("BIGTREE_CONF_ASSERTIONS", True))

bigtree/globals.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

bigtree/node/basenode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import heapq
55
from typing import Any, Generator, Iterable, Mapping, TypeVar
66

7-
from bigtree.globals import ASSERTIONS
7+
from bigtree._globals import Globals
88
from bigtree.utils import exceptions, iterators
99

1010
try:
@@ -192,7 +192,7 @@ def parent(self: T, new_parent: T) -> None:
192192
Args:
193193
new_parent: parent node
194194
"""
195-
if ASSERTIONS.FLAG:
195+
if Globals.ASSERTIONS:
196196
self.__check_parent_type(new_parent)
197197
self.__check_parent_loop(new_parent)
198198

@@ -335,7 +335,7 @@ def children(self: T, new_children: list[T] | tuple[T] | set[T]) -> None:
335335
Args:
336336
new_children: child node
337337
"""
338-
if ASSERTIONS.FLAG:
338+
if Globals.ASSERTIONS:
339339
self.__check_children_type(new_children)
340340
self.__check_children_loop(new_children)
341341
new_children = list(new_children)

bigtree/node/binarynode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import Any, TypeVar
44

5-
from bigtree.globals import ASSERTIONS
5+
from bigtree._globals import Globals
66
from bigtree.node import node
77
from bigtree.utils import exceptions
88

@@ -166,7 +166,7 @@ def parent(self: T, new_parent: T | None) -> None:
166166
Args:
167167
new_parent: parent node
168168
"""
169-
if ASSERTIONS.FLAG:
169+
if Globals.ASSERTIONS:
170170
self.__check_parent_type(new_parent)
171171
self._BaseNode__check_parent_loop(new_parent) # type: ignore
172172

@@ -296,7 +296,7 @@ def children(self: T, _new_children: list[T | None]) -> None:
296296
"""
297297
self._BaseNode__check_children_type(_new_children) # type: ignore
298298
new_children = self.__check_children_type(_new_children)
299-
if ASSERTIONS.FLAG:
299+
if Globals.ASSERTIONS:
300300
self.__check_children_loop(new_children)
301301

302302
current_new_children = {

bigtree/node/dagnode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import copy
44
from typing import Any, Generator, Iterable, Mapping, TypeVar
55

6-
from bigtree.globals import ASSERTIONS
6+
from bigtree._globals import Globals
77
from bigtree.utils import exceptions, iterators
88

99

@@ -212,7 +212,7 @@ def parents(self: T, new_parents: list[T]) -> None:
212212
Args:
213213
new_parents: parent nodes
214214
"""
215-
if ASSERTIONS.FLAG:
215+
if Globals.ASSERTIONS:
216216
self.__check_parent_type(new_parents)
217217
self.__check_parent_loop(new_parents)
218218

@@ -311,7 +311,7 @@ def children(self: T, new_children: Iterable[T]) -> None:
311311
Args:
312312
new_children: child node
313313
"""
314-
if ASSERTIONS.FLAG:
314+
if Globals.ASSERTIONS:
315315
self.__check_children_type(new_children)
316316
self.__check_children_loop(new_children)
317317

bigtree/node/node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections import Counter
44
from typing import Any, TypeVar
55

6-
from bigtree.globals import ASSERTIONS
6+
from bigtree._globals import Globals
77
from bigtree.node import basenode
88
from bigtree.utils import exceptions
99

@@ -84,7 +84,7 @@ def __init__(self, name: str, sep: str = "/", **kwargs: Any):
8484
self.name = name
8585
self._sep = sep
8686
super().__init__(**kwargs)
87-
if ASSERTIONS.FLAG and not self.node_name:
87+
if Globals.ASSERTIONS and not self.node_name:
8888
raise exceptions.TreeError("Node must have a `name` attribute")
8989

9090
@property
@@ -133,7 +133,7 @@ def _BaseNode__pre_assign_parent(self: T, new_parent: T) -> None:
133133
Args:
134134
new_parent: new parent to be added
135135
"""
136-
if ASSERTIONS.FLAG and new_parent is not None:
136+
if Globals.ASSERTIONS and new_parent is not None:
137137
if any(
138138
child.node_name == self.node_name and child is not self
139139
for child in new_parent.children
@@ -149,7 +149,7 @@ def _BaseNode__pre_assign_children(self: T, new_children: list[T]) -> None:
149149
Args:
150150
new_children: new children to be added
151151
"""
152-
if ASSERTIONS.FLAG:
152+
if Globals.ASSERTIONS:
153153
children_names = [node.node_name for node in new_children]
154154
duplicate_names = [
155155
item[0] for item in Counter(children_names).items() if item[1] > 1

bigtree/tree/tree.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,6 @@ def register_plugins(
8686
for name, func in mapping.items():
8787
cls.register_plugin(name, func, method)
8888

89-
def show(self, **kwargs: Any) -> None:
90-
self.node.show(**kwargs)
91-
92-
def hshow(self, **kwargs: Any) -> None:
93-
self.node.hshow(**kwargs)
94-
95-
def vshow(self, **kwargs: Any) -> None:
96-
self.node.vshow(**kwargs)
97-
9889
@property
9990
def diameter(self) -> int:
10091
"""Get diameter of tree, the length of longest path between any two nodes.
@@ -210,6 +201,12 @@ def __repr__(self) -> str:
210201
"add_dict_by_path": construct.add_dict_to_tree_by_path,
211202
"add_dict_by_name": construct.add_dict_to_tree_by_name,
212203
# Export methods
204+
"show": export.print_tree,
205+
"hshow": export.hprint_tree,
206+
"vshow": export.vprint_tree,
207+
"yield": export.yield_tree,
208+
"hyield": export.hyield_tree,
209+
"vyield": export.vyield_tree,
213210
"to_dataframe": export.tree_to_dataframe,
214211
"to_polars": export.tree_to_polars,
215212
"to_dict": export.tree_to_dict,

docs/bigtree/tree/construct.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ title: Tree Construct
66

77
## Tree Construct Methods
88

9-
Construct Tree from list, dictionary, and pandas DataFrame.
9+
Construct Tree from list, dictionary, and pandas/polars DataFrame.
1010

1111
To decide which method to use, consider your data type and data values.
1212

0 commit comments

Comments
 (0)