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 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

circular_imports-0.2.0.tar.gz (4.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.2.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: circular_imports-0.2.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for circular_imports-0.2.0.tar.gz
Algorithm Hash digest
SHA256 03db8a9b1fa6bcecac0a725c3d9f3d925c8211859af19bec72a016e52a79ae2f
MD5 8f0aa21806c62a1efc1c6819d5767357
BLAKE2b-256 1e4a687345c6d400bbb1f2e9c6011fd134ae9609283ed298190c625fdf5dcdc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for circular_imports-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3187ec310244b895017bf92c178b255893da6141299d31b89c2a152d2c2a75d6
MD5 03efdcc38b717061a66146bbca9ac465
BLAKE2b-256 4512dffbc517f6608e7b1d8f06257e84a366cd3be18163e48c7980a4d626b9fc

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