Advanced Python import diagnostic tool with deep analysis, subprocess isolation, auto-fixing suggestions, and CI-ready enforcement.
Project description
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
- CLI: Parses arguments and loads configuration.
- Discovery: Scans the file system to find all Python modules in the target package.
- Runner: Iterates through discovered modules, spawning isolated subprocesses to import them safely.
- Analysis: Captures stdout/stderr from subprocesses. If an import fails,
analysis.pyinspects the error and AST to determine the root cause (e.g., circular dependency, missing symbol). - 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
-
Clone the repository:
git clone https://github.com/dhruv13x/importdoc.git cd importdoc
-
Install dependencies:
pip install .[dev]
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e9945b108cb7f971379a0f7bf200b49d6325b59ba285c43ec1eb6c1523ee5013
|
|
| MD5 |
68bfa6315325dd1b9cbf00292f3a4ece
|
|
| BLAKE2b-256 |
28aeb7e8dc712cde9470240ac05f310a334ea547966bcb35df572c27598978dc
|
Provenance
The following attestation bundles were made for importdoc-4.0.1.tar.gz:
Publisher:
publish.yml on dhruv13x/importdoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
importdoc-4.0.1.tar.gz -
Subject digest:
e9945b108cb7f971379a0f7bf200b49d6325b59ba285c43ec1eb6c1523ee5013 - Sigstore transparency entry: 764297144
- Sigstore integration time:
-
Permalink:
dhruv13x/importdoc@800c0e3ce40fc92af059139d2bdc1c35e8ab6129 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@800c0e3ce40fc92af059139d2bdc1c35e8ab6129 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5500aafaeda3061ea0939952da35d8af3f776614de4bba612caf2b8628b3f29
|
|
| MD5 |
2a5b1be7fe159c0549367af2334ddadc
|
|
| BLAKE2b-256 |
30edc2fe0f9a22cea74b316c244574ce8069fbdc386d00c408297eb5dc930033
|
Provenance
The following attestation bundles were made for importdoc-4.0.1-py3-none-any.whl:
Publisher:
publish.yml on dhruv13x/importdoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
importdoc-4.0.1-py3-none-any.whl -
Subject digest:
b5500aafaeda3061ea0939952da35d8af3f776614de4bba612caf2b8628b3f29 - Sigstore transparency entry: 764297149
- Sigstore integration time:
-
Permalink:
dhruv13x/importdoc@800c0e3ce40fc92af059139d2bdc1c35e8ab6129 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@800c0e3ce40fc92af059139d2bdc1c35e8ab6129 -
Trigger Event:
push
-
Statement type: