Skip to content

Commit 0712830

Browse files
committed
Modernize project structure for better OSS contribution experience
This commit restructures the project to follow modern Python packaging best practices and makes it easier for contributors to get started. Major changes: - Add pyproject.toml for unified project configuration (PEP 621) - Simplify setup.py to only handle C++ extension building - Consolidate requirements.txt files into pyproject.toml - Reorganize development scripts into tools/ directory - Add comprehensive DEVELOPMENT.md guide for contributors - Update Makefile with modern development workflows - Update CI/CD workflows to use new structure - Clean up root directory for better organization Benefits: - Single source of truth for dependencies and metadata - Easier setup for new contributors (pip install -e ".[dev]") - Modern tooling integration (black, ruff, mypy) - Clear development documentation - Cleaner, more maintainable project structure Files removed: - init_develop.sh, run_test.sh (replaced by Makefile targets) - requirements.txt, requirements-dev.txt (moved to pyproject.toml) Files added: - pyproject.toml (project configuration) - DEVELOPMENT.md (contributor guide) - tools/ directory (development utilities) Files updated: - setup.py (simplified, metadata moved to pyproject.toml) - Makefile (new targets for modern workflow) - README.md (updated installation instructions) - CI/CD workflows (updated for new structure) - MANIFEST.in (updated for new file structure)
1 parent 40e664e commit 0712830

File tree

15 files changed

+590
-78
lines changed

15 files changed

+590
-78
lines changed

.github/workflows/cibuildwheel.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,11 @@ jobs:
4545
python-version: ${{ matrix.python }}
4646
- name: Install dependencies
4747
run: |
48-
python -m pip install --upgrade pip wheel setuptools
49-
python -m pip install numpy pytest
48+
python -m pip install --upgrade pip build
5049
- name: Build and install
51-
run: python -m pip install -e .
50+
run: python -m pip install -e ".[dev]"
5251
- name: Run tests
53-
run: pytest tests -vv
52+
run: python -m pytest tests -vv
5453

5554
build_wheels:
5655
# Skip wheel builds on PRs - only build on main branch and tags

DEVELOPMENT.md

Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
# Development Guide
2+
3+
Welcome to the python_prtree development guide! This document will help you get started with contributing to the project.
4+
5+
## Project Structure
6+
7+
```
8+
python_prtree/
9+
├── src/ # Python source code
10+
│ └── python_prtree/ # Main package
11+
├── cpp/ # C++ implementation
12+
├── tests/ # Test suite
13+
│ ├── unit/ # Unit tests
14+
│ ├── integration/ # Integration tests
15+
│ └── e2e/ # End-to-end tests
16+
├── tools/ # Development tools and scripts
17+
├── benchmarks/ # Performance benchmarks
18+
├── docs/ # Documentation
19+
├── .github/workflows/ # CI/CD configuration
20+
└── third/ # Third-party dependencies (git submodules)
21+
```
22+
23+
## Prerequisites
24+
25+
- Python 3.8 or higher
26+
- CMake 3.22 or higher
27+
- C++17 compatible compiler
28+
- Git (for submodules)
29+
30+
### Platform-Specific Requirements
31+
32+
**macOS:**
33+
```bash
34+
brew install cmake
35+
```
36+
37+
**Ubuntu/Debian:**
38+
```bash
39+
sudo apt-get install cmake build-essential
40+
```
41+
42+
**Windows:**
43+
- Visual Studio 2019 or later with C++ development tools
44+
- CMake (can be installed via Visual Studio installer or from cmake.org)
45+
46+
## Getting Started
47+
48+
### 1. Clone the Repository
49+
50+
```bash
51+
git clone https://github.com/atksh/python_prtree.git
52+
cd python_prtree
53+
```
54+
55+
### 2. Initialize Submodules
56+
57+
The project uses git submodules for third-party dependencies:
58+
59+
```bash
60+
git submodule update --init --recursive
61+
```
62+
63+
Or use the Makefile:
64+
65+
```bash
66+
make init
67+
```
68+
69+
### 3. Set Up Development Environment
70+
71+
#### Using pip (recommended)
72+
73+
```bash
74+
# Install in development mode with all dependencies
75+
pip install -e ".[dev,docs,benchmark]"
76+
```
77+
78+
#### Using make
79+
80+
```bash
81+
# Initialize submodules and install dependencies
82+
make dev
83+
```
84+
85+
This will:
86+
- Initialize git submodules
87+
- Install the package in editable mode
88+
- Install all development dependencies
89+
90+
### 4. Build the C++ Extension
91+
92+
```bash
93+
# Build in debug mode (default)
94+
make build
95+
96+
# Or build in release mode
97+
make build-release
98+
```
99+
100+
## Development Workflow
101+
102+
### Running Tests
103+
104+
```bash
105+
# Run all tests
106+
make test
107+
108+
# Run tests in parallel (faster)
109+
make test-fast
110+
111+
# Run tests with coverage report
112+
make test-coverage
113+
114+
# Run specific test
115+
make test-one TEST=test_insert
116+
```
117+
118+
Or use pytest directly:
119+
120+
```bash
121+
pytest tests -v
122+
pytest tests/unit/test_insert.py -v
123+
pytest tests -k "test_insert" -v
124+
```
125+
126+
### Code Quality
127+
128+
#### Format Code
129+
130+
```bash
131+
# Format both Python and C++ code
132+
make format
133+
134+
# Format only Python (uses black)
135+
python -m black src/ tests/
136+
137+
# Format only C++ (uses clang-format)
138+
clang-format -i cpp/*.cc cpp/*.h
139+
```
140+
141+
#### Lint Code
142+
143+
```bash
144+
# Lint all code
145+
make lint
146+
147+
# Lint only Python (uses ruff)
148+
make lint-python
149+
150+
# Lint only C++ (uses clang-tidy)
151+
make lint-cpp
152+
153+
# Type check Python code (uses mypy)
154+
make type-check
155+
```
156+
157+
### Building Documentation
158+
159+
```bash
160+
make docs
161+
```
162+
163+
### Cleaning Build Artifacts
164+
165+
```bash
166+
# Remove build artifacts
167+
make clean
168+
169+
# Clean everything including submodules
170+
make clean-all
171+
```
172+
173+
## Project Configuration
174+
175+
All project metadata and dependencies are defined in `pyproject.toml`:
176+
177+
- **Project metadata**: name, version, description, authors
178+
- **Dependencies**: runtime and development dependencies
179+
- **Build system**: setuptools with CMake integration
180+
- **Tool configurations**: pytest, black, ruff, mypy, coverage
181+
182+
## Testing Guidelines
183+
184+
### Test Organization
185+
186+
- `tests/unit/`: Unit tests for individual components
187+
- `tests/integration/`: Tests for component interactions
188+
- `tests/e2e/`: End-to-end workflow tests
189+
- `tests/legacy/`: Legacy test suite
190+
191+
### Writing Tests
192+
193+
```python
194+
import pytest
195+
from python_prtree import PRTree
196+
197+
def test_basic_insertion():
198+
"""Test basic rectangle insertion."""
199+
tree = PRTree()
200+
tree.insert([0, 0, 10, 10], "rect1")
201+
assert tree.size() == 1
202+
203+
def test_query():
204+
"""Test rectangle query."""
205+
tree = PRTree()
206+
tree.insert([0, 0, 10, 10], "rect1")
207+
results = tree.query([5, 5, 15, 15])
208+
assert len(results) > 0
209+
```
210+
211+
### Running Specific Test Categories
212+
213+
```bash
214+
# Run only unit tests
215+
pytest tests/unit -v
216+
217+
# Run only integration tests
218+
pytest tests/integration -v
219+
220+
# Run only e2e tests
221+
pytest tests/e2e -v
222+
```
223+
224+
## C++ Development
225+
226+
### Building with Debug Symbols
227+
228+
```bash
229+
make debug-build
230+
```
231+
232+
### Profiling
233+
234+
```bash
235+
# Run profiling scripts
236+
./tools/profile.sh
237+
python tools/profile.py
238+
```
239+
240+
### Benchmarks
241+
242+
```bash
243+
# Run benchmarks (if available)
244+
make benchmark
245+
```
246+
247+
## Continuous Integration
248+
249+
The project uses GitHub Actions for CI/CD:
250+
251+
- **Pull Requests**: Runs unit tests on multiple platforms (Linux, macOS, Windows) and Python versions (3.8-3.14)
252+
- **Main Branch**: Builds wheels for all platforms and Python versions
253+
- **Version Tags**: Publishes packages to PyPI
254+
255+
## Making Changes
256+
257+
### Workflow
258+
259+
1. Create a new branch:
260+
```bash
261+
git checkout -b feature/my-feature
262+
```
263+
264+
2. Make your changes and write tests
265+
266+
3. Run tests and linting:
267+
```bash
268+
make test
269+
make lint
270+
```
271+
272+
4. Commit your changes:
273+
```bash
274+
git add .
275+
git commit -m "Add feature: description"
276+
```
277+
278+
5. Push and create a pull request:
279+
```bash
280+
git push origin feature/my-feature
281+
```
282+
283+
### Code Style
284+
285+
- **Python**: Follow PEP 8, use black for formatting (100 char line length)
286+
- **C++**: Follow Google C++ Style Guide, use clang-format
287+
- **Commits**: Use conventional commit messages
288+
- `feat:` for new features
289+
- `fix:` for bug fixes
290+
- `docs:` for documentation
291+
- `test:` for test changes
292+
- `refactor:` for refactoring
293+
- `chore:` for maintenance tasks
294+
295+
## Troubleshooting
296+
297+
### Submodules Not Initialized
298+
299+
```bash
300+
git submodule update --init --recursive
301+
```
302+
303+
### Build Fails
304+
305+
1. Ensure CMake is installed and up to date
306+
2. Check that all submodules are initialized
307+
3. Try cleaning and rebuilding:
308+
```bash
309+
make clean
310+
make build
311+
```
312+
313+
### Tests Fail
314+
315+
1. Ensure the extension is built:
316+
```bash
317+
make build
318+
```
319+
320+
2. Check that all dependencies are installed:
321+
```bash
322+
pip install -e ".[dev]"
323+
```
324+
325+
### Import Errors
326+
327+
Ensure you've installed the package in development mode:
328+
```bash
329+
pip install -e .
330+
```
331+
332+
## Additional Resources
333+
334+
- [CONTRIBUTING.md](CONTRIBUTING.md) - Contribution guidelines
335+
- [README.md](README.md) - Project overview
336+
- [CHANGES.md](CHANGES.md) - Version history
337+
- [GitHub Issues](https://github.com/atksh/python_prtree/issues) - Bug reports and feature requests
338+
339+
## Questions?
340+
341+
If you have questions or need help, please:
342+
343+
1. Check existing [GitHub Issues](https://github.com/atksh/python_prtree/issues)
344+
2. Open a new issue with your question
345+
3. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details
346+
347+
Happy coding! 🎉

MANIFEST.in

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
include README.md LICENSE
2-
include requirements.txt
1+
include README.md LICENSE CHANGES.md CONTRIBUTING.md DEVELOPMENT.md
2+
include pyproject.toml setup.py
33
global-include CMakeLists.txt *.cmake
4-
recursive-include cpp *
5-
recursive-include src *
6-
recursive-include third *
4+
recursive-include cpp *.h *.cc
5+
recursive-include src *.py
6+
recursive-include third *
7+
exclude third/.git*
8+
prune third/**/.git

0 commit comments

Comments
 (0)