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.1.1.tar.gz (3.8 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.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: circular_imports-0.1.1.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

Hashes for circular_imports-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ae9cb50617531d3eed64666aab2dc4dd51f9b43669d6bbdda0a5f6f83e6522c5
MD5 f53582fdf29c010e82b414ca829da85c
BLAKE2b-256 c84db8f4e20397f98c13e12f5de5b045a13ff45ef1779647d9e8d40877430979

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for circular_imports-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc9f8430173b53fcacdfdff664324c7cb4fce6804d821fb048b2f316ba363893
MD5 a04ad99b2c3809fea1e7849257324c2e
BLAKE2b-256 ed528afb370d70d1485ff47be84ad841696b2bc64723b906d0dcd6e0e80c274e

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