Plugin for PyLint that checks if we import from permitted modules
Project description
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]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pylint_forbidden_imports-1.0.0.tar.gz
.
File metadata
- Download URL: pylint_forbidden_imports-1.0.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d96d9b52e3dfce6814270b1e42f54b03790078ae906383759146df992df009e9 |
|
MD5 | 656d7bafa7a48053429c5d7385b34de5 |
|
BLAKE2b-256 | c87774546ee7dd81af01e5e2e69812b97188bfb593da1fe948086c1efe240f18 |
File details
Details for the file pylint_forbidden_imports-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pylint_forbidden_imports-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e138a184e7b5ad5bf7077d2a75bdcdac7569c53d7e30b0fb4d4aa3ae9ad458b6 |
|
MD5 | 85df9200a31e97957e9e1350cd82d086 |
|
BLAKE2b-256 | 6cfdb262164aef8312ef5ac87376a5c1bcdbc6b1019d8b9790d4bc086015f56c |