Skip to main content

a pylint plugin to enforce restrictions on imports within your project, similar to nx's enforce-module-boundaries eslint plugin

Project description

pylint module boundaries

a pylint plugin to enforce boundaries between modules in your project. similar to nx's enforce-module-boundaries eslint plugin

example

say you have three packages in your project - common, package1, and package2 - you can use the banned-imports rule to prevent common from importing anything from package1 or package2, thus avoiding issues such as circular dependencies.

Pylint can then be used to detect any violations of this rule:

see usage below for a config example

installing

poetry install pylint-module-boundaries

usage

pyproject.toml example

[tool.pylint.MASTER]
load-plugins = "pylint_module_boundaries"
banned-imports = '''
{
    "common(\\..*)?": ["package1(\\..*)?", "package2(\\..*)?"],
    "scripts(\\..*)?": ["package1(\\..*)?", "package2(\\..*)?"]
}
'''
banned-imports-check-usages = true

options

option type description default
banned-imports string a JSON object pairing regexes matching modules to arrays of regexes matching modules that they are not allowed to import from. due to the limitations in config types allowed by pylint, this has to be a JSON object represented as a string.

note that these regexes must be a full match, so to match any submodules you should append (\\..*)? to the regex (double \ required because it's JSON).

yes, i know this option is quite annoying to use but its purpose is to be as flexible as possible. i plan to add an easier to use option in the future that covers most basic use cases. see this issue
{}
banned-imports-check-usages boolean whether usages of the imports should be checked as well as the imports themselves. works on imports of entire modules but can potentially cause false positives depending on your use case true

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylint_module_boundaries-1.3.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

pylint_module_boundaries-1.3.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page