Skip to content

ouro is a Python package that checks your code for circular (cyclic) imports.

License

Notifications You must be signed in to change notification settings

abdelrahman0w/ouro

Repository files navigation

Ouro

python ouro license tox pre-commit code-quality pypi-version pypi-downloads

Description

OURO (OUROboros) is a Python package that checks your code for circular (cyclic) imports.

Currently, ouro only supports absolute imports

Name Origin

The name "ouro" is derived from the term "ouroboros", a symbol from ancient mythology depicting a snake consuming its own tail, representing the concept of infinity and cyclicality. This name was chosen for its apt metaphorical representation of the package's functionality. Just as the ouroboros symbolizes a cycle, the "ouro" package checks for circular imports in Python. The connection to Python, a language named after a type of snake, further reinforces this symbolic link.

Demo

OURO

Installation

You can install ouro in multiple ways, as follows.

Using PIP

pip install ouro

Using Poetry

poetry add ouro

From Source

  1. Clone this repo

    git clone https://github.com/abdelrahman0w/ouro

    Or you can download it as a zip file

  2. Naviage to the repo directory

    cd ouro
  3. Once you have a copy of the source, you can install it as follows:

    • Using make

      make install
    • Using pip

      pip install .
    • Or directly from the setup.py file

      python setup.py install

Usage

Using the CLI tool

Basic Usage

  1. Navigage to your project

    cd path/to/your/project
  2. Run ouro

    ouro

Entry Point

ouro [-h] [-v] [--verbose] [--no-categorize] [-e] [-i IGNORE [IGNORE ...]] [path]

Available Options

<path>             path to the Python project to be checked (default: current working directory)

-h, --help         show this help message and exit
-v, --version      show version number and exit
--verbose          increase output verbosity (print report to console)
--no-categorize    don't categorize cycles (mark all cycles as critical)
-e, --export       export the report to a json file
-i. --ignore       list of files, directories, or glob patterns to ignore

As a pre-commit hook

Check pre-commit for instructions

  • Sample usage in .pre-commit-config.yaml file:

    Add ouro to repos as follows:

    - repo: https://github.com/abdelrahman0w/ouro
        rev: v0.2.0
        hooks:
        - id: ouro

Features

Current features are checked

  • CLI tool for checking circular imports in a Python code
  • Get the context of the import to ignore imports within a function scope
  • Ignore .git dir in case of git repo
  • Ignore paths and patterns in .gitignore file
  • Ability to ignore a file name, directory name, or a glob pattern
  • Show imports in context with file name and line number
  • Support for absolute imports
  • Support for relative imports