Skip to content

Commit 57d2065

Browse files
committed
Multiple enhancements:
* Remove py3.6 support due to its EOL * Migrate to poetry build toolchain * Add more comprehensive tests and examples * Unify tests, linting, formatting across python versions 3.7+ * Polish lib docstring and doc page.
1 parent b82d38d commit 57d2065

36 files changed

+6935
-917
lines changed

.cursor/rules/basics.mcd

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
7+
You're working on **treelib**—a pure python implemented tree data structure library.
8+
9+
## CODE OF CONDUCT
10+
11+
- After generation, always make sure the code format and linting are performed well.
12+
- Always DO NOT change unrelated parts beyond user requirements.
13+
14+
## CODE STYLE
15+
16+
- Always perfer modularized design for each module.
17+
- Always consider compability for python versions declared in supported range.

.github/workflows/python-package.yml

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,56 @@ name: Package testing
44

55
on:
66
push:
7-
branches: [ "master", "dev" ]
7+
branches: [ "master", "dev", "feature/*", "feat/*" ]
88
pull_request:
99
types: [opened, synchronize, reopened]
1010

1111
jobs:
12-
build-compat:
13-
runs-on: ubuntu-20.04
14-
strategy:
15-
fail-fast: false
16-
matrix:
17-
python-version: ["3.6", "3.7"]
18-
steps:
19-
- uses: actions/checkout@v4
20-
- name: Set up Python ${{ matrix.python-version }}
21-
uses: actions/[email protected]
22-
with:
23-
python-version: ${{ matrix.python-version }}
24-
- name: Install dependencies
25-
run: |
26-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27-
if [ -f requirements-t-pre37.txt ]; then pip install -r requirements-t-pre37.txt; fi
28-
- name: Test with nosetest
29-
run: |
30-
./scripts/testing.sh
3112
build-latest:
3213
runs-on: ubuntu-22.04
3314
strategy:
3415
fail-fast: false
3516
matrix:
36-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
17+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
3718
steps:
3819
- uses: actions/checkout@v4
3920
- name: Set up Python ${{ matrix.python-version }}
4021
uses: actions/[email protected]
4122
with:
4223
python-version: ${{ matrix.python-version }}
24+
- name: Install Poetry
25+
uses: snok/install-poetry@v1
26+
with:
27+
version: ${{ (matrix.python-version == '3.7' && '1.5.1' || (matrix.python-version == '3.8' && '1.7.1' || 'latest')) }}
28+
virtualenvs-create: true
29+
virtualenvs-in-project: true
30+
installer-parallel: true
31+
- name: Load cached venv
32+
id: cached-poetry-dependencies
33+
uses: actions/cache@v4
34+
with:
35+
path: .venv
36+
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
4337
- name: Install dependencies
44-
run: |
45-
python -m pip install --upgrade pip
46-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
47-
if [ -f requirements-t.txt ]; then pip install -r requirements-t.txt; fi
38+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
39+
run: poetry install --no-interaction --no-root
40+
- name: Install project
41+
run: poetry install --no-interaction
42+
- name: Verify pytest installation
43+
run: poetry run python -c "import pytest; print('pytest version:', pytest.__version__)"
4844
- name: Lint with flake8
45+
if: matrix.python-version != '3.7'
4946
run: |
50-
./scripts/flake8.sh
47+
make lint
48+
- name: Check code format
49+
if: matrix.python-version != '3.7'
50+
run: |
51+
make format-check
5152
- name: Test with pytest
5253
run: |
53-
pytest
54+
make test
55+
- name: Run examples
56+
run: |
57+
make run-examples
58+
- name: Build package
59+
run: make build

HISTORY

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Add all_nodes() routine to Tree class.
2626

2727
May 1, 2013
2828
Pulish the module on PyPI with version 1.2 under GNU General Pulic License
29-
version 3.
29+
version 3.
3030

3131

3232
Mar 21, 2013

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Python 2/3 Tree Implementation
33

44
Copyright (C) 2011
55
Brett Alistair Kromkamp - [email protected]
6-
Copyright (C) 2012-2017
6+
Copyright (C) 2012-2025
77
Xiaming Chen - [email protected]
88
and other contributors.
99
All rights reserved.

MANIFEST.in

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

Makefile

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
.PHONY: help install install-dev test test-coverage lint autofix autofix-imports autofix-pep8 autofix-unused format format-check clean build docs
2+
.DEFAULT_GOAL := help
3+
4+
# Variables
5+
PYTHON := python3
6+
POETRY := poetry
7+
DIRS := examples treelib tests
8+
9+
help: ## Show this help message
10+
@echo "Available commands:"
11+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
12+
13+
install: ## Install production dependencies
14+
$(POETRY) install --only main
15+
16+
install-dev: ## Install development dependencies
17+
$(POETRY) install
18+
19+
test: install-dev ## Run tests with pytest
20+
$(POETRY) run pytest
21+
22+
run-examples: install ## Run all example scripts to verify they work correctly
23+
@echo "Running all example scripts..."
24+
@echo "🚀 Running getting_started.py..."
25+
@$(POETRY) run python examples/getting_started.py > /dev/null
26+
@echo "✅ getting_started.py completed successfully"
27+
@echo "👨‍👩‍👧‍👦 Running family_tree.py..."
28+
@$(POETRY) run python examples/family_tree.py > /dev/null
29+
@echo "✅ family_tree.py completed successfully"
30+
@echo "💾 Running save_tree2file.py..."
31+
@$(POETRY) run python examples/save_tree2file.py > /dev/null
32+
@echo "✅ save_tree2file.py completed successfully"
33+
@echo "📁 Running folder_tree.py..."
34+
@$(POETRY) run python examples/folder_tree.py --demo > /dev/null
35+
@echo "✅ folder_tree.py completed successfully"
36+
@echo "📄 Running json_trees.py..."
37+
@$(POETRY) run python examples/json_trees.py > /dev/null
38+
@echo "✅ json_trees.py completed successfully"
39+
@echo "🌳 Running recursive_dirtree.py..."
40+
@$(POETRY) run python examples/recursive_dirtree.py > /dev/null
41+
@echo "✅ recursive_dirtree.py completed successfully"
42+
@echo "🧮 Running tree_algorithms.py..."
43+
@$(POETRY) run python examples/tree_algorithms.py > /dev/null
44+
@echo "✅ tree_algorithms.py completed successfully"
45+
@echo "🎉 All examples completed successfully!"
46+
47+
lint: install-dev ## Run linting checks (flake8)
48+
$(POETRY) run flake8 $(DIRS) --count --select=E9,F63,F7,F82 --ignore=E231 --max-line-length=120 --show-source --statistics
49+
50+
autofix-unused: install-dev ## Remove unused imports and variables
51+
$(POETRY) run autoflake --remove-all-unused-imports --remove-unused-variables --in-place --recursive $(DIRS)
52+
53+
autofix-imports: install-dev ## Sort and organize imports
54+
$(POETRY) run isort $(DIRS) --profile black
55+
56+
autofix-pep8: install-dev ## Fix PEP 8 style issues
57+
$(POETRY) run autopep8 --in-place --recursive --aggressive --aggressive $(DIRS)
58+
59+
autofix: autofix-unused autofix-imports autofix-pep8 format
60+
61+
format: install-dev ## Format code with black
62+
$(POETRY) run black $(DIRS)
63+
64+
format-check: install-dev ## Check code formatting with black
65+
$(POETRY) run black --check $(DIRS)
66+
67+
check: lint format-check ## Run all checks (lint + format check)
68+
69+
clean: ## Clean build artifacts and cache
70+
rm -rf build/
71+
rm -rf dist/
72+
rm -rf *.egg-info/
73+
rm -rf .pytest_cache/
74+
rm -rf .coverage
75+
rm -rf htmlcov/
76+
find . -type d -name __pycache__ -delete
77+
find . -type f -name "*.pyc" -delete
78+
79+
build: ## Build the package
80+
$(POETRY) build
81+
82+
docs: ## Build documentation
83+
@if [ -d "docs" ]; then \
84+
cd docs && make html; \
85+
else \
86+
echo "No docs directory found"; \
87+
fi

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Tree implementation in python: simple for you to use.
1515
[![GitHub pull-requests](https://img.shields.io/github/issues-pr/caesar0301/treelib.svg)](https://GitHub.com/caesar0301/treelib/pulls)
1616
[![GitHub pull-requests closed](https://img.shields.io/github/issues-pr-closed/caesar0301/treelib.svg)](https://GitHub.com/caesar0301/treelib/pulls?q=is%3Apr+is%3Aclosed)
1717

18+
1819
## Quick Start
1920

2021
pip install -U treelib
@@ -23,14 +24,14 @@ Tree implementation in python: simple for you to use.
2324

2425
For installation, APIs and examples, see http://treelib.readthedocs.io/en/latest/
2526

26-
DeepWiki Generation: https://deepwiki.com/caesar0301/treelib
27+
Ask DeepWiki: https://deepwiki.com/caesar0301/treelib
28+
29+
### Development Commands
2730

28-
## Code Style
31+
We provide a convenient Makefile for common development tasks. Run `make help` to show usage.
2932

30-
`treelib` complies with [black](https://github.com/psf/black) formatter and
31-
specific [flake8 validations](https://github.com/caesar0301/treelib/blob/master/scripts/flake8.sh).
3233
Before creating a pull request, please make sure you pass the local validation
33-
with `scripts/flake8.sh`.
34+
with `make check`.
3435

3536
## Contributors
3637

0 commit comments

Comments
 (0)