Cyclopy is a fast import-cycle checker for Python, written in OCaml. It detects circular dependencies in your Python projects, which can lead to hard-to-debug issues and unpredictable behavior.
- Fast detection of circular imports in Python projects
- Clear visualization of import cycles
- Easy to install and use (TODO)
Cyclopy analyzes your Python files to extract import statements, builds a directed graph of dependencies, and then detects cycles in this graph. It uses OCaml's speed and strong type system to provide fast and reliable results.
- OCaml (recommended version 4.14.0 or newer)
- opam (OCaml package manager)
- dune (OCaml build system)
- Clone the repository:
git clone https://github.com/yourusername/cyclopy.git
cd cyclopy- Create a local switch for the project:
opam switch create . --deps-only ocaml-base-compiler.5.0.0
eval $(opam env)- Install dependencies:
make install_dev- Build the project:
dune buildRun Cyclopy by specifying the entry point of your Python project:
dune exec -- circular_imports /path/to/your/project/main.pyFor instance:
dune exec -- circular_imports data/fixtures/main.pyFor verbose output, add the -v flag:
dune exec -- circular_imports -v /path/to/your/project/main.pyWhen circular imports are found:
Found 3 circular import chain(s):
__init__ -> main -> __init__
main -> c -> main
main -> b -> c -> main
If you installed the doc dependencies, you can generate the documentation through
opam exec -- dune build @docand open the documentation using
open _build/default/_doc/_html/index.htmlSimply change the depends stanza in dune-project, and update the lockfile:
dune pkg lockLastly, sync the .opam file:
dune build circular_imports.opamContributions are welcome! Please feel free to submit a Pull Request.
This README provides clear installation instructions with local switch setup, usage examples, and a brief explanation of how the tool works. It also includes sections for features, contributing, and licensing information.