Skip to content

Commit 618d85b

Browse files
committed
fix: resolve Python package installation error in Code Quality workflow
**Immediate Fix:** - Fix 'pip install -e python/' error: package configuration is in repository root, not python/ subdirectory - Update Code Quality workflow to use PYTHONPATH approach for Python fallback testing - Replace incorrect package installation with proper module path setup - Add validation steps to ensure Python module can be imported before testing **Package Structure Clarification:** - pyproject.toml and package configuration are in repository root (correct) - python/demopy/ contains Python fallback implementation (correct) - Workflow now uses PYTHONPATH=python approach for testing fallback code - Removed attempt to install non-existent python/pyproject.toml **Comprehensive Testing Infrastructure:** - Create scripts/test_python_structure.py for package structure validation - Create scripts/test_ci_python.py for complete CI simulation - Add validation of Python fallback import and functionality - Test all package functions (hello, add, multiply, sum_list, reverse_string, power) **Development Experience:** - Add validate-python and test-python-fallback commands to Makefile - Integrate Python structure validation into development setup - Provide clear feedback on package import status and functionality - Enable local testing of exact CI workflow steps **Code Quality Fixes:** - Fix flake8 linting issues (import order, line length) - Add noqa comments for necessary import order exceptions - Format code with black and isort for consistency - Ensure all Python quality checks pass locally **Expected Resolution:** - Code Quality workflow should complete Python steps without installation errors - Python fallback code should be properly testable via PYTHONPATH approach - All Python quality checks (black, isort, flake8, mypy, pytest) should pass - Package functionality should be validated in CI environment **Root Cause:** Workflow tried to install package from python/ subdirectory, but package configuration (pyproject.toml) is in repository root. The python/ directory only contains the fallback implementation code. **Solution:** Use PYTHONPATH approach to make Python fallback code importable for testing, rather than attempting package installation from incorrect location.
1 parent 7ed4e70 commit 618d85b

File tree

8 files changed

+685
-79
lines changed

8 files changed

+685
-79
lines changed

.github/workflows/code-quality.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,17 @@ jobs:
8484
- name: Install Python dependencies
8585
run: |
8686
python -m pip install --upgrade pip
87-
pip install black isort flake8 mypy pytest
88-
pip install -e python/
87+
pip install black isort flake8 mypy pytest maturin
88+
89+
- name: Setup Python package for testing
90+
run: |
91+
# For Python quality checks, we need to make the Python code importable
92+
# Add the python directory to PYTHONPATH for testing the fallback code
93+
echo "PYTHONPATH=${PYTHONPATH}:$(pwd)/python" >> $GITHUB_ENV
94+
95+
# Validate that the package can be imported
96+
python -c "import sys; sys.path.insert(0, 'python'); import demopy; print('✅ demopy module imported successfully')"
97+
python -c "import sys; sys.path.insert(0, 'python'); import demopy; print('Package version:', demopy.__version__)"
8998
9099
- name: Check Python formatting (Black)
91100
run: black --check --diff python/ tests/
@@ -102,7 +111,14 @@ jobs:
102111

103112
- name: Run Python tests
104113
run: |
114+
# Ensure Python can find the demopy module
105115
export PYTHONPATH="${PYTHONPATH}:$(pwd)/python"
116+
echo "PYTHONPATH: $PYTHONPATH"
117+
118+
# Test that the module can be imported
119+
python -c "import sys; sys.path.insert(0, 'python'); import demopy; print('✅ demopy module imported successfully')"
120+
121+
# Run the actual tests
106122
pytest tests/ -v
107123
108124
yaml-quality:

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,13 @@ tools-list:
187187
tools-clean:
188188
@echo "🧹 Cleaning Rust tool cache..."
189189
python scripts/install_rust_tools.py --mode clean
190+
191+
# Validate Python package structure
192+
validate-python:
193+
@echo "🔍 Validating Python package structure..."
194+
python scripts/test_python_structure.py
195+
196+
# Test Python fallback only
197+
test-python-fallback:
198+
@echo "🐍 Testing Python fallback implementation..."
199+
PYTHONPATH=python python -c "import demopy; print('Version:', demopy.__version__); print('Hello:', demopy.hello())"

python/demopy/__init__.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,15 @@
88

99
try:
1010
# Import the Rust extension
11-
from demopy_gb_jj._rust import (
12-
hello as _rust_hello,
13-
add,
14-
multiply,
15-
sum_list,
16-
reverse_string,
17-
power,
18-
)
19-
11+
from demopy_gb_jj._rust import add
12+
from demopy_gb_jj._rust import hello as _rust_hello
13+
from demopy_gb_jj._rust import multiply, power, reverse_string, sum_list
14+
2015
# Use the Rust implementation for hello
2116
def hello():
2217
"""Return a greeting message from the Rust extension."""
2318
return _rust_hello()
24-
19+
2520
# Export all functions
2621
__all__ = [
2722
"hello",
@@ -30,34 +25,34 @@ def hello():
3025
"sum_list",
3126
"reverse_string",
3227
"power",
33-
"__version__"
28+
"__version__",
3429
]
35-
30+
3631
except ImportError:
3732
# Fallback to pure Python implementation if Rust extension is not available
3833
def hello():
3934
"""Return a greeting message (pure Python fallback)."""
4035
return "Hello from demopy_gb_jj (Python fallback)!"
41-
36+
4237
def add(a, b):
4338
"""Add two numbers (pure Python fallback)."""
4439
return a + b
45-
40+
4641
def multiply(a, b):
4742
"""Multiply two numbers (pure Python fallback)."""
4843
return a * b
49-
44+
5045
def sum_list(numbers):
5146
"""Sum a list of numbers (pure Python fallback)."""
5247
return sum(numbers)
53-
48+
5449
def reverse_string(s):
5550
"""Reverse a string (pure Python fallback)."""
5651
return s[::-1]
5752

5853
def power(base, exponent):
5954
"""Calculate the power of a number (base^exponent) (pure Python fallback)."""
60-
return base ** exponent
55+
return base**exponent
6156

6257
__all__ = [
6358
"hello",
@@ -66,5 +61,5 @@ def power(base, exponent):
6661
"sum_list",
6762
"reverse_string",
6863
"power",
69-
"__version__"
64+
"__version__",
7065
]

scripts/setup_dev_environment.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,20 @@ def run_initial_checks():
157157
print("\n" + "="*50)
158158
print("🔍 RUNNING INITIAL QUALITY CHECKS")
159159
print("="*50)
160-
160+
161+
# First validate Python package structure
162+
success = run_command("python scripts/test_python_structure.py", "Validate Python package structure", check=False)
163+
if not success:
164+
print("⚠️ Python package structure validation failed, but continuing...")
165+
161166
checks = [
162167
("cargo fmt --all -- --check", "Check Rust formatting"),
163168
("cargo clippy --all-targets --all-features -- -D warnings", "Run Rust linting"),
164169
("cargo test", "Run Rust tests"),
165170
("black --check python/ tests/", "Check Python formatting"),
166171
("isort --check-only python/ tests/", "Check Python import sorting"),
167172
("flake8 python/ tests/", "Run Python linting"),
173+
("PYTHONPATH=python python -c 'import demopy; print(\"Python fallback works:\", demopy.hello())'", "Test Python fallback import"),
168174
]
169175

170176
results = []

0 commit comments

Comments
 (0)