https://github.com/abstra-app/python-circular-imports
Detect circular imports in codebase
https://github.com/abstra-app/python-circular-imports
Last synced: 3 months ago
JSON representation
Detect circular imports in codebase
- Host: GitHub
- URL: https://github.com/abstra-app/python-circular-imports
- Owner: abstra-app
- Created: 2024-12-29T18:47:25.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-12-29T20:10:59.000Z (5 months ago)
- Last Synced: 2024-12-29T20:18:14.290Z (5 months ago)
- Language: Python
- Size: 13.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```bash
pip install circular-imports
```## Usage
### CLI
Example:
```bash
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`](https://graphviz.org/docs/layouts/dot/), [`.mermaid`](https://mermaid.js.org/). When empty, the output will be printed to the console.
- `--exclude`: comma-separated list of directories to exclude from the searchExits with code 0 if no circular imports are found, 1 otherwise.
### Python
```python
from unittest import TestCasefrom 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