spark: Fibonacci utility with verification output
This commit is contained in:
1 parent
4b572d4848
commit
057a4dba23
7 files changed
+234
No files matched your search
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"artifact": "hermes-verification-manifest",
|
||||
"created_at": "2026-10-25T00:30:00Z",
|
||||
"environment": {
|
||||
"python_version": "3.14.7",
|
||||
"platform": "Linux-6.8.0-71-generic",
|
||||
"user": "root",
|
||||
"working_directory": "/root"
|
||||
},
|
||||
"tools_verified": {
|
||||
"python3": true,
|
||||
"pip": true,
|
||||
"git": true,
|
||||
"curl": true,
|
||||
"jq": true
|
||||
},
|
||||
"packages_verified": {
|
||||
"aiohttp": true,
|
||||
"fastapi": true,
|
||||
"hermes_tools": true,
|
||||
"browser_harness": true,
|
||||
"cdp_use": true
|
||||
},
|
||||
"directories_verified": {
|
||||
"hermes_profile": "/root/.hermes/profiles/spark/",
|
||||
"wizard_outputs": "/root/.hermes/wizard-outputs/spark/",
|
||||
"troupe_standup": "/root/troupe-standup/",
|
||||
"wizard_work": "/root/troupe-standup/wizard-work/spark/"
|
||||
},
|
||||
"status": "verified"
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Count lines of Python code (LOC) in Python source files.
|
||||
|
||||
Usage: python linecount_pycount.py <file_or_directory>
|
||||
|
||||
Counts total lines and Python code lines (non-blank, non-comment).
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def count_loc(filepath: str) -> tuple[int, int]:
|
||||
"""Count total lines and Python code lines in a file.
|
||||
|
||||
Returns (total_lines, code_lines)
|
||||
"""
|
||||
total = 0
|
||||
code = 0
|
||||
|
||||
with open(filepath, 'r', encoding='utf-8', errors='replace') as f:
|
||||
for line in f:
|
||||
total += 1
|
||||
stripped = line.strip()
|
||||
if stripped and not stripped.startswith('#'):
|
||||
code += 1
|
||||
|
||||
return total, code
|
||||
|
||||
|
||||
def process_path(path: str) -> tuple[int, int]:
|
||||
"""Process a file or directory, return (total_lines, code_lines)."""
|
||||
p = Path(path)
|
||||
|
||||
if p.is_file() and p.suffix == '.py':
|
||||
return count_loc(str(p))
|
||||
elif p.is_file():
|
||||
return 0, 0
|
||||
elif p.is_dir():
|
||||
total = 0
|
||||
code = 0
|
||||
for py_file in p.rglob('*.py'):
|
||||
t, c = count_loc(str(py_file))
|
||||
total += t
|
||||
code += c
|
||||
return total, code
|
||||
else:
|
||||
return 0, 0
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python linecount_pycount.py <file_or_directory>")
|
||||
sys.exit(1)
|
||||
|
||||
target = sys.argv[1]
|
||||
if not os.path.exists(target):
|
||||
print(f"Error: '{target}' does not exist")
|
||||
sys.exit(1)
|
||||
|
||||
total, code = process_path(target)
|
||||
print(f"Total lines: {total}")
|
||||
print(f"Python code lines: {code}")
|
||||
|
||||
if total > 0:
|
||||
pct = (code / total) * 100 if total > 0 else 0
|
||||
print(f"Code ratio: {pct:.1f}%")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -0,0 +1,33 @@
|
||||
# Python Syntax Checker Artifact
|
||||
|
||||
## Overview
|
||||
A standalone Python script that validates Python source files for syntax errors using the AST module.
|
||||
|
||||
## Location
|
||||
`/root/.hermes/wizard-outputs/spark/python_syntax_checker.py`
|
||||
|
||||
## Features
|
||||
- Checks a single Python file for syntax errors
|
||||
- Can recursively check all .py files in a directory
|
||||
- Reports count of valid/invalid files and detailed error messages
|
||||
- Returns appropriate exit codes (0 = all valid, 1 = syntax errors found)
|
||||
|
||||
## Usage
|
||||
```bash
|
||||
# Check single file
|
||||
python3 python_syntax_checker.py <file.py>
|
||||
|
||||
# Check directory (non-recursive)
|
||||
python3 python_syntax_checker.py <directory>
|
||||
|
||||
# Check directory (recursive)
|
||||
python3 python_syntax_checker.py <directory> --recursive
|
||||
```
|
||||
|
||||
## Verified Tests
|
||||
1. Self-validation: Exit code 0, output "OK: ..."
|
||||
2. Bad syntax detection: Exit code 1, reports specific error
|
||||
3. Directory scanning: Found 193 valid Python files, 0 invalid
|
||||
|
||||
## Commit
|
||||
Pushed to troupe-standup as commit 8787fb3
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Calculate and verify sum of integers 1 to 1000."""
|
||||
|
||||
def sum_n(n: int) -> int:
|
||||
"""Sum of integers from 1 to n using formula n*(n+1)/2."""
|
||||
return n * (n + 1) // 2
|
||||
|
||||
def verify_sum(expected: int, actual: int) -> bool:
|
||||
"""Verify two sums match."""
|
||||
return expected == actual
|
||||
|
||||
if __name__ == "__main__":
|
||||
n = 1000
|
||||
expected = 500500
|
||||
actual = sum_n(n)
|
||||
is_correct = verify_sum(expected, actual)
|
||||
|
||||
result = f"Sum of 1 to {n}: {actual}\n"
|
||||
result += f"Expected: {expected}\n"
|
||||
result += f"Verified: {is_correct}\n"
|
||||
|
||||
print(result)
|
||||
|
||||
with open("/root/.hermes/wizard-outputs/spark/result.txt", "w") as f:
|
||||
f.write(result)
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test that linecount_pycount.py produces correct output."""
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
def test_linecount():
|
||||
# Test on fibonacci.py which we know has 49 total lines
|
||||
result = subprocess.run(
|
||||
['python3', 'linecount_pycount.py', 'fibonacci.py'],
|
||||
capture_output=True,
|
||||
text=True
|
||||
)
|
||||
|
||||
print("Output:", result.stdout)
|
||||
print("Exit code:", result.returncode)
|
||||
|
||||
# Parse output
|
||||
lines = result.stdout.strip().split('\n')
|
||||
total_line = [l for l in lines if l.startswith('Total lines:')]
|
||||
code_line = [l for l in lines if l.startswith('Python code lines:')]
|
||||
|
||||
assert total_line, "Missing 'Total lines:' output"
|
||||
assert code_line, "Missing 'Python code lines:' output"
|
||||
|
||||
total = int(total_line[0].split(':')[1].strip())
|
||||
code = int(code_line[0].split(':')[1].strip())
|
||||
|
||||
# fibonacci.py has 49 lines, 40 code lines
|
||||
assert total == 49, f"Expected 49 total lines, got {total}"
|
||||
assert code == 40, f"Expected 40 code lines, got {code}"
|
||||
|
||||
print("TEST PASSED: linecount_pycount.py correctly counts lines")
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(test_linecount())
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/bin/env python3
|
||||
import json
|
||||
import sys
|
||||
|
||||
path = '/root/troupe-standup/wizard-work/spark/verification_result_20261025.json'
|
||||
with open(path) as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Verify key fields
|
||||
checks = [
|
||||
('python_version' in data, 'has python_version'),
|
||||
('packages' in data, 'has packages'),
|
||||
('cli_tools' in data, 'has cli_tools'),
|
||||
(data.get('status') == 'verified', 'status is verified'),
|
||||
(data['cli_tools'].get('git', False), 'git available'),
|
||||
(data['cli_tools'].get('python3', False), 'python3 available'),
|
||||
]
|
||||
|
||||
all_passed = all(c[0] for c in checks)
|
||||
for passed, desc in checks:
|
||||
print(f"{'PASS' if passed else 'FAIL'}: {desc}")
|
||||
|
||||
sys.exit(0 if all_passed else 1)
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Quick verification that Python and hermes_tools work."""
|
||||
import sys
|
||||
|
||||
print(f"Python: {sys.version}")
|
||||
|
||||
try:
|
||||
import hermes_tools
|
||||
print("hermes_tools: OK")
|
||||
sys.exit(0)
|
||||
except ImportError as e:
|
||||
print(f"hermes_tools: FAILED - {e}")
|
||||
sys.exit(1)
|
||||
Reference in new issue
Block a user