Skip to main content

flake8-obey-import-goat

An extension for flake8 that forbids some imports statements in some modules.

Important: this project is developed using DDD, so some of the docs can not exists. Stay tuned :)

Installation

pip install flake8-obey-import-goat

Example

# foo.py
from datetime import datetime
from typing import Optional

def foo():
    pass


# users/bar.py
from foo import foo


# users/domain.py
def foo():
    pass


# users/implementation.py
from users.domain import foo


# orders/implementation.py
from users.domain import foo
# setup.cfg
[flake8]
forbidden-imports =
    *: datetime.datetime, stdlib modules should be imported as a module
    *: typing.Optional, we use T | None instead of Optional[T]
    users.*: foo.*, users module should not use foo module
    *.implementation.*: *.domain.*, implementation layer should not use domain layer

Usage:

$ flake8 test.py
foo.py:1:1: OIG001 datetime.datetime is forbidden, since stdlib modules should be imported as a module.
foo.py:2:1: OIG001 typing.Optional is forbidden, since we use T | None instead of Optional[T].
users/bar.py:1:1: OIG001 foo.foo import is forbidden is forbidden, since users module should not use foo module.
users/implementation.py:1:1: OIG001 *.domain.* import is forbidden is forbidden, since implementation layer should not use domain layer.
orders/implementation.py:1:1: OIG001 *.domain.* import is forbidden is forbidden, since implementation layer should not use domain layer.

Tested on Python 3.9+ and flake8 4.0+.

Error codes

Error code Description
OIG001 importable is forbidden, since reason

Metadata

Release files for flake8-obey-import-goat 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-obey-import-goat 0.1.1
File Size Uploaded
flake8_obey_import_goat-0.1.1.tar.gz 4.3 kB Details

Release files / flake8_obey_import_goat-0.1.1.tar.gz

Download URL flake8_obey_import_goat-0.1.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2e4c7be21b96dda72e903c21de16ff928e11fccdf9427889bfb7ccf4610f6072
BLAKE2b-256 checksum
How to use checksums
bd6e314f890189d95826e62be32120012e1d0fe5709334efe133d0df2461cb38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

Release history Release notifications | RSS feed

This release

0.1.1 This release

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page