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.3.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.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: circular_imports-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 05b4ef2c22a1389e13c3bce26d1c42b126197a4bc4135e3a6909924e31d1f6b0
MD5 74a6e230d0e3657316d70e32bf32b6d2
BLAKE2b-256 224d71e274bbb01f5289ed757328baaf1964cab79438aa87c75ffc8a4d2bb7f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for circular_imports-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 365aa5eadcb105b11996990c66bef78fbbe8a35ce6502dd041140fe3448d2842
MD5 d60112339873e4acd12d22cd9f0e3537
BLAKE2b-256 65b3a016a65d62aa234e28091e2cf0afa50fdf5688c3d59cbd98d18cde428767

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