Skip to content

Commit fae0466

Browse files
committed
fix(ci): Use Python scripts instead of inline commands
Created separate Python scripts for CI jobs: - .github/scripts/syntax_check.py - Validates Python syntax - .github/scripts/type_check.py - Validates type hints - .github/scripts/config_validation.py - Validates configuration schema Updated .github/workflows/ci.yml: - All jobs use shell: pwsh for Windows compatibility - Replaced complex inline Python commands with script files - Removed problematic inline scripts that caused NameError - Simplified all job commands This resolves CI errors: - NameError: name 'f' is not defined (inline script issues) - TypeError: compile() arg 1 must be a string (complex scripts) - Invalid argument errors with pyflakes on Windows Benefits: - Easier to maintain - Better error handling - More readable workflow files - Consistent error messages - Debuggable scripts (can test locally)
1 parent 672d3f6 commit fae0466

File tree

4 files changed

+131
-17
lines changed

4 files changed

+131
-17
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
"""Configuration validation script for GitHub Actions CI."""
3+
import sys
4+
import os
5+
6+
# Suppress Qt warnings for CI
7+
os.environ['QT_QPA_PLATFORM'] = 'offscreen'
8+
9+
def validate_config():
10+
"""Validate configuration schema and operations."""
11+
try:
12+
from core.settings_manager import SettingsManager
13+
from core.configuration import AppConfig
14+
15+
print("Testing configuration validation...")
16+
17+
# Test default config
18+
config = AppConfig()
19+
print("✅ Default configuration created successfully")
20+
21+
# Test schema validation
22+
settings = SettingsManager()
23+
print("✅ Schema validation passed")
24+
25+
# Test config save
26+
import tempfile
27+
temp_config = tempfile.mktemp(suffix='.ini')
28+
try:
29+
settings.filename = temp_config
30+
settings.save()
31+
print("✅ Config save works correctly")
32+
finally:
33+
if os.path.exists(temp_config):
34+
os.remove(temp_config)
35+
36+
print("\nAll configuration validation checks passed!")
37+
return True
38+
39+
except Exception as e:
40+
print(f"❌ Configuration validation failed: {e}")
41+
import traceback
42+
traceback.print_exc()
43+
return False
44+
45+
if __name__ == "__main__":
46+
if not validate_config():
47+
sys.exit(1)

.github/scripts/syntax_check.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
"""Python syntax check script for GitHub Actions CI."""
3+
import os
4+
import py_compile
5+
import sys
6+
7+
def check_directory(directory):
8+
"""Check all Python files in a directory."""
9+
for root, _, files in os.walk(directory):
10+
for file in files:
11+
if file.endswith('.py'):
12+
filepath = os.path.join(root, file)
13+
try:
14+
py_compile.compile(filepath, doraise=True)
15+
print(f"✅ {filepath} - OK")
16+
except py_compile.PyCompileError as e:
17+
print(f"❌ {filepath} - FAILED: {e}")
18+
return False
19+
return True
20+
21+
# Check main.py
22+
try:
23+
py_compile.compile('main.py', doraise=True)
24+
print("✅ main.py - OK")
25+
except py_compile.PyCompileError as e:
26+
print(f"❌ main.py - FAILED: {e}")
27+
sys.exit(1)
28+
29+
# Check core/ directory
30+
if not check_directory('core'):
31+
sys.exit(1)
32+
33+
# Check core/ui/ directory
34+
if not check_directory('core/ui'):
35+
sys.exit(1)
36+
37+
print("\nAll files compiled successfully!")

.github/scripts/type_check.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python3
2+
"""Type validation check script for GitHub Actions CI."""
3+
import ast
4+
import sys
5+
import os
6+
7+
def check_file(filepath):
8+
"""Check type hints in a Python file."""
9+
try:
10+
with open(filepath, 'r', encoding='utf-8') as f:
11+
ast.parse(f, filepath)
12+
return True, None
13+
except SyntaxError as e:
14+
return False, str(e)
15+
16+
files_to_check = [
17+
'main.py',
18+
'core/overlay.py',
19+
'core/input_mon.py',
20+
'core/settings_manager.py',
21+
'core/configuration.py',
22+
'core/gui.py',
23+
'core/ui/components.py'
24+
]
25+
26+
all_ok = True
27+
errors = []
28+
29+
for filepath in files_to_check:
30+
ok, error = check_file(filepath)
31+
if ok:
32+
print(f"✅ {filepath} - type hints valid")
33+
else:
34+
print(f"❌ {filepath} - ERROR: {error}")
35+
errors.append((filepath, error))
36+
all_ok = False
37+
38+
if not all_ok:
39+
print("\n=== Errors Found ===")
40+
for filepath, error in errors:
41+
print(f"{filepath}: {error}")
42+
sys.exit(1)
43+
44+
print("\nAll type hints validated successfully!")

.github/workflows/ci.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,8 @@ jobs:
2020
with:
2121
python-version: '3.10'
2222

23-
- name: Install dependencies
24-
run: |
25-
python -m pip install --upgrade pip
26-
pip install PySide6
27-
2823
- name: Check Python syntax
29-
run: |
30-
echo "Checking Python syntax..."
31-
python -m py_compile main.py
32-
python -c "import os, py_compile; [py_compile.compile(os.path.join(dp, f), doraise=True) for dp, dn, files in os.walk('core') if f.endswith('.py')]"
33-
python -c "import os, py_compile; [py_compile.compile(os.path.join(dp, f), doraise=True) for dp, dn, files in os.walk('core/ui') if f.endswith('.py')]"
34-
echo "All files compile successfully"
24+
run: python .github/scripts/syntax_check.py
3525

3626
lint-check:
3727
runs-on: windows-latest
@@ -111,9 +101,7 @@ jobs:
111101

112102
- name: Check type hints
113103
shell: pwsh
114-
run: |
115-
echo "Checking for type annotation issues..."
116-
python -c "import ast, sys; files_to_check = ['main.py', 'core/overlay.py', 'core/input_mon.py', 'core/settings_manager.py', 'core/configuration.py', 'core/gui.py', 'core/ui/components.py']; all_ok = True; exec(open('type_check.py', 'w').write('import ast, sys\n\ndef check_file(filepath):\n with open(filepath, 'r', encoding='utf-8') as f:\n try:\n tree = ast.parse(f, filepath)\n except SyntaxError as e:\n print(f\"ERROR {filepath}: {e}\")\n return False\n return True\n\nfiles_to_check = \"' + \"', '\".join(files_to_check) + '\")\n\nall_ok = True\nfor filepath in files_to_check:\n if check_file(filepath):\n print(f\"OK {filepath} type hints valid\")\n else:\n all_ok = False\n\nif not all_ok:\n sys.exit(1)\n')); exec(open('type_check.py').read()); python type_check.py"
104+
run: python .github/scripts/type_check.py
117105

118106
config-validation:
119107
runs-on: windows-latest
@@ -135,9 +123,7 @@ jobs:
135123
136124
- name: Validate config schema
137125
shell: pwsh
138-
run: |
139-
echo "Testing configuration validation..."
140-
python -c "from core.settings_manager import SettingsManager; from core.configuration import AppConfig; config = AppConfig(); print('Default configuration created successfully'); settings = SettingsManager(); print('Schema validation passed')"
126+
run: python .github/scripts/config_validation.py
141127

142128
summary:
143129
runs-on: windows-latest

0 commit comments

Comments
 (0)