You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extract error handling patterns into utility functions
Create single source of truth for PK detection
Extract column mapping logic into reusable function
Create validation utility module
Add tests for utility functions
Project Hygiene (P0)
Implement automatic backup cleanup (max 5 files)
Add cleanup command for temporary files
Update .gitignore with Python cache directories
Add .gitignore for coverage reports
Clean up empty __init__.py files
Remove orphaned temporary files
Code Organization (P1)
Create excel_to_sql/utils/ for utilities
Organize modules by responsibility
Remove empty or redundant files
Add module docstrings
Proposed Solutions
1. Error Handling Utilities
Create excel_to_sql/utils/errors.py:
"""Error handling utilities."""frompathlibimportPathfromtypingimportOptionalfromrich.consoleimportConsoleconsole=Console()
defhandle_file_error(
error: Exception,
file_path: Path,
context: str="operation"
) ->None:
"""Handle file-related errors consistently. Args: error: The exception that occurred file_path: Path to the file being processed context: Description of the operation """ifisinstance(error, FileNotFoundError):
console.print(f"[red]Error:[/red] File not found: {file_path}")
console.print(f"[dim]Context: {context}[/dim]")
raiseSystemExit(1)
elifisinstance(error, PermissionError):
console.print(f"[red]Error:[/red] Permission denied: {file_path}")
console.print("[dim]Tip: Check file permissions[/dim]")
raiseSystemExit(1)
else:
console.print(f"[red]Error:[/red] {error}")
raiseSystemExit(1)
2. Backup Cleanup
Option A: Automatic Cleanup
# In AutoFixer or backup creationdef_cleanup_old_backups(backup_dir: Path, max_backups: int=5) ->None:
"""Remove old backup files, keeping only the most recent max_backups."""backups=sorted(backup_dir.glob("*.xlsx.bak"),
key=lambdap: p.stat().st_mtime,
reverse=True)
forold_backupinbackups[max_backups:]:
old_backup.unlink()
Refactor: Fix Code Duplication and Project Hygiene Issues
Problem Description
The codebase contains duplicated code logic and project hygiene issues that impact maintainability and leave temporary files behind.
1. Code Duplication
1.1 Error Handling Patterns
Locations: Throughout
cli.pyDuplicated Code:
Impact:
1.2 Primary Key Detection Logic
Locations:
cli.py- Magic commandauto_pilot/detector.py- PatternDetectorDuplicated Code:
Impact:
1.3 Column Mapping Logic
Locations:
cli.py- Magic command configuration generationImpact:
2. Project Hygiene Issues
2.1 Temporary Files Not Cleaned Up
Issue:
.excel-to-sql/backups/directory accumulates backup filesCurrent State:
Impact:
Example:
2.2 Gitignore Gaps
Current State:
__pycache__/)htmlcov/)Impact:
2.3 Inconsistent File Organization
Issues:
config/__init__.pyAcceptance Criteria
Code Deduplication (P0)
Project Hygiene (P0)
__init__.pyfilesCode Organization (P1)
excel_to_sql/utils/for utilitiesProposed Solutions
1. Error Handling Utilities
Create
excel_to_sql/utils/errors.py:2. Backup Cleanup
Option A: Automatic Cleanup
Option B: Cleanup Command
3. Gitignore Improvements
Add to
.gitignore:4. Service Layer Architecture
Create
excel_to_sql/services/:import_service.py- Import business logicexport_service.py- Export business logicvalidation_service.py- Validation utilitiesBenefits:
Implementation Plan
Phase 1: Extract Utilities (P0)
excel_to_sql/utils/directoryPhase 2: Refactor CLI (P0)
Phase 3: Project Hygiene (P0)
Phase 4: Reorganization (P1)
Code Duplication Examples
Before Duplication
Location: cli.py (multiple places)
After Extraction
Utility function:
Usage:
Testing Requirements
Duplication Tests
Hygiene Tests
Benefits
Maintainability
Code Quality
User Experience
Breaking Changes
None. Internal refactoring only.
Migration Guide
For Developers
Before:
After (if moving modules):
Most refactoring is internal and won't affect public APIs.
Dependencies
No new dependencies required.
Related Issues
Files to Create
excel_to_sql/utils/(new directory)excel_to_sql/utils/__init__.pyexcel_to_sql/utils/errors.pyexcel_to_sql/utils/validation.pytests/test_utils.pyFiles to Modify
excel_to_sql/cli.py- Use utilities, reduce duplicationexcel_to_sql/auto_pilot/- Use shared utilitiestests/conftest.py- Add utility fixtures.gitignore- Add more patternsSuccess Metrics
Estimated Impact
Code Reduction
Maintenance
Disk Space