Skip to main content

Advanced Python import diagnostic tool with deep analysis, subprocess isolation, auto-fixing suggestions, and CI-ready enforcement.

Project description

importdoc logo

PyPI version Python Wheel Release

Build status Codecov Test Coverage Code style: black Ruff Security

Downloads OS Python Versions

License: MIT

Docs

importdoc

Production-Ready Import Diagnostic Tool for Python

Advanced Python import diagnostic tool with deep analysis, subprocess isolation, auto-fixing suggestions, and CI-ready enforcement.


⚡ Quick Start (The "5-Minute Rule")

Prerequisites

  • Python: 3.10+
  • Dependencies: jsonschema, tqdm, rich (installed automatically)

Install

pip install importdoc

Run

To start diagnosing your package immediately:

importdoc <your_package_name>

Demo

Copy and paste this snippet to audit your package and generate a visual report:

# Install importdoc
pip install importdoc

# Run a full diagnostic check with verbose output
importdoc my_awesome_package --verbose

# Generate an interactive HTML graph of your import structure
importdoc my_awesome_package --html

✨ Features

Core Capabilities

  • Import Graph Discovery: Recursively maps and validates imports across your entire project.
  • Subprocess Isolation: Imports each module in a sandboxed subprocess to prevent crashes and ensure timeout safety.
  • Circular Dependency Detection: Identifies dependency cycles with detailed stack traces.

Performance & Security

  • Smart Caching: Speeds up subsequent runs by caching analysis results (--enable-cache).
  • Parallel Execution: runs imports in parallel for large codebases (--parallel).
  • Safe Mode: Enforces execution within a virtual environment to prevent system pollution.

Advanced Analysis

  • Auto-Fix Suggestions: Suggests proper import paths and generates JSON patches for auto-fixing errors.
  • AST-Based Resolution: "God Level" analysis parses source code to find undefined symbols and correct import paths.
  • Interactive Reports: Generates self-contained HTML reports for exploring import graphs visually.
  • CI-Ready JSON: Provides structured JSON output for easy integration with CI/CD pipelines.

🛠️ Configuration

You can configure importdoc using CLI arguments or a configuration file (pyproject.toml or .importdoc.rc).

CLI Arguments

Argument Description Default
package The root package to diagnose. Required
--dir The directory of the package (adds parent to sys.path). None
--config Path to config file (implicit: pyproject.toml or .importdoc.rc). Auto
--verbose Enables detailed and extensive output. False
--json Outputs the diagnosis in JSON format. False
--html Generates an interactive HTML report. False
--graph Generates a DOT graph of import dependencies. False
--dot-file Path to the output DOT file. None
--timeout Timeout in seconds for each import. 0 (None)
--parallel Number of parallel imports to run. 0 (Sequential)
--enable-cache Enables caching of results. False
--generate-fixes Generates automated fixes for import errors. False
--fix-output Output file for automated fixes (JSON). None
--continue-on-error Continues diagnosis even after encountering errors. False
--dry-run Discovers modules without actually importing them. False
--dev-mode Enables developer mode for additional diagnostics. False

Configuration File (pyproject.toml)

You can persist your configuration in pyproject.toml under the [tool.importdoc] section:

[tool.importdoc]
verbose = true
timeout = 5
enable_cache = true
exclude_patterns = ["tests/*", "migrations/*"]

🏗️ Architecture

Directory Tree

src/
└── importdoc/
    ├── cli.py             # CLI Entry Point
    ├── banner.py          # Logo & Branding
    └── modules/
        ├── diagnostics.py # Core Controller (Orchestrator)
        ├── discovery.py   # File & Module Discovery
        ├── runner.py      # Subprocess Execution Logic
        ├── analysis.py    # AST & Error Analysis
        ├── reporting.py   # JSON/HTML/Console Output
        ├── config.py      # Configuration Loader
        ├── cache.py       # Caching Mechanism
        ├── autofix.py     # Fix Generation Logic
        └── ...

High-Level Flow

  1. CLI: Parses arguments and loads configuration.
  2. Discovery: Scans the file system to find all Python modules in the target package.
  3. Runner: Iterates through discovered modules, spawning isolated subprocesses to import them safely.
  4. Analysis: Captures stdout/stderr from subprocesses. If an import fails, analysis.py inspects the error and AST to determine the root cause (e.g., circular dependency, missing symbol).
  5. Reporting: Aggregates results and outputs them to the console, JSON file, or HTML report.

🐞 Troubleshooting

Common Issues

Error Message Possible Cause Solution
ModuleNotFoundError The package root is not in sys.path. Use the --dir argument to specify the package location.
ImportError: cannot import name... Circular dependency or wrong path. Run with --graph to visualize cycles or --generate-fixes to see suggestions.
TimeoutError Module takes too long to import. Increase the timeout using --timeout <seconds>.
PermissionError Running as root (not recommended). Use --allow-root if absolutely necessary.

Debug Mode

If you are facing unexpected behavior, enable verbose logging and developer traces:

importdoc my_package --verbose --dev-mode --dev-trace

🤝 Contributing

We welcome contributions! Please check out our CONTRIBUTING.md (if available) or follow the steps below.

Dev Setup

  1. Clone the repository:

    git clone https://github.com/dhruv13x/importdoc.git
    cd importdoc
    
  2. Install dependencies:

    pip install .[dev]
    
  3. Run Tests:

    python -m pytest
    

🗺️ Roadmap

We are constantly improving importdoc. Here is a glimpse of what's coming:

  • Phase 1 (Done): Subprocess isolation, Circular dependency detection, JSON/HTML output.
  • Phase 2 (Current): Performance optimization (Caching, Parallelism), Configuration files.
  • Phase 3 (Next): Plugin architecture, IDE integrations (VS Code), GitHub Actions support.
  • Phase 4 (Vision): AI-powered architectural refactoring and predictive dependency analysis.

See ROADMAP.md for the full detailed plan.

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

importdoc-4.0.1.tar.gz (55.0 kB view details)

Uploaded Source

Built Distribution

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

importdoc-4.0.1-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

Details for the file importdoc-4.0.1.tar.gz.

File metadata

  • Download URL: importdoc-4.0.1.tar.gz
  • Upload date:
  • Size: 55.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for importdoc-4.0.1.tar.gz
Algorithm Hash digest
SHA256 e9945b108cb7f971379a0f7bf200b49d6325b59ba285c43ec1eb6c1523ee5013
MD5 68bfa6315325dd1b9cbf00292f3a4ece
BLAKE2b-256 28aeb7e8dc712cde9470240ac05f310a334ea547966bcb35df572c27598978dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for importdoc-4.0.1.tar.gz:

Publisher: publish.yml on dhruv13x/importdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file importdoc-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: importdoc-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 40.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for importdoc-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5500aafaeda3061ea0939952da35d8af3f776614de4bba612caf2b8628b3f29
MD5 2a5b1be7fe159c0549367af2334ddadc
BLAKE2b-256 30edc2fe0f9a22cea74b316c244574ce8069fbdc386d00c408297eb5dc930033

See more details on using hashes here.

Provenance

The following attestation bundles were made for importdoc-4.0.1-py3-none-any.whl:

Publisher: publish.yml on dhruv13x/importdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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