Skip to main content

A tool for visualizing and analyzing code repositories

Project description

Code Cartographer

Deep Multilayer Static Analyzer for Python Projects


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!


Code Cartographer

"If Git is for branches, this is for forks of forks."


Features

  • Full file and definition level metadata
    Class/function blocks, line counts, docstrings, decorators, async flags, calls, type hints

  • 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, Markdown/Graphviz toggles


Setup & Installation

Prerequisites

  • Python 3.8+
  • (Optional) Graphviz for dependency visualization

Installation

You can install code-cartographer directly from PyPI:

pip install code-cartographer

For development installation:

  1. Clone the Repository
git clone https://github.com/stochastic-sisyphus/code-cartographer.git
cd code-cartographer
  1. Create Virtual Environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install in Development Mode
pip install -e ".[dev]"

Usage Guide

Quick Start

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")

Advanced Usage

1. Deep Code Analysis

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")

2. Code Variant Analysis

from code_cartographer import VariantAnalyzer

analyzer = VariantAnalyzer(
    similarity_threshold=0.7,  # 70% similarity required
    normalize_code=True
)

# Analyze for variants
variants = analyzer.analyze(source_files)

# Get variant groups
groups = analyzer.get_variant_groups()

# Generate comparison report
analyzer.generate_report("variants.md")

Output Structure

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

Key Metrics

  • Code complexity metrics
  • Import dependencies
  • Function/class definitions
  • Documentation coverage
  • Code variants and duplicates
  • Semantic similarity scores

Best Practices

1. Regular Analysis

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")

2. Large Projects

from code_cartographer import ProjectAnalyzer

# Analyze specific directories with exclusions
analyzer = ProjectAnalyzer(
    "src",
    exclude_patterns=[
        "tests/.*",
        "docs/.*",
        "*.pyc",
        "__pycache__/.*"
    ]
)
results = analyzer.analyze()

Troubleshooting

Memory Issues

  • Reduce analysis scope using exclude patterns
  • Process directories sequentially for large projects
  • Use the similarity threshold in VariantAnalyzer to limit comparisons

Performance Tips

  • Focus analysis on specific directories
  • Use appropriate similarity thresholds
  • Leverage code normalization options

Common Issues

  • Ensure Python 3.8+ is being used
  • Check file permissions for output directories
  • Verify Graphviz installation for dependency graphs

Author Notes

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."


License

MIT License. See LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_cartographer-0.1.7.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_cartographer-0.1.7-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file code_cartographer-0.1.7.tar.gz.

File metadata

  • Download URL: code_cartographer-0.1.7.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.18

File hashes

Hashes for code_cartographer-0.1.7.tar.gz
Algorithm Hash digest
SHA256 61354f00f4b6df2c3ee0896f7c74547d31415d49abd7637c7c3a734c0ba6904f
MD5 6b2207fee4b9ac7279f906dc67a34fe4
BLAKE2b-256 c77b50a432b82ef659883cbc69aec79a153c0b782387b37362c878af0f8bc6fe

See more details on using hashes here.

File details

Details for the file code_cartographer-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for code_cartographer-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 130ebcb5fbbff18241715b92b79990f027148fed68e294711c0e4fa69eac46cc
MD5 05fa7f6d1975c2c5e497041e03eab276
BLAKE2b-256 b8ff481888904aa47bf5f848719d4ed1900f91bb6d852ac2f8d98f19e98431e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page