Skip to content

Commit ca66efe

Browse files
Fix critical package shadowing bug and add project tooling
- Move all benchmark tests under benchmarks/ directory to prevent local folders (numpy/, async/, etc.) from shadowing real Python packages - Remove __init__.py files that were causing import conflicts - Add pre-commit hooks: black, ruff, pylint, isort, mypy, zizmor, hadolint - Add Claude.md with project context and setup instructions - Add Summary/ folder with session tracking and code review documents - Add .gitignore for Python/benchmark artifacts - Update pytest.ini with correct testpaths and asyncio_mode - Fix type annotations for mypy compliance Note: Pre-existing pylint style warnings remain (9.53/10 score) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a8d7163 commit ca66efe

21 files changed

+434
-11
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution / packaging
7+
dist/
8+
build/
9+
*.egg-info/
10+
11+
# Virtual environments
12+
venv/
13+
.venv/
14+
venv_*/
15+
16+
# Benchmark results
17+
benchmark_results/
18+
comparison_results/
19+
.benchmarks/
20+
21+
# pytest
22+
.pytest_cache/
23+
24+
# Ruff
25+
.ruff_cache/
26+
27+
# IDE
28+
.idea/
29+
.vscode/
30+
*.swp
31+
*.swo
32+
33+
# OS
34+
.DS_Store
35+
Thumbs.db

.pre-commit-config.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
repos:
2+
# Black - Code formatting
3+
- repo: https://github.com/psf/black
4+
rev: 24.10.0
5+
hooks:
6+
- id: black
7+
language_version: python3
8+
9+
# isort - Import sorting
10+
- repo: https://github.com/pycqa/isort
11+
rev: 5.13.2
12+
hooks:
13+
- id: isort
14+
args: ["--profile", "black"]
15+
16+
# Ruff - Fast Python linter
17+
- repo: https://github.com/astral-sh/ruff-pre-commit
18+
rev: v0.8.2
19+
hooks:
20+
- id: ruff
21+
args: ["--fix"]
22+
23+
# Pylint - Python linter
24+
- repo: https://github.com/pylint-dev/pylint
25+
rev: v3.3.2
26+
hooks:
27+
- id: pylint
28+
additional_dependencies: ["pytest", "numpy"]
29+
30+
# Mypy - Static type checking
31+
- repo: https://github.com/pre-commit/mirrors-mypy
32+
rev: v1.13.0
33+
hooks:
34+
- id: mypy
35+
additional_dependencies: ["pytest", "numpy", "types-requests"]
36+
args: ["--ignore-missing-imports"]
37+
38+
# Zizmor - GitHub Actions security scanner
39+
- repo: https://github.com/woodruffw/zizmor-pre-commit
40+
rev: v1.0.1
41+
hooks:
42+
- id: zizmor
43+
44+
# Hadolint - Dockerfile linter
45+
- repo: https://github.com/hadolint/hadolint
46+
rev: v2.12.0
47+
hooks:
48+
- id: hadolint-docker

Claude.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Claude Code Context
2+
3+
## Development Environment
4+
5+
- **Package Manager**: uv
6+
- **Development Environment**: GitHub Codespaces
7+
- **Secrets Management**: API keys and secrets are managed through GitHub Codespaces secrets
8+
9+
## Python Version Testing
10+
11+
This project tests across multiple Python versions:
12+
- Python 3.10, 3.11, 3.12, 3.13
13+
- Python 3.14 (upcoming release)
14+
- Python 3.14t (free-threaded/no-GIL build)
15+
16+
## Pre-commit Hooks
17+
18+
The project uses pre-commit with the following hooks:
19+
- **black** - Code formatting
20+
- **isort** - Import sorting (black profile)
21+
- **ruff** - Fast Python linter
22+
- **pylint** - Python linter
23+
- **mypy** - Static type checking
24+
- **zizmor** - GitHub Actions security scanner
25+
- **hadolint** - Dockerfile linter
26+
27+
## Setup
28+
29+
```bash
30+
# Install uv (if not already installed)
31+
curl -LsSf https://astral.sh/uv/install.sh | sh
32+
source $HOME/.local/bin/env # Add uv to PATH
33+
34+
# Install pre-commit
35+
uv pip install pre-commit --system
36+
37+
# Install git hooks
38+
pre-commit install
39+
```
40+
41+
## Project Purpose
42+
43+
Python benchmarking suite for comparing performance across different Python versions and configurations.

Summary/REVIEW_20251214.md

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
# Senior Engineer Code Review: python-benchmarks
2+
3+
**Date:** 2025-12-14
4+
**Reviewer:** Claude (AI)
5+
**Status:** Initial Review
6+
7+
---
8+
9+
## Executive Summary
10+
11+
This Python benchmarking suite has solid foundational concepts and well-organized benchmark categories, but has a **critical structural bug** that prevents it from running. The codebase shows good intent but needs immediate fixes before it can be used.
12+
13+
---
14+
15+
## Critical Issues (P0 - Must Fix)
16+
17+
### 1. Package Name Collision - BLOCKING BUG
18+
19+
**Location:** Root directory structure
20+
**Severity:** Critical - Benchmarks cannot run
21+
22+
The project has folders named `numpy/`, `async/`, `memory/` at the root level with `__init__.py` files. This creates a Python package that **shadows** the real installed packages:
23+
24+
```
25+
python-benchmarks/
26+
├── __init__.py # Makes root a package
27+
├── numpy/ # Shadows real numpy!
28+
│ ├── __init__.py
29+
│ └── test_array_operations.py
30+
├── async/ # "async" is a Python keyword!
31+
│ ├── __init__.py
32+
│ └── test_async_operations.py
33+
...
34+
```
35+
36+
**Evidence:**
37+
```
38+
$ uv run pytest numpy/test_array_operations.py --benchmark-only
39+
AttributeError: module 'numpy' has no attribute 'zeros'
40+
```
41+
42+
**Recommended Fix:**
43+
Option A (Preferred): Rename directories to avoid collisions
44+
```
45+
benchmarks/
46+
├── numpy_benchmarks/
47+
├── async_benchmarks/
48+
├── memory_benchmarks/
49+
├── pytorch_benchmarks/
50+
├── startup_benchmarks/
51+
```
52+
53+
Option B: Move tests under a `benchmarks/` folder and update README paths
54+
```
55+
benchmarks/
56+
├── numpy/
57+
├── async/
58+
...
59+
```
60+
61+
### 2. README Path Mismatch
62+
63+
**Location:** `README.md`, `QUICKSTART.md`
64+
**Severity:** High - Documentation is misleading
65+
66+
Documentation references `benchmarks/` directory that doesn't exist:
67+
- README: `pytest benchmarks/ --benchmark-only`
68+
- QUICKSTART: `python benchmarks/run_benchmarks.py`
69+
70+
Actual structure has tests at root level.
71+
72+
---
73+
74+
## High Priority Issues (P1)
75+
76+
### 3. Missing pyproject.toml
77+
78+
**Impact:** No standardized dependency management with uv
79+
80+
The project uses `requirements.txt` but lacks a `pyproject.toml` for modern Python packaging. Given the project uses uv, should have:
81+
82+
```toml
83+
[project]
84+
name = "python-benchmarks"
85+
version = "0.1.0"
86+
dependencies = [...]
87+
88+
[project.optional-dependencies]
89+
dev = [...]
90+
```
91+
92+
### 4. Unused Variable Warnings (Pre-commit Failures)
93+
94+
**Location:** Multiple files
95+
**Detected by:** ruff, pylint
96+
97+
- `run_benchmarks.py:90` - `result` variable assigned but never used
98+
- `utils/profile_memory.py:70` - `initial_stats` assigned but never used
99+
100+
### 5. Missing Encoding in File Operations
101+
102+
**Location:** `run_benchmarks.py:112`, `utils/compare_results.py:12`
103+
104+
```python
105+
# Current (will warn)
106+
with open(results_file) as f:
107+
108+
# Should be
109+
with open(results_file, encoding='utf-8') as f:
110+
```
111+
112+
---
113+
114+
## Medium Priority Issues (P2)
115+
116+
### 6. pytest-asyncio Configuration
117+
118+
**Location:** `pytest.ini`
119+
120+
Missing asyncio mode configuration. Should add:
121+
```ini
122+
asyncio_mode = auto
123+
```
124+
125+
### 7. Type Hints Incomplete
126+
127+
**Location:** Various files
128+
129+
Some functions have type hints, others don't. Inconsistent:
130+
- `compare_results.py` has type hints
131+
- `run_benchmarks.py` lacks type hints
132+
- `conftest.py` lacks type hints
133+
134+
### 8. Docstring Coverage
135+
136+
Many test classes and inner classes lack docstrings. pylint reports:
137+
- `test_async_operations.py:438` - Missing class docstring
138+
- `test_memory_operations.py:33,196,210` - Missing class docstrings
139+
- Multiple `too-few-public-methods` warnings
140+
141+
### 9. Complex Functions
142+
143+
**Location:** `run_benchmarks.py:109` `generate_summary()`
144+
- Too many local variables (20/15)
145+
- Too many branches (15/12)
146+
- Too many statements (57/50)
147+
148+
Should be refactored into smaller functions.
149+
150+
---
151+
152+
## Low Priority Issues (P3)
153+
154+
### 10. Import Outside Toplevel (Intentional)
155+
156+
**Location:** `startup/test_startup_operations.py`
157+
158+
Many imports inside functions - this is intentional for measuring import time, but could use `# pylint: disable` comments more consistently.
159+
160+
### 11. Line Length
161+
162+
**Location:** `run_benchmarks.py:25`, `utils/compare_results.py:149`
163+
164+
Lines exceed 100 characters. Consider wrapping.
165+
166+
### 12. GitHub Actions / CI Missing
167+
168+
No `.github/workflows/` directory for CI/CD. Should have:
169+
- Matrix testing across Python 3.10-3.14
170+
- Pre-commit hook validation
171+
- Benchmark result archiving
172+
173+
---
174+
175+
## Positive Observations
176+
177+
### Well Done
178+
179+
1. **Comprehensive Benchmark Categories**
180+
- Memory, async, startup, numpy, pytorch - covers key Python performance areas
181+
- Good variety of test cases per category
182+
183+
2. **Good Test Patterns**
184+
- Proper use of pytest fixtures
185+
- Good docstrings on most test methods explaining what's being measured
186+
- Appropriate use of `pytest.skip()` for optional dependencies
187+
188+
3. **Helpful Utilities**
189+
- `compare_results.py` provides useful version comparison
190+
- `profile_memory.py` offers detailed memory analysis
191+
- `compare_versions.sh` automates multi-version testing
192+
193+
4. **Pre-commit Now Configured**
194+
- black, ruff, pylint, isort, mypy, zizmor, hadolint
195+
196+
5. **Good Documentation Intent**
197+
- README explains benchmark categories well
198+
- QUICKSTART provides good onboarding
199+
200+
---
201+
202+
## Recommended Action Plan
203+
204+
### Immediate (Before Any Benchmarking)
205+
1. [ ] Rename directories to avoid package collision (Critical Bug)
206+
2. [ ] Update documentation to match actual paths
207+
3. [ ] Fix unused variable warnings
208+
209+
### Short Term
210+
4. [ ] Add `pyproject.toml` for uv/pip compatibility
211+
5. [ ] Add encoding to file operations
212+
6. [ ] Configure pytest-asyncio properly
213+
214+
### Medium Term
215+
7. [ ] Refactor `generate_summary()` into smaller functions
216+
8. [ ] Add GitHub Actions CI workflow
217+
9. [ ] Complete type hints across codebase
218+
219+
---
220+
221+
## Files Reviewed
222+
223+
| File | Lines | Notes |
224+
|------|-------|-------|
225+
| `README.md` | 209 | Path mismatch issue |
226+
| `QUICKSTART.md` | 170 | Path mismatch issue |
227+
| `run_benchmarks.py` | 260 | Complexity issues, unused var |
228+
| `conftest.py` | 23 | Good, minor issues |
229+
| `pytest.ini` | 23 | Missing asyncio_mode |
230+
| `requirements.txt` | 26 | Should migrate to pyproject.toml |
231+
| `numpy/test_array_operations.py` | 215 | Good tests, shadowing issue |
232+
| `async/test_async_operations.py` | 455 | Good coverage |
233+
| `memory/test_memory_operations.py` | 377 | Good variety |
234+
| `startup/test_startup_operations.py` | 399 | Good coverage |
235+
| `pytorch/test_tensor_operations.py` | 297 | Good PyTorch tests |
236+
| `utils/compare_results.py` | 192 | Good, minor issues |
237+
| `utils/profile_memory.py` | 188 | Good, unused var |
238+
| `compare_versions.sh` | 106 | Good automation |
239+
240+
---
241+
242+
## Conclusion
243+
244+
The benchmarking suite has excellent potential and covers important Python performance areas comprehensively. However, the **critical package shadowing bug** must be fixed before any meaningful benchmarking can occur. Once the directory structure is corrected, this will be a valuable tool for comparing Python version performance.
245+
246+
**Estimated Effort to Fix Critical Issues:** 1-2 hours
247+
**Estimated Effort for All P1 Issues:** Half day
248+
**Estimated Effort for Complete Cleanup:** 1-2 days

0 commit comments

Comments
 (0)