Helps to prevent import of certain modules from certain modules.
It's useful if you have many modules in your project and want to keep them kind of isolated.
After installing just add import-rules option to your setup.cfg file.
[flake8]
...
import-rules=
# yaml format here
- module_one: [
module_two allow,
any deny
]
- module_two: [
module_one.sub.submodule deny
]
- module_two.sumbodule: module_one deny
- module_three: any allow
# many section for the same module are allowed
# for example
- module_two: [
deny some_other_module
]
# this will prevent any import everywhere
- any: [
any deny
]
# default behaviour is
- any: [
any allow
]
# For each module (among foo bar baz) allow import from self submodules
# and top module of others but not from submodules
- X | Y | foo | bar | baz : [
Y.ANY deny,
Y allow,
X allow
]
...
Rules are checking top-down. The Order Matters.
If current module name match section name or is submodule, then it will check all imports by rules from the section.
There can be one or more rules in section. There can be one or more sections for the same module/submodule.
modulepath allow - means allow imports from modulepath and its submodules
modulepath deny - means deny imports from modulepath and its submodules.
Keyword any or ANY or all or ALL - menas any module (like *)
To combine different module paths in one rule we can use | symbol. For example
to define rule for foo.hi foo.low bar.hi bar.low we can use
foo|bar.hi|low .
We can "define" variable that will be valid only during one section and its rules.
A | B | foo | bar | baz : [
...
]
means if current module name is foo or bar or baz then A is equal to current module name and B will correspond other names from group foo|bar|baz without current module name.
Variable name can be only single uppercase character. You can use variable name in section rule and inside section.
You can use variables for different module level for example
X|mod_a|mod_b.domain.Y : [
X.infra.Y allow
X.infra.ANY deny
]
CAUTION. As .INI configparser ignores indentation use [ ... , .. ] flow for lists as in example.
Metadata
Release files for flake8-import-rules 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| flake8_import_rules-1.0.0.tar.gz | 5.3 kB | Without provenance | Details for flake8_import_rules-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flake8_import_rules-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for flake8_import_rules-1.0.0-py3-none-any.whl |
Total release size: 11.4 kB
Release files / flake8_import_rules-1.0.0.tar.gz
| Download URL | flake8_import_rules-1.0.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39b53226ed4945ccb2cf6e888fb2f6d3c0c41a1f8eb0aa7a47f9a65e2f49dcbf
|
|
BLAKE2b-256 checksum How to use checksums |
a1bcafc7227c5508b8ba1582202b2455b65b0979c6986cc2aa3be69fc243215b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.5 Linux/5.4.0-84-generic
|
Release files / flake8_import_rules-1.0.0-py3-none-any.whl
| Download URL | flake8_import_rules-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c13d6dbdc202f3b925392da0ab9b112418da72f4f30a85a121c07cc65831cb55
|
|
BLAKE2b-256 checksum How to use checksums |
8ebf59b8814d23995b1890268c8e4f9da326211037d7dbfba5a64dfcb3ac2d8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.5 Linux/5.4.0-84-generic
|
Security for flake8-import-rules 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.