Skip to main content

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 circular_imports import cycles_in_path

circular_imports = cycles_in_path('path/to/python/project/dir')
print(circular_imports)

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

circular_imports-0.0.7.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

circular_imports-0.0.7-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file circular_imports-0.0.7.tar.gz.

File metadata

  • Download URL: circular_imports-0.0.7.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for circular_imports-0.0.7.tar.gz
Algorithm Hash digest
SHA256 d129cbc2cf07578bb0b57c7cd3e2d9d231d04c08eb86e1cb73594e7d47d6398e
MD5 e1fd3c21bda8d3a3dd22415fcd4429d2
BLAKE2b-256 bd5e116c85772d6e67a0d22870d2b1bd5ac4f3f4ffa6feb970a22d134c0a9cd9

See more details on using hashes here.

File details

Details for the file circular_imports-0.0.7-py3-none-any.whl.

File metadata

File hashes

Hashes for circular_imports-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 00e2a4653f3fc2b28ff34d2ebb80ef4f591ee73c4ae6788c6adf021af64134b8
MD5 c29bac1f70fe5bcbf95672165d4e346e
BLAKE2b-256 88485fa039dab0ae744294a5e76c1c0bff0036847c543595278c91f812ca0e5c

See more details on using hashes here.

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