As a masochist, I am never satisfied with a project until I reach perfection.
To me, perfection is so far beyond running correctly or achieving 0 problems across all files in a directory.
Although I've never actually achieved the elusive "perfect" finish line in any project ever, so I can't be sure about the definition.
It's also just what happens when you're experimenting. When you're deep in research, you're iterating in a vacuum; by the time something works, you've rewritten it five times. Therefore, I unsurprisingly constantly have at least a few iterations of the same project on my local machine that I'm actively making more refinements to at all times.
This can cause confusion (shocker!), especially because I am reluctant to push or publish incomplete or "inadequate" code. I also have a fear of being perceived—and what's more vulnerable than my code?
"For when your code is too chaotic for flake8 and too personal for git push."
Just like that, a vicious cycle is born.
An unproductive, deeply confusing, memory-consuming vicious cycle.
Unfortunately the cycle is much harder to follow when there are dozens of moving parts in dozens of subfolders, each with (dozens) of lengthy scripts. You could feed your directory setup as context in an attempt to gain some clarity, but that's a gamble that backfires 9 times out of 10. Has any LLM ever in all of human history actually internalized any tree structure to assist you in reorganizing a repo? Yeah, I didn't think so. Not for me either. So if a vicious cycle is now my daily routine, at a certain point I decided to give myself the illusion of respite, however brief. This has given me solace at least once. Enjoy!
"If Git is for branches, this is for forks of forks."
-
Full file and definition level metadata
Class/function blocks, line counts, docstrings, decorators, async flags, calls, type hints -
Intelligent Code Normalization
Standardizes variable names, function signatures, and code structure for better comparison -
Advanced Variant Detection & Merging
Automatically identifies and merges similar code blocks with semantic analysis -
Auto-patching System
Safely applies merged variants with automatic backup creation -
Function/class SHA-256 hashes
Detects variants, clones, and partial rewrites across versions -
Cyclomatic complexity & maintainability index analysis (via
radon
)
Flags "at-risk" code with CC > 10 or MI < 65 -
Auto-generated LLM refactor prompts
Variant grouping, inline diffs, rewrite guidance -
Internal dependency graph
Outputs a Graphviz.dot
of all intra-project imports -
Markdown summary
Skimmable digest with risk flags and structure -
Interactive Dashboard
Visual analysis of code complexity, variants, and dependencies -
CLI flexibility
Exclusion patterns, Git SHA tagging, output formatting, variant merging controls
- Python 3.8+
- (Optional) Graphviz for dependency visualization
You can install code-cartographer directly from PyPI:
pip install code-cartographer
For development installation:
- Clone the Repository
git clone https://github.com/stochastic-sisyphus/code-cartographer.git
cd code-cartographer
- Create Virtual Environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
- Install in Development Mode
pip install -e ".[dev]"
The code-cartographer package provides tools for analyzing Python codebases:
from code_cartographer import ProjectAnalyzer, VariantAnalyzer
# Initialize analyzers
project_analyzer = ProjectAnalyzer("/path/to/your/project")
variant_analyzer = VariantAnalyzer()
# Run analysis
analysis_results = project_analyzer.analyze()
variant_results = variant_analyzer.analyze(analysis_results)
# Generate reports
project_analyzer.generate_markdown("analysis.md")
project_analyzer.generate_dependency_graph("dependencies.dot")
from code_cartographer import ProjectAnalyzer
analyzer = ProjectAnalyzer(
project_dir="/path/to/project",
exclude_patterns=["tests/.*", "build/.*"]
)
# Run analysis
results = analyzer.analyze()
# Generate reports
analyzer.generate_markdown("summary.md")
analyzer.generate_dependency_graph("deps.dot")
from code_cartographer import VariantAnalyzer
# Initialize analyzer with custom settings
analyzer = VariantAnalyzer(
root="/path/to/project",
semantic_threshold=0.8, # 80% similarity required
min_lines=5 # Minimum lines for variant consideration
)
# Run analysis
results = analyzer.analyze()
# Apply merged variants (with automatic backups)
analyzer.apply_merged_variants(backup=True)
# Analyze and merge variants with backups
code-cartographer variants -d /path/to/project --apply-merges
# Analyze and merge variants without backups
code-cartographer variants -d /path/to/project --apply-merges --no-backup
# Analyze with custom similarity threshold
code-cartographer variants -d /path/to/project --semantic-threshold 0.9
After analysis, you'll find:
analyzed-project/
├── analysis.md # Human-readable summary
├── dependencies.dot # Dependency graph (if Graphviz is installed)
└── variants.md # Code variant analysis report
- Code complexity metrics
- Import dependencies
- Function/class definitions
- Documentation coverage
- Code variants and duplicates
- Semantic similarity scores
from code_cartographer import ProjectAnalyzer
import datetime
# Add to your analysis pipeline
analyzer = ProjectAnalyzer(".")
results = analyzer.analyze()
date_str = datetime.datetime.now().strftime("%Y%m%d")
analyzer.generate_markdown(f"analysis-{date_str}.md")
from code_cartographer import ProjectAnalyzer
# Analyze specific directories with exclusions
analyzer = ProjectAnalyzer(
"src",
exclude_patterns=[
"tests/.*",
"docs/.*",
"*.pyc",
"__pycache__/.*"
]
)
results = analyzer.analyze()
- Reduce analysis scope using exclude patterns
- Process directories sequentially for large projects
- Use the similarity threshold in VariantAnalyzer to limit comparisons
- Focus analysis on specific directories
- Use appropriate similarity thresholds
- Leverage code normalization options
- Ensure Python 3.8+ is being used
- Check file permissions for output directories
- Verify Graphviz installation for dependency graphs
This tool exists to reconcile broken, duplicated, or ghost-forked Python projects. It helps you detect what's salvageable, refactor what's duplicated, and visualize the mess you made.
Whether you're dealing with:
- Fragmented directories
- Local edits lost to time
- Abandoned branches and reanimated scripts
This is for you. Or at least, for the version of you that still wants to fix it.
"Structured remorse for unstructured code."
MIT License. See LICENSE file for details.