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 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+
jsonschematqdmrich
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 nameddiagnosis: 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:
- 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!
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-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3558c7b79ed55364460b6e9a63f8d27d1de85c18ea5247c6fb9104f7fa3391e
|
|
| MD5 |
ea4c597d21cd2d3533adc9902b8f87b3
|
|
| BLAKE2b-256 |
4525a35863bafb714f86320e6aa4fe52e06e818cb16589450590ea69915d2593
|
Provenance
The following attestation bundles were made for importdoc-3.0.2.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-3.0.2.tar.gz -
Subject digest:
f3558c7b79ed55364460b6e9a63f8d27d1de85c18ea5247c6fb9104f7fa3391e - Sigstore transparency entry: 725378223
- Sigstore integration time:
-
Permalink:
dhruv13x/importdoc@d1cfe431973025e2bf207e017a1f6ea3c5bfa0aa -
Branch / Tag:
refs/tags/v3.0.2 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d1cfe431973025e2bf207e017a1f6ea3c5bfa0aa -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5649a9e788b3e491020e9b0173e854ccdaa6f554cfbc685c4fee5f62cd9ca209
|
|
| MD5 |
81f69cec8a1afab72d214fefa97622da
|
|
| BLAKE2b-256 |
e580fefbe0ed8b08f69a123706fa03cfea16b0c334487bc9360301795db1fe1b
|
Provenance
The following attestation bundles were made for importdoc-3.0.2-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-3.0.2-py3-none-any.whl -
Subject digest:
5649a9e788b3e491020e9b0173e854ccdaa6f554cfbc685c4fee5f62cd9ca209 - Sigstore transparency entry: 725378227
- Sigstore integration time:
-
Permalink:
dhruv13x/importdoc@d1cfe431973025e2bf207e017a1f6ea3c5bfa0aa -
Branch / Tag:
refs/tags/v3.0.2 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d1cfe431973025e2bf207e017a1f6ea3c5bfa0aa -
Trigger Event:
push
-
Statement type: