Skip to content

Commit 04a5df8

Browse files
committed
Merge branch 'master' of https://github.com/dgercho/treelib into dev/105-from_json
2 parents 72c8f56 + b8f85ff commit 04a5df8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+9649
-1013
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/pypi-publish.yml

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This workflow will upload a Python Package using Twine when a release is created
1+
# This workflow will upload a Python Package using Poetry when a release is created
22
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
33

44
# This workflow uses actions that are not certified by GitHub.
@@ -14,26 +14,95 @@ on:
1414

1515
permissions:
1616
contents: read
17+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
1718

1819
jobs:
1920
deploy:
20-
2121
runs-on: ubuntu-latest
22-
22+
environment:
23+
name: pypi
24+
url: https://pypi.org/p/treelib
25+
2326
steps:
2427
- uses: actions/checkout@v4
28+
2529
- name: Set up Python
2630
uses: actions/setup-python@v5.4.0
2731
with:
28-
python-version: '3.x'
32+
python-version: '3.11' # Use specific version for consistency
33+
34+
- name: Install Poetry
35+
uses: snok/install-poetry@v1
36+
with:
37+
version: latest
38+
virtualenvs-create: true
39+
virtualenvs-in-project: true
40+
installer-parallel: true
41+
42+
- name: Load cached venv
43+
id: cached-poetry-dependencies
44+
uses: actions/cache@v4
45+
with:
46+
path: .venv
47+
key: venv-${{ runner.os }}-3.11-${{ hashFiles('**/poetry.lock') }}
48+
2949
- name: Install dependencies
50+
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
51+
run: poetry install --no-interaction --no-root
52+
53+
- name: Install project
54+
run: poetry install --no-interaction
55+
56+
- name: Verify version matches release tag
3057
run: |
31-
python -m pip install --upgrade pip
32-
pip install build
58+
POETRY_VERSION=$(poetry version --short)
59+
RELEASE_TAG=${GITHUB_REF#refs/tags/}
60+
echo "Poetry version: $POETRY_VERSION"
61+
echo "Release tag: $RELEASE_TAG"
62+
63+
# Handle both v1.8.0 style and v1.0 style tags
64+
if [ "v$POETRY_VERSION" = "$RELEASE_TAG" ]; then
65+
echo "✅ Exact match: v$POETRY_VERSION = $RELEASE_TAG"
66+
elif [ "$POETRY_VERSION" = "${RELEASE_TAG#v}" ]; then
67+
echo "✅ Version match: $POETRY_VERSION = ${RELEASE_TAG#v}"
68+
else
69+
echo "❌ Version mismatch:"
70+
echo " Poetry version: $POETRY_VERSION"
71+
echo " Release tag: $RELEASE_TAG"
72+
echo " Expected: v$POETRY_VERSION"
73+
exit 1
74+
fi
75+
echo "✅ Version verification passed"
76+
77+
- name: Run tests before publishing
78+
run: |
79+
echo "🧪 Running tests to ensure package quality..."
80+
make test
81+
82+
- name: Check code format and lint
83+
run: |
84+
echo "🔍 Running code quality checks..."
85+
make format-check
86+
make lint
87+
3388
- name: Build package
34-
run: python -m build
35-
- name: Publish package
36-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
89+
run: |
90+
echo "🏗️ Building package with Poetry..."
91+
make build
92+
93+
- name: Verify build artifacts
94+
run: |
95+
echo "📦 Verifying build artifacts..."
96+
ls -la dist/
97+
# Check that both wheel and source distribution were created
98+
if [ ! -f dist/*.whl ] || [ ! -f dist/*.tar.gz ]; then
99+
echo "❌ Missing build artifacts"
100+
exit 1
101+
fi
102+
echo "✅ Build artifacts verified"
103+
104+
- name: Publish package to PyPI
105+
uses: pypa/gh-action-pypi-publish@release/v1
37106
with:
38-
user: __token__
39-
password: ${{ secrets.PYPI_API_TOKEN }}
107+
verbose: true
108+
print-hash: true

.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/setup-python@v5.4.0
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/setup-python@v5.4.0
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

.readthedocs.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Read the Docs configuration file for treelib
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
# Required
5+
version: 2
6+
7+
# Set the version of Python and other tools you might need
8+
build:
9+
os: ubuntu-22.04
10+
tools:
11+
python: "3.11"
12+
13+
# Build documentation in the docs/ directory with Sphinx
14+
sphinx:
15+
configuration: docs/source/conf.py
16+
17+
# Optionally declare the Python requirements required to build your docs
18+
python:
19+
install:
20+
- requirements: docs/requirements.txt
21+
- method: pip
22+
path: .

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 - brettkromkamp@gmail.com
6-
Copyright (C) 2012-2017
6+
Copyright (C) 2012-2025
77
Xiaming Chen - chenxm35@gmail.com
88
and other contributors.
99
All rights reserved.

MANIFEST.in

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

Makefile

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

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ Tree implementation in python: simple for you to use.
1010
[![PyV](https://img.shields.io/pypi/pyversions/treelib.svg)](https://pypi.python.org/pypi/treelib)
1111
[![PyPI download month](https://img.shields.io/pypi/dm/treelib.svg)](https://pypi.python.org/pypi/treelib/)
1212
[![GitHub contributors](https://img.shields.io/github/contributors/caesar0301/treelib.svg)](https://github.com/caesar0301/treelib/graphs/contributors/)
13-
14-
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
1513
[![GitHub pull-requests](https://img.shields.io/github/issues-pr/caesar0301/treelib.svg)](https://github.com/caesar0301/treelib/pulls)
1614
[![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)
1715

16+
[![AI Assisted Yes](https://img.shields.io/badge/AI%20Assisted-Yes-green?style=for-the-badge)](https://github.com/mefengl/made-by-ai)
17+
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

docs/publish.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PYLIB=../treelib
55
TARGET=html
66
BUILT=build
77

8-
rm -rf $BUILD
8+
rm -rf $BUILT
99
sphinx-apidoc -o $SOURCE $PYLIB
1010
make $TARGET
1111
touch $BUILT/$TARGET/.nojekyll

0 commit comments

Comments
 (0)