Plugin for PyLint that checks if we import from permitted modules
How does it work?
This plugin inspects import statements for configured packages. Both checkers are using powerful AST analysis techniques, standard for pylint.
This emerged as a standalone experimentation during development of the Clean Architecture example project
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.
pylint my_cool_project --load-plugins=pylint_forbidden_imports
or append it to your pylintrc file:
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.
- Install dev dependencies: ::
- pip install -e .[dev]
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size pylint_forbidden_imports-1.0.0-py3-none-any.whl (7.6 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size pylint_forbidden_imports-1.0.0.tar.gz (5.3 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for pylint_forbidden_imports-1.0.0-py3-none-any.whl
Hashes for pylint_forbidden_imports-1.0.0.tar.gz