Skip to content

Commit 7501fd7

Browse files
authored
Add ruff as linter + Remove support for Python 3.8 and 3.9 (#402)
* feat: nested_key_dict to tree to support child_key=None * feat: tree to nested_key_dict to support child_key=None * feat: add ruff * feat: add ruff * docs: update CHANGELOG * feat: add exclusions * Remove support for 3.8, 3.9 * Remove support for 3.8, 3.9 * Update CHANGELOG.md * Upgrade version * Upgrade version
1 parent f465398 commit 7501fd7

File tree

14 files changed

+64
-37
lines changed

14 files changed

+64
-37
lines changed

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
15+
python-version: ["3.10", "3.11", "3.12", "3.13"]
1616
fail-fast: false
1717
steps:
1818
- uses: actions/checkout@v3

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
9+
## [0.31.0] - 2025-09-11
810
### Changed:
11+
- General: Remove support for Python 3.8, 3.9.
912
- Docs: Enhanced docs.
13+
- Docs: Add ruff.
1014

1115
## [0.30.1] - 2025-09-10
1216
### Added:
@@ -815,7 +819,8 @@ ignore null attribute columns.
815819
- Utility Iterator: Tree traversal methods.
816820
- Workflow To Do App: Tree use case with to-do list implementation.
817821

818-
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.30.1...HEAD
822+
[Unreleased]: https://github.com/kayjan/bigtree/compare/0.31.0...HEAD
823+
[0.31.0]: https://github.com/kayjan/bigtree/compare/0.30.1...0.31.0
819824
[0.30.1]: https://github.com/kayjan/bigtree/compare/0.30.0...0.30.1
820825
[0.30.0]: https://github.com/kayjan/bigtree/compare/0.29.2...0.30.0
821826
[0.29.2]: https://github.com/kayjan/bigtree/compare/0.29.1...0.29.2

bigtree/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.30.1"
1+
__version__ = "0.31.0"
22

33
from bigtree.binarytree.construct import list_to_binarytree
44
from bigtree.dag.construct import dataframe_to_dag, dict_to_dag, list_to_dag

bigtree/node/basenode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def parent(self: T, new_parent: T) -> None:
239239
self.__parent = current_parent
240240
if current_child_idx is not None:
241241
current_parent.__children.insert(current_child_idx, self)
242-
raise exceptions.TreeError(exc_info)
242+
raise exceptions.TreeError(exc_info) from None
243243

244244
def __pre_assign_parent(self, new_parent: T) -> None:
245245
"""Custom method to check before attaching parent. Can be overridden with `_BaseNode__pre_assign_parent()`.
@@ -386,7 +386,7 @@ def children(self: T, new_children: List[T] | Tuple[T] | Set[T]) -> None:
386386
self.__children = current_children
387387
for child in current_children:
388388
child.__parent = self
389-
raise exceptions.TreeError(exc_info)
389+
raise exceptions.TreeError(exc_info) from None
390390

391391
@children.deleter
392392
def children(self) -> None:

bigtree/node/binarynode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def parent(self: T, new_parent: Optional[T]) -> None:
212212
self.__parent = current_parent
213213
if current_child_idx is not None:
214214
current_parent.__children[current_child_idx] = self
215-
raise exceptions.TreeError(exc_info)
215+
raise exceptions.TreeError(exc_info) from None
216216

217217
def __pre_assign_parent(self: T, new_parent: Optional[T]) -> None:
218218
"""Custom method to check before attaching parent. Can be overridden with `_BinaryNode__pre_assign_parent()`.
@@ -345,7 +345,7 @@ def children(self: T, _new_children: List[Optional[T]]) -> None:
345345
for child in current_children:
346346
if child:
347347
child.__parent = self
348-
raise exceptions.TreeError(exc_info)
348+
raise exceptions.TreeError(exc_info) from None
349349

350350
@children.deleter
351351
def children(self) -> None:

bigtree/node/dagnode.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def parents(self: T, new_parents: List[T]) -> None:
234234
if new_parent not in current_parents:
235235
self.__parents.remove(new_parent)
236236
new_parent.__children.remove(self)
237-
raise exceptions.TreeError(exc_info)
237+
raise exceptions.TreeError(exc_info) from None
238238

239239
def __pre_assign_parents(self: T, new_parents: List[T]) -> None:
240240
"""Custom method to check before attaching parent. Can be overridden with `_DAGNode__pre_assign_parent()`.
@@ -332,7 +332,7 @@ def children(self: T, new_children: Iterable[T]) -> None:
332332
if new_child not in current_children:
333333
new_child.__parents.remove(self)
334334
self.__children.remove(new_child)
335-
raise exceptions.TreeError(exc_info)
335+
raise exceptions.TreeError(exc_info) from None
336336

337337
@children.deleter
338338
def children(self) -> None:

bigtree/tree/export/_stdout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
T = TypeVar("T", bound=node.Node)
1616

17+
default_vstyle = BaseVPrintStyle.from_style("const")
18+
1719

1820
def calculate_stem_pos(length: int) -> int:
1921
"""Calculate stem position based on length.
@@ -33,9 +35,7 @@ def format_node(
3335
_node: T,
3436
alias: str = "node_name",
3537
intermediate_node_name: bool = True,
36-
style: Union[BaseHPrintStyle, BaseVPrintStyle] = BaseVPrintStyle.from_style(
37-
"const"
38-
),
38+
style: Union[BaseHPrintStyle, BaseVPrintStyle] = default_vstyle,
3939
border_style: Optional[BorderStyle] = None,
4040
min_width: int = 0,
4141
add_buffer: bool = True,

bigtree/tree/export/_yield_tree.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def recursive(
255255

256256
result_children, result_idx = [], []
257257
cumulative_height = 0
258-
for idx, child in enumerate(children):
258+
for child in children:
259259
result_child, result_branch_idx = self.recursive(child, _cur_depth + 1)
260260
result_idx.append(cumulative_height + result_branch_idx)
261261
cumulative_height += len(result_child)
@@ -296,7 +296,7 @@ def recursive(
296296
line_prefix = space * (first + 1)
297297
line = space * first + style_class.FIRST_CHILD
298298
line_suffix = space * first + style_class.BRANCH
299-
for idx, (bef, aft) in enumerate(zip(result_idx, result_idx[1:])):
299+
for bef, aft in zip(result_idx, result_idx[1:], strict=False):
300300
line_prefix += space * (aft - bef)
301301
line += (
302302
style_class.STEM * (aft - bef - 1) + style_class.SUBSEQUENT_CHILD
@@ -402,7 +402,7 @@ def recursive(self, _node: Union[T, node.Node]) -> Tuple[List[str], int]:
402402

403403
result_children, result_idx = [], []
404404
cumulative_width = 0
405-
for idx, child in enumerate(children):
405+
for child in children:
406406
result_child, result_branch_idx = self.recursive(child)
407407
result_idx.append(cumulative_width + result_branch_idx)
408408
cumulative_width += len(result_child[0]) + self.spacing
@@ -424,7 +424,7 @@ def recursive(self, _node: Union[T, node.Node]) -> Tuple[List[str], int]:
424424
line = space * first + style_class.BRANCH + space * (total - first - 1)
425425
else:
426426
line = space * first + style_class.FIRST_CHILD
427-
for idx, (bef, aft) in enumerate(zip(result_idx, result_idx[1:])):
427+
for bef, aft in zip(result_idx, result_idx[1:], strict=False):
428428
line += style_class.STEM * (aft - bef - 1)
429429
line += style_class.SUBSEQUENT_CHILD
430430
line = line[:-1] + style_class.LAST_CHILD

bigtree/tree/export/images.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ def tree_to_dot(
175175

176176
name_dict: Dict[str, List[str]] = collections.defaultdict(list)
177177

178-
def _recursive_append(parent_name: Optional[str], child_node: T) -> None:
178+
def _recursive_append(
179+
parent_name: Optional[str],
180+
child_node: T,
181+
_name_dict: Dict[str, List[str]] = name_dict,
182+
) -> None:
179183
"""Recursively iterate through node and its children to export to dot by creating node and edges.
180184
181185
Args:
@@ -197,10 +201,10 @@ def _recursive_append(parent_name: Optional[str], child_node: T) -> None:
197201
_edge_style.update(edge_attr(child_node)) # type: ignore
198202

199203
child_label = child_node.node_name
200-
if child_node.path_name not in name_dict[child_label]: # pragma: no cover
201-
name_dict[child_label].append(child_node.path_name)
204+
if child_node.path_name not in _name_dict[child_label]: # pragma: no cover
205+
_name_dict[child_label].append(child_node.path_name)
202206
child_name = child_label + str(
203-
name_dict[child_label].index(child_node.path_name)
207+
_name_dict[child_label].index(child_node.path_name)
204208
)
205209
pydot_child_node = pydot.Node(
206210
name=child_name, label=child_label, **_node_style
@@ -227,10 +231,10 @@ def _load_font(
227231
font_family = urlopen(dejavusans_url)
228232
try:
229233
font = ImageFont.truetype(font_family, font_size)
230-
except OSError:
234+
except OSError as err:
231235
raise ValueError(
232236
f"Font file {font_family} is not found, set `font_family` parameter to point to a valid .ttf file."
233-
)
237+
) from err
234238
return font
235239

236240

@@ -349,7 +353,7 @@ def get_node_text(_node: T, _node_content: str) -> str:
349353
norm = Normalize(vmin=min(cmap_range), vmax=max(cmap_range))
350354
cmap_range_list = [norm(c) for c in cmap_range]
351355
cmap_colour_list = rect_fill(cmap_range_list) # type: ignore
352-
cmap_dict = dict(zip(cmap_range_list, cmap_colour_list))
356+
cmap_dict = dict(zip(cmap_range_list, cmap_colour_list, strict=True))
353357

354358
# Get x, y, coordinates and height, width of diagram
355359
from bigtree.utils.plot import reingold_tilford

bigtree/tree/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def get_tree_diff(
634634

635635
# Check tree structure difference
636636
data_diff = data_diff_all.dropna(subset=[suffix_col])
637-
path_to_suffix = dict(zip(data_diff[path_col], data_diff[suffix_col]))
637+
path_to_suffix = dict(zip(data_diff[path_col], data_diff[suffix_col], strict=True))
638638

639639
# Check tree attribute difference
640640
path_attr_diff: Dict[str, Dict[str, Any]] = {}

0 commit comments

Comments
 (0)