Skip to main content

X-ray your Python project: import graph + stub maturity metrics + Graphviz viz + CLI

Project description

CodeClinic (codeclinic)

Diagnose your Python project: import dependencies → maturity metrics (stub ratio) → Graphviz visualization.

Install

pip install codeclinic
# or, from source (dev):
pip install -e .

Note: Rendering SVG/PNG requires the Graphviz system tool (dot) in your PATH. macOS: brew install graphviz; Ubuntu: sudo apt-get install graphviz.

Quick start

codeclinic --path ./src --out results

This prints a summary + adjacency list and writes:

  • results/analysis.json (project analysis data)
  • results/stub_report.json (detailed stub function report)
  • results/dependency_graph.dot (DOT source)
  • results/dependency_graph.svg (rendered visualization)

Marking stubs

from codeclinic import stub

@stub
def todo_api():
    pass

@stub will (1) mark the function for static counting and (2) emit a warnings.warn when it’s actually called.

Config

You can keep settings in pyproject.toml under [tool.codeclinic] or in a codeclinic.toml file:

[tool.codeclinic]
paths = ["src"]
include = ["**/*.py"]
exclude = ["**/tests/**", "**/.venv/**"]
aggregate = "package"     # "module" | "package"
format = "svg"            # svg | png | pdf | dot
output = "build/cc_graph"
count_private = false

CLI flags override config.

Output Formats

All-in-One (Default)

codeclinic --path ./src --out results

Generates complete analysis with all output files in a single directory.

JSON Data Only

codeclinic --path ./src --out results --format json

Generates only JSON files (analysis + stub report) without visualization.

Specific Visualization Formats

codeclinic --path ./src --out results --format svg    # SVG visualization
codeclinic --path ./src --out results --format png    # PNG visualization  
codeclinic --path ./src --out results --format pdf    # PDF visualization

Stub Function Reports

The stub_report.json file contains detailed information about all @stub decorated functions:

{
  "metadata": {
    "total_stub_functions": 5,
    "modules_with_stubs": 3,
    "function_stubs": 3,
    "method_stubs": 2
  },
  "stub_functions": [
    {
      "module_name": "myproject.utils",
      "file_path": "/path/to/utils.py", 
      "function_name": "incomplete_feature",
      "full_name": "incomplete_feature",
      "docstring": "This feature is not yet implemented.",
      "is_method": false,
      "class_name": null,
      "graph_depth": 2
    }
  ]
}

Each stub function includes:

  • File location and module information
  • Function/method name with full qualified name (e.g., ClassName.method_name)
  • Docstring extracted from the function
  • Graph depth - dependency level for implementation prioritization
  • Method classification - whether it's a standalone function or class method

CLI

codeclinic --path PATH [--out OUTPUT_DIR] [--format svg|png|pdf|dot|json] [--aggregate module|package]

How it works

  • Parses your code with ast (no import-time side effects).
  • Builds an internal import graph (absolute & relative imports resolved).
  • Counts public functions/methods and @stub-decorated ones to compute a stub ratio per node.
  • Renders a Graphviz graph with node colors by ratio (green→yellow→red).

Roadmap

  • Smell detectors (circulars, forbidden deps, god packages, layer rules).
  • HTML/PDF report with dashboards.
  • Plugin entry points: codeclinic.detector.

License

MIT

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

codeclinic-0.1.3b2.tar.gz (36.9 kB view details)

Uploaded Source

Built Distribution

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

codeclinic-0.1.3b2-py3-none-any.whl (44.7 kB view details)

Uploaded Python 3

File details

Details for the file codeclinic-0.1.3b2.tar.gz.

File metadata

  • Download URL: codeclinic-0.1.3b2.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codeclinic-0.1.3b2.tar.gz
Algorithm Hash digest
SHA256 d981c2ff2d3ef01d8c95ccfecdf36f56c0eca7f962712d2e71d759da7f2ced14
MD5 6ce2f027be90da0de82aebeb60dbcdde
BLAKE2b-256 d94743e37e9ac8864fe46a5140ef905f9d7077e5b0e75b2f78a3d520d29297f1

See more details on using hashes here.

File details

Details for the file codeclinic-0.1.3b2-py3-none-any.whl.

File metadata

  • Download URL: codeclinic-0.1.3b2-py3-none-any.whl
  • Upload date:
  • Size: 44.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for codeclinic-0.1.3b2-py3-none-any.whl
Algorithm Hash digest
SHA256 b2cb3fb2accaab81dda2b5d88a0083f5ac121a1124e6337ff09f608a8a8d313f
MD5 670ad945f8df42c33f5f6a126148f69a
BLAKE2b-256 711026111a018c9461d03abed5ba707518f600f6881161451aad780619bc1eb6

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