Skip to main content

How does it work?

This plugin inspects import statements for configured packages. Both checkers are using powerful AST analysis techniques, standard for pylint.

Status

This emerged as a standalone experimentation during development of the Clean Architecture example project

Why?

To enforce certain conventions project-wide in an automatic way, without having to watch for it during code review. For example: “we do not import anything from foo in bar.” or “we must not import anything from guts of the package baz, only what’s kept in it’s top-level __init__.py __all__ list”.

How to use it?

After installing a package just run pylint, appending pylint_forbidden_imports to your –load-plugins option.

An example:

pylint my_cool_project --load-plugins=pylint_forbidden_imports

or append it to your pylintrc file:

[MASTER]
load-plugins=pylint_forbidden_imports

Then, you have to configure the plugin. Example for .pylintrc:

[ARBITRARY-SECTION-NAME]
encapsulated-modules=auctions,payments
encapsulated-modules-friendships=auctions_infrastructure->auctions
allowed-modules-dependencies=auctions_infrastructure->auctions,
                             main->*,
                             *->foundation,

All settings are comma-separated.

encapsulated-modules - checks whether we import from it only things kept in top-level __init__.py. encapsulated-modules-friendships - allows for creating exceptions to that rule for “friend” packages. allowed-modules-dependencies - defines which packages are allowed to be imported from certain packages. Asterisk (*) is a wildcard - main->* means main package can import anything while *->foundation means that any package can import from foundation. If a certain package does not appear at least once, no rules are enforced.

Development

Install dev dependencies: ::

pip install -e .[dev]

Metadata

Release files for pylint-forbidden-imports 1.0.0

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

Source distribution (sdist)

Source distribution for pylint-forbidden-imports 1.0.0
File Size Uploaded
pylint_forbidden_imports-1.0.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pylint-forbidden-imports 1.0.0
File Interpreter ABI Platform
pylint_forbidden_imports-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / pylint_forbidden_imports-1.0.0.tar.gz

Download URL pylint_forbidden_imports-1.0.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d96d9b52e3dfce6814270b1e42f54b03790078ae906383759146df992df009e9
BLAKE2b-256 checksum
How to use checksums
c87774546ee7dd81af01e5e2e69812b97188bfb593da1fe948086c1efe240f18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Release files / pylint_forbidden_imports-1.0.0-py3-none-any.whl

Download URL pylint_forbidden_imports-1.0.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e138a184e7b5ad5bf7077d2a75bdcdac7569c53d7e30b0fb4d4aa3ae9ad458b6
BLAKE2b-256 checksum
How to use checksums
6cfdb262164aef8312ef5ac87376a5c1bcdbc6b1019d8b9790d4bc086015f56c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.4

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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