#python #circular #find #cli #imports #module #toml

app marui

Find circular imports in a Python project

3 unstable releases

0.2.0 Mar 22, 2023
0.1.1 Feb 24, 2023
0.1.0 Feb 24, 2023

#2269 in Development tools

44 downloads per month

MIT license

18KB
347 lines

marui - Find circular imports in Python projects.

Crate

At work I work with a relatively large Python code base. Sometimes I find myself accidentally adding circular dependencies between modules. This leads to the classical

ImportError: cannot import name 'A' from partially initialized module 'B'

marui mitigates this problem by finding circular imports before you run your CI suite.

Usage

In a Python project (characterized by a pyproject.toml being present), simply run

$ marui .

Limitations

In its current version (0.2.0), marui can only find imports from within project that are imported with their fully qualified path. For example, if you have a project structure like this:

.
├── pyproject.toml
├── my_package 
│   ├── a
│   │   ├── __init__.py
│   │   └── b.py
│   └── c
│       ├── __init__.py
│       └── d.py
└── ...

b.py can import d.py as

import my_package.c.d 

but as not as

import c.d

This will be addressed in the next version.

Installation

If you have cloned this repository, build and install marui with cargo:

$ gh repo clone jan-krecke/marui
$ cd marui
$ cargo install --path .

Alternatively, just get marui directly from crates.io:

$ cargo install marui

Feeback and contribution

If you want to use this tool and find any problems, feel free to open a PR or an issue :-).

Dependencies

~3MB
~61K SLoC