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 A hardened diagnostic tool for deep, automated import analysis in Python projects. It features subprocess-safe imports, circular dependency detection, auto-fix suggestions, AST-based symbol resolution, and CI-ready JSON output.


๐Ÿš€ Quick Start (User View):

Prerequisites

  • Python 3.10+
  • jsonschema
  • tqdm
  • rich

One-Command Installation

pip install importdoc

Usage Example

importdoc your_package

โœจ Key Features

  • ๐Ÿ” Import graph discovery: Recursively maps and validates imports across a project.
  • ๐Ÿง  AST-based analysis: Detects missing imports, wrong module paths, and unresolved symbols.
  • โšก Subprocess safe imports: Imports each module in a sandboxed subprocess, making it timeout-safe.
  • ๐Ÿ›‘ Circular import detection: Identifies dependency cycles with detailed stack traces.
  • ๐Ÿ› ๏ธ Automated fix suggestions: Suggests proper import paths and generates JSON patches for auto-fixing.
  • ๐Ÿ“Š JSON diagnostic mode: Provides CI-friendly structured reports for easy integration.
  • ๐Ÿ“ฆ Cache & telemetry: Includes an optional cache and performance metrics to speed up subsequent runs.
  • ๐Ÿ›ก๏ธ Safe mode: Avoids dangerous imports outside the virtual environment by default.
  • ๐Ÿ“ˆ Graph export: Generates a DOT dependency graph for visualization with Graphviz.
  • Enhanced no module named diagnosis: God Level Parses import symbols from the AST to suggest correct paths based on symbol definitions, providing more accurate and actionable insights.

๐Ÿงช Example Output (Success)

๐ŸŽ‰ ALL MODULES IMPORTED SUCCESSFULLY! โœจ Production-ready: No import issues detected

๐Ÿšจ Example Output (Import Error)

๐Ÿšจ FAILED TO IMPORT: myapp.models.user ๐Ÿ”ฅ ROOT CAUSE: ImportError: cannot import name 'Profile' from 'myapp.profile' ๐Ÿ“Š Evidence:

  • myapp/profile.py:15: class Profile ๐Ÿ’ก Suggested Fixes:
  1. from myapp.profile import Profile ๐Ÿง  Confidence: 9/10

โš™๏ธ Configuration & Advanced Usage (Dev View)

CLI/API Table

Argument Description Default
package The root package to diagnose. N/A
--dir The directory of the package, which adds the parent to sys.path. N/A
--continue-on-error Continues the diagnosis even after encountering errors. False
--dry-run Discovers modules without actually importing them. False
--max-depth The maximum depth for module discovery. N/A
--log-file The path to the log file. N/A
--verbose Enables detailed and extensive output. False
--quiet Minimizes the output to only essential information. False
--no-emoji Disables the use of emojis in the output. False
--timeout The timeout in seconds for each import. 0
--unload Unloads modules after they are imported. False
--json Outputs the diagnosis in JSON format. False
--parallel The number of parallel imports to run. 0
--dev-mode Enables developer mode for additional diagnostics. False
--dev-trace Traces the import chains for debugging. False
--graph Generates a DOT graph of the import dependencies. False
--dot-file The path to the output DOT file. N/A
--allow-root Allows the tool to be run as the root user. False
--show-env Shows the environment variables at the start. False
--enable-telemetry Enables production telemetry for performance tracking. False
--enable-cache Enables caching of results to speed up subsequent runs. False
--generate-fixes Generates automated fixes for import errors. False
--fix-output The output file for the automated fixes in JSON format. N/A
--no-safe-mode Disables safe mode, allowing imports from outside the virtual environment. False
--no-safe-skip Does not auto-skip imports when not in a virtual environment with safe mode active. False
--max-scan-results The maximum number of results for repository scans. 200
--version Shows the version of the tool. N/A

Note: For a full list of options, run importdoc --help.


๐Ÿ—๏ธ Architecture

importdoc/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ importdoc/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ cli.py         # CLI entry point and argument parsing
โ”‚       โ””โ”€โ”€ modules/
โ”‚           โ”œโ”€โ”€ diagnostics.py # Core diagnostic logic
โ”‚           โ””โ”€โ”€ ...        # Other utility modules
โ””โ”€โ”€ pyproject.toml     # Project metadata and dependencies

The core logic resides in src/importdoc/modules/diagnostics.py, which is responsible for import analysis, subprocess management, and report generation. The CLI entry point, src/importdoc/cli.py, handles argument parsing and initializes the diagnostic process.


๐Ÿ—บ๏ธ Roadmap

  • Completed:

    • Subprocess-safe imports
    • Circular dependency detection
    • AST-based symbol resolution
    • Automated fix suggestions
    • CI-ready JSON output
  • Upcoming:

    • Interactive HTML reports
    • Plugin architecture for custom checks
    • Deeper integration with IDEs

๐Ÿ›ก๏ธ CI/CD Usage

GitHub Actions

  • name: Run import diagnostics run: importdoc mypkg --json --continue-on-error > import_report.json

๐Ÿง  When to Use importdoc

Situation importdoc saves you

โ“ Random import failures โœ… Pinpoints real source ๐Ÿ” Circular imports โœ… Finds cycles with stack trace โš™๏ธ Large refactors โœ… Detects broken import paths ๐Ÿค– CI safety โœ… Reports without executing package runtime logic ๐Ÿ“ฆ Package release testing โœ… Ensures import reliability


๐Ÿงฉ Project Structure Example

yourproject/ โ”œโ”€ src/ โ”‚ โ””โ”€ yourpackage/ โ”‚ โ”œโ”€ init.py โ”‚ โ”œโ”€ ... โ””โ”€ tests/

Run:

importdoc yourpackage --dir ./src


๐Ÿค Contributing & License

Contributions are welcome! Please feel free to submit a pull request or open an issue.

This project is licensed under the MIT License. See the LICENSE file for details.


โญ Support

If you find this tool useful:

pip install importdoc

And give the repo a โญ on GitHub!

https://github.com/dhruv13x/importdoc

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-3.0.2.tar.gz (47.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-3.0.2-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for importdoc-3.0.2.tar.gz
Algorithm Hash digest
SHA256 f3558c7b79ed55364460b6e9a63f8d27d1de85c18ea5247c6fb9104f7fa3391e
MD5 ea4c597d21cd2d3533adc9902b8f87b3
BLAKE2b-256 4525a35863bafb714f86320e6aa4fe52e06e818cb16589450590ea69915d2593

See more details on using hashes here.

Provenance

The following attestation bundles were made for importdoc-3.0.2.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-3.0.2-py3-none-any.whl.

File metadata

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

File hashes

Hashes for importdoc-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5649a9e788b3e491020e9b0173e854ccdaa6f554cfbc685c4fee5f62cd9ca209
MD5 81f69cec8a1afab72d214fefa97622da
BLAKE2b-256 e580fefbe0ed8b08f69a123706fa03cfea16b0c334487bc9360301795db1fe1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for importdoc-3.0.2-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