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

Uploaded Python 3

File details

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

File metadata

  • Download URL: circular_imports-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 57fdb22a772646340efdcd9d12592afd5bd4631cd22e4d8df41035547ce7c44d
MD5 982898612fb4293c6489c9481bb7be4a
BLAKE2b-256 9a4c19ef0ecce08d4a8fea498f2dbb36b6fbbce345a10328a20494ecf33ae6ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for circular_imports-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8bbb13c9b73150711b2cca6a0c735f155e9788bf67c9b93bf20c66165068b033
MD5 2c375aa3afd452f88f48d49a646616f1
BLAKE2b-256 ac584d8feb62be7cdd0185697c0bd7aff909a866b52cb7d65f98da7d0137c78f

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