Detect circular imports in codebase.
Project description
Circular Imports
If you see an error like this:
ImportError: cannot import name 'some_module'
or
ImportError: cannot import name 'some_module' from partially initialized module 'path.to.module' (most likely due to a circular import)
then you have a circular import in your code.
This library helps you to detect circular imports in Python code to fix them.
Installation
pip install circular-imports
Usage
CLI
Example:
circular-imports path/to/python/project/dir --output output_file.dot --exclude .venv,build
Parameters:
path: path to the Python project directory--output: output file, this can be a.dot,.mermaid. When empty, the output will be printed to the console.--exclude: comma-separated list of directories to exclude from the search
Exits with code 0 if no circular imports are found, 1 otherwise.
Python
from unittest import TestCase
from circular_imports import cycles_in_path
class TestCircularDeps(TestCase):
def test_no_cycles(self):
cycles = cycles_in_path(".", exclude=".venv,build")
self.assertEqual(cycles, set())
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
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 circular_imports-0.1.4.tar.gz.
File metadata
- Download URL: circular_imports-0.1.4.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ffad43190fc60c2bd8f8d01aaf4b79f4218317b171b38e062888e3768130a15
|
|
| MD5 |
8b84b77841147315313af581c594fadc
|
|
| BLAKE2b-256 |
152d681cfa7ee4cf20ac76fcba358d1546d3d2fc3b3cd92197f1fd68ac22cdb4
|
File details
Details for the file circular_imports-0.1.4-py3-none-any.whl.
File metadata
- Download URL: circular_imports-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b98b73289982483a8563b58c05de1fda8d237c130a64d277e91281e211773c19
|
|
| MD5 |
376cc8f94186d0d1ddf2e3c29a053746
|
|
| BLAKE2b-256 |
77a92e78030fd59aa7d0077105dbb987d6aaecb3a1d9427990c15a2b37107daa
|