Skip to main content

pylint-restricted-imports is a Pylint plugin to restrict what imports are allowed in different modules

Project description

About

pylint-restricted-imports is Pylint plugin for restricting what imports are allowed in specific module trees. Want to prevent django from being imported in a flask app? This plugin is for you!

Usage

Ensure pylint-restricted-imports is installed and on your path, and then run pylint using pylint-restricted-imports as a plugin:

pip install pylint-restricted-imports
pylint --load-plugins pylint_restricted_imports [..your module..]

Configuration

Before the plugin will do anything, it needs configuring. You can use pylint to generate the default configuration:

pylint --load-plugins pylint_restricted_imports --generate-rcfile

You will end up with a block similar to below:

[RESTRICTED-IMPORT]
# Colon/semicolon-delimited sets of names that determine what modules are
# allowed to be imported from another module
restricted-imports=

# Check restricted imports recursively
restricted-import-recurse=no

Restricted Imports

restricted-imports is a csv list of module/restricted imports. The format is <module>:<restricted module>;.... For example, the following would prevent restricted1 and restricted2 from being imported in module1 and restricted3 and restricted4 from being imported in module2:

module1:restricted1;restricted2,module2:fordibben3;restricted4

Recursion

You can enable the transitive detection of restricted imports, however this takes a lot more compute.

For example, if have the following files:

# flask_app.py
import flask
import common_utils

# common_utils.py
import django

If flask_app is not allowed to import django, the transitive checker would throw an error because importing common_utils would cause django to be imported, which is restricted.

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-restricted-imports-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file pylint-restricted-imports-0.1.0.tar.gz.

File metadata

  • Download URL: pylint-restricted-imports-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.4

File hashes

Hashes for pylint-restricted-imports-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04518d5b9eea4e32d9fc2082027b707a2370e1be82f16eaaddf099808a18c7de
MD5 2f85350386d0e59c0f291a6d2c3fc49b
BLAKE2b-256 7b0c15256a4ed7700a55074766cdd12415e08aa8e389e3773228742ec0851894

See more details on using hashes here.

File details

Details for the file pylint_restricted_imports-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pylint_restricted_imports-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.4

File hashes

Hashes for pylint_restricted_imports-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5e0914f14032b6585556e5a3539d4bd9779ec9c2da2f17f3b39924886ba771c3
MD5 fde45c19c4ad1b5ab39aa2a1867d6dfe
BLAKE2b-256 3eaaa9735d43e12dea0d2a7572ccaddfe985ee843919731bc71d0152c98015ae

See more details on using hashes here.

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