style: apply black and isort formatting across entire codebase

- Standardize quote style (single to double quotes)
- Reorder and group imports alphabetically
- Fix line breaks and indentation for consistency
- Apply PEP 8 formatting standards

Also updated Makefile to exclude both venv and .venv from code quality checks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-28 19:30:17 +01:00
parent 13f0094743
commit 21c13ca39b
236 changed files with 8450 additions and 6545 deletions

View File

@@ -11,11 +11,11 @@ Usage:
"""
import os
import sys
import subprocess
import sys
from datetime import datetime
from pathlib import Path
from typing import List, Dict
from typing import Dict, List
def count_files(directory: str, pattern: str) -> int:
@@ -26,10 +26,14 @@ def count_files(directory: str, pattern: str) -> int:
count = 0
for root, dirs, files in os.walk(directory):
# Skip __pycache__ and other cache directories
dirs[:] = [d for d in dirs if d not in ['__pycache__', '.pytest_cache', '.git', 'node_modules']]
dirs[:] = [
d
for d in dirs
if d not in ["__pycache__", ".pytest_cache", ".git", "node_modules"]
]
for file in files:
if pattern == '*' or file.endswith(pattern):
if pattern == "*" or file.endswith(pattern):
count += 1
return count
@@ -41,26 +45,26 @@ def get_tree_structure(directory: str, exclude_patterns: List[str] = None) -> st
# Try to use system tree command first
try:
if sys.platform == 'win32':
if sys.platform == "win32":
# Windows tree command
result = subprocess.run(
['tree', '/F', '/A', directory],
["tree", "/F", "/A", directory],
capture_output=True,
text=True,
encoding='utf-8',
errors='replace'
encoding="utf-8",
errors="replace",
)
return result.stdout
else:
# Linux/Mac tree command with exclusions
exclude_args = []
if exclude_patterns:
exclude_args = ['-I', '|'.join(exclude_patterns)]
exclude_args = ["-I", "|".join(exclude_patterns)]
result = subprocess.run(
['tree', '-F', '-a'] + exclude_args + [directory],
["tree", "-F", "-a"] + exclude_args + [directory],
capture_output=True,
text=True
text=True,
)
if result.returncode == 0:
return result.stdout
@@ -71,10 +75,19 @@ def get_tree_structure(directory: str, exclude_patterns: List[str] = None) -> st
return generate_manual_tree(directory, exclude_patterns)
def generate_manual_tree(directory: str, exclude_patterns: List[str] = None, prefix: str = "") -> str:
def generate_manual_tree(
directory: str, exclude_patterns: List[str] = None, prefix: str = ""
) -> str:
"""Generate tree structure manually when tree command is not available."""
if exclude_patterns is None:
exclude_patterns = ['__pycache__', '.pytest_cache', '.git', 'node_modules', '*.pyc', '*.pyo']
exclude_patterns = [
"__pycache__",
".pytest_cache",
".git",
"node_modules",
"*.pyc",
"*.pyo",
]
output = []
path = Path(directory)
@@ -86,7 +99,7 @@ def generate_manual_tree(directory: str, exclude_patterns: List[str] = None, pre
# Skip excluded patterns
skip = False
for pattern in exclude_patterns:
if pattern.startswith('*'):
if pattern.startswith("*"):
# File extension pattern
if item.name.endswith(pattern[1:]):
skip = True
@@ -106,7 +119,9 @@ def generate_manual_tree(directory: str, exclude_patterns: List[str] = None, pre
if item.is_dir():
output.append(f"{prefix}{current_prefix}{item.name}/")
extension = " " if is_last else ""
subtree = generate_manual_tree(str(item), exclude_patterns, prefix + extension)
subtree = generate_manual_tree(
str(item), exclude_patterns, prefix + extension
)
if subtree:
output.append(subtree)
else:
@@ -127,20 +142,36 @@ def generate_frontend_structure() -> str:
# Templates section
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ JINJA2 TEMPLATES ║")
output.append("║ Location: app/templates ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ JINJA2 TEMPLATES ║"
)
output.append(
"║ Location: app/templates ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append(get_tree_structure("app/templates"))
# Static assets section
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ STATIC ASSETS ║")
output.append("║ Location: static ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ STATIC ASSETS ║"
)
output.append(
"║ Location: static ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append(get_tree_structure("static"))
@@ -148,11 +179,21 @@ def generate_frontend_structure() -> str:
if os.path.exists("docs"):
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ DOCUMENTATION ║")
output.append("║ Location: docs ║")
output.append("║ (also listed in tools structure) ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ DOCUMENTATION ║"
)
output.append(
"║ Location: docs ║"
)
output.append(
"║ (also listed in tools structure) ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append("Note: Documentation is also included in tools structure")
output.append(" for infrastructure/DevOps context.")
@@ -160,9 +201,15 @@ def generate_frontend_structure() -> str:
# Statistics section
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ STATISTICS ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ STATISTICS ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append("Templates:")
@@ -174,8 +221,8 @@ def generate_frontend_structure() -> str:
output.append(f" - JavaScript files: {count_files('static', '.js')}")
output.append(f" - CSS files: {count_files('static', '.css')}")
output.append(" - Image files:")
for ext in ['png', 'jpg', 'jpeg', 'gif', 'svg', 'webp', 'ico']:
count = count_files('static', f'.{ext}')
for ext in ["png", "jpg", "jpeg", "gif", "svg", "webp", "ico"]:
count = count_files("static", f".{ext}")
if count > 0:
output.append(f" - .{ext}: {count}")
@@ -200,41 +247,58 @@ def generate_backend_structure() -> str:
output.append("=" * 78)
output.append("")
exclude = ['__pycache__', '*.pyc', '*.pyo', '.pytest_cache', '*.egg-info', 'templates']
exclude = [
"__pycache__",
"*.pyc",
"*.pyo",
".pytest_cache",
"*.egg-info",
"templates",
]
# Backend directories to include
backend_dirs = [
('app', 'Application Code'),
('middleware', 'Middleware Components'),
('models', 'Database Models'),
('storage', 'File Storage'),
('tasks', 'Background Tasks'),
('logs', 'Application Logs'),
("app", "Application Code"),
("middleware", "Middleware Components"),
("models", "Database Models"),
("storage", "File Storage"),
("tasks", "Background Tasks"),
("logs", "Application Logs"),
]
for directory, title in backend_dirs:
if os.path.exists(directory):
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(f"{title.upper().center(62)}")
output.append(f"║ Location: {directory + '/'.ljust(51)}")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append(get_tree_structure(directory, exclude))
# Statistics section
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ STATISTICS ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ STATISTICS ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append("Python Files by Directory:")
total_py_files = 0
for directory, title in backend_dirs:
if os.path.exists(directory):
count = count_files(directory, '.py')
count = count_files(directory, ".py")
total_py_files += count
output.append(f" - {directory}/: {count} files")
@@ -242,11 +306,11 @@ def generate_backend_structure() -> str:
output.append("")
output.append("Application Components (if in app/):")
components = ['routes', 'services', 'schemas', 'exceptions', 'utils']
components = ["routes", "services", "schemas", "exceptions", "utils"]
for component in components:
component_path = f"app/{component}"
if os.path.exists(component_path):
count = count_files(component_path, '.py')
count = count_files(component_path, ".py")
output.append(f" - app/{component}: {count} files")
output.append("")
@@ -264,48 +328,58 @@ def generate_tools_structure() -> str:
output.append("=" * 78)
output.append("")
exclude = ['__pycache__', '*.pyc', '*.pyo', '.pytest_cache', '*.egg-info']
exclude = ["__pycache__", "*.pyc", "*.pyo", ".pytest_cache", "*.egg-info"]
# Tools directories to include
tools_dirs = [
('alembic', 'Database Migrations'),
('scripts', 'Utility Scripts'),
('docker', 'Docker Configuration'),
('docs', 'Documentation'),
("alembic", "Database Migrations"),
("scripts", "Utility Scripts"),
("docker", "Docker Configuration"),
("docs", "Documentation"),
]
for directory, title in tools_dirs:
if os.path.exists(directory):
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(f"{title.upper().center(62)}")
output.append(f"║ Location: {directory + '/'.ljust(51)}")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append(get_tree_structure(directory, exclude))
# Configuration files section
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ CONFIGURATION FILES ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ CONFIGURATION FILES ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append("Root configuration files:")
config_files = [
('Makefile', 'Build automation'),
('requirements.txt', 'Python dependencies'),
('pyproject.toml', 'Python project config'),
('setup.py', 'Python setup script'),
('setup.cfg', 'Setup configuration'),
('alembic.ini', 'Alembic migrations config'),
('mkdocs.yml', 'MkDocs documentation config'),
('Dockerfile', 'Docker image definition'),
('docker-compose.yml', 'Docker services'),
('.dockerignore', 'Docker ignore patterns'),
('.gitignore', 'Git ignore patterns'),
('.env.example', 'Environment variables template'),
("Makefile", "Build automation"),
("requirements.txt", "Python dependencies"),
("pyproject.toml", "Python project config"),
("setup.py", "Python setup script"),
("setup.cfg", "Setup configuration"),
("alembic.ini", "Alembic migrations config"),
("mkdocs.yml", "MkDocs documentation config"),
("Dockerfile", "Docker image definition"),
("docker-compose.yml", "Docker services"),
(".dockerignore", "Docker ignore patterns"),
(".gitignore", "Git ignore patterns"),
(".env.example", "Environment variables template"),
]
for file, description in config_files:
@@ -315,9 +389,15 @@ def generate_tools_structure() -> str:
# Statistics section
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ STATISTICS ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ STATISTICS ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append("Database Migrations:")
@@ -327,7 +407,9 @@ def generate_tools_structure() -> str:
if migration_count > 0:
# Get first and last migration
try:
migrations = sorted([f for f in os.listdir("alembic/versions") if f.endswith('.py')])
migrations = sorted(
[f for f in os.listdir("alembic/versions") if f.endswith(".py")]
)
if migrations:
output.append(f" - First: {migrations[0][:40]}...")
if len(migrations) > 1:
@@ -341,9 +423,9 @@ def generate_tools_structure() -> str:
output.append("Scripts:")
if os.path.exists("scripts"):
script_types = {
'.py': 'Python scripts',
'.sh': 'Shell scripts',
'.bat': 'Batch scripts',
".py": "Python scripts",
".sh": "Shell scripts",
".bat": "Batch scripts",
}
for ext, desc in script_types.items():
count = count_files("scripts", ext)
@@ -356,8 +438,8 @@ def generate_tools_structure() -> str:
output.append("Documentation:")
if os.path.exists("docs"):
doc_types = {
'.md': 'Markdown files',
'.rst': 'reStructuredText files',
".md": "Markdown files",
".rst": "reStructuredText files",
}
for ext, desc in doc_types.items():
count = count_files("docs", ext)
@@ -368,7 +450,7 @@ def generate_tools_structure() -> str:
output.append("")
output.append("Docker:")
docker_files = ['Dockerfile', 'docker-compose.yml', '.dockerignore']
docker_files = ["Dockerfile", "docker-compose.yml", ".dockerignore"]
docker_exists = any(os.path.exists(f) for f in docker_files)
if docker_exists:
output.append(" ✓ Docker configuration present")
@@ -394,25 +476,44 @@ def generate_test_structure() -> str:
# Test files section
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ TEST FILES ║")
output.append("║ Location: tests/ ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ TEST FILES ║"
)
output.append(
"║ Location: tests/ ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
exclude = ['__pycache__', '*.pyc', '*.pyo', '.pytest_cache', '*.egg-info']
exclude = ["__pycache__", "*.pyc", "*.pyo", ".pytest_cache", "*.egg-info"]
output.append(get_tree_structure("tests", exclude))
# Configuration section
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ TEST CONFIGURATION ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ TEST CONFIGURATION ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
output.append("Test configuration files:")
test_config_files = ['pytest.ini', 'conftest.py', 'tests/conftest.py', '.coveragerc']
test_config_files = [
"pytest.ini",
"conftest.py",
"tests/conftest.py",
".coveragerc",
]
for file in test_config_files:
if os.path.exists(file):
output.append(f"{file}")
@@ -420,16 +521,22 @@ def generate_test_structure() -> str:
# Statistics section
output.append("")
output.append("")
output.append("╔══════════════════════════════════════════════════════════════════╗")
output.append("║ STATISTICS ║")
output.append("╚══════════════════════════════════════════════════════════════════╝")
output.append(
"╔══════════════════════════════════════════════════════════════════╗"
)
output.append(
"║ STATISTICS ║"
)
output.append(
"╚══════════════════════════════════════════════════════════════════╝"
)
output.append("")
# Count test files
test_file_count = 0
if os.path.exists("tests"):
for root, dirs, files in os.walk("tests"):
dirs[:] = [d for d in dirs if d != '__pycache__']
dirs[:] = [d for d in dirs if d != "__pycache__"]
for file in files:
if file.startswith("test_") and file.endswith(".py"):
test_file_count += 1
@@ -439,13 +546,13 @@ def generate_test_structure() -> str:
output.append("")
output.append("By Category:")
categories = ['unit', 'integration', 'system', 'e2e', 'performance']
categories = ["unit", "integration", "system", "e2e", "performance"]
for category in categories:
category_path = f"tests/{category}"
if os.path.exists(category_path):
count = 0
for root, dirs, files in os.walk(category_path):
dirs[:] = [d for d in dirs if d != '__pycache__']
dirs[:] = [d for d in dirs if d != "__pycache__"]
for file in files:
if file.startswith("test_") and file.endswith(".py"):
count += 1
@@ -455,12 +562,12 @@ def generate_test_structure() -> str:
test_function_count = 0
if os.path.exists("tests"):
for root, dirs, files in os.walk("tests"):
dirs[:] = [d for d in dirs if d != '__pycache__']
dirs[:] = [d for d in dirs if d != "__pycache__"]
for file in files:
if file.startswith("test_") and file.endswith(".py"):
filepath = os.path.join(root, file)
try:
with open(filepath, 'r', encoding='utf-8') as f:
with open(filepath, "r", encoding="utf-8") as f:
for line in f:
if line.strip().startswith("def test_"):
test_function_count += 1
@@ -494,19 +601,19 @@ def main():
structure_type = sys.argv[1].lower()
generators = {
'frontend': ('frontend-structure.txt', generate_frontend_structure),
'backend': ('backend-structure.txt', generate_backend_structure),
'tests': ('test-structure.txt', generate_test_structure),
'tools': ('tools-structure.txt', generate_tools_structure),
"frontend": ("frontend-structure.txt", generate_frontend_structure),
"backend": ("backend-structure.txt", generate_backend_structure),
"tests": ("test-structure.txt", generate_test_structure),
"tools": ("tools-structure.txt", generate_tools_structure),
}
if structure_type == 'all':
if structure_type == "all":
for name, (filename, generator) in generators.items():
print(f"\n{'=' * 60}")
print(f"Generating {name} structure...")
print('=' * 60)
print("=" * 60)
content = generator()
with open(filename, 'w', encoding='utf-8') as f:
with open(filename, "w", encoding="utf-8") as f:
f.write(content)
print(f"{name.capitalize()} structure saved to {filename}")
print(f"\n{content}\n")
@@ -514,7 +621,7 @@ def main():
filename, generator = generators[structure_type]
print(f"Generating {structure_type} structure...")
content = generator()
with open(filename, 'w', encoding='utf-8') as f:
with open(filename, "w", encoding="utf-8") as f:
f.write(content)
print(f"\n✅ Structure saved to {filename}\n")
print(content)