flake8-import-rules


Nameflake8-import-rules JSON
Version 1.0.0 PyPI version JSON
download
home_page
Summary
upload_time2023-04-24 16:12:27
maintainer
docs_urlNone
authorVL
requires_python>=3.8,<4.0
license
keywords flake8 plugin linting import deprecate import
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "flake8-import-rules",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "flake8,plugin,linting,import,deprecate import",
    "author": "VL",
    "author_email": "1844144@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/a1/bc/afc7227c5508b8ba1582202b2455b65b0979c6986cc2aa3be69fc243215b/flake8_import_rules-1.0.0.tar.gz",
    "platform": null,
    "description": "Helps to prevent import of certain modules from certain modules.\n\nIt's useful if you have many modules in your project and want to keep them kind of\nisolated.\n\nAfter installing just add `import-rules` option to your `setup.cfg` file.\n\n```\n[flake8]\n...\nimport-rules= \n\t# yaml format here\n\t- module_one: [\n\t\tmodule_two allow,\n\t\tany deny\n\t]\n\t- module_two: [\n\t\tmodule_one.sub.submodule deny\n\t]\n\t- module_two.sumbodule: module_one deny\n\t- module_three: any allow\n\n\t# many section for the same module are allowed\n\t# for example\n\t- module_two: [\n\t\tdeny some_other_module\n\t]\n\n\t# this will prevent any import everywhere\n\t- any: [\n\t\tany deny\n\t]\n\n\t# default behaviour is\n\t- any: [\n\t\tany allow\n\t]\n\n\t# For each module (among foo bar baz) allow import from self submodules \n\t# and top module of others but not from submodules\n\t- X | Y | foo | bar | baz : [\n\t\tY.ANY deny,\n\t\tY     allow,\n\t\tX \t  allow\n\n\t]\n\n...\n```\nRules are checking top-down. The Order Matters.\n\nIf current module name match section name or is submodule, then it will check all imports by rules from the section.\n\nThere can be one or more rules in section.\nThere can be one or more sections for the same module/submodule.\n\n`modulepath allow` - means allow imports from `modulepath` and its submodules\n\n`modulepath deny` - means deny imports from `modulepath` and its submodules.\n\nKeyword `any` or `ANY` or `all` or `ALL` - menas any module (like `*`)\n\nTo combine different module paths in one rule we can use `|` symbol. For example\nto define rule for foo.hi foo.low bar.hi bar.low we can use \n`foo|bar.hi|low` . \n\nWe can \"define\" variable that will be valid only during one section and its rules.\n```\nA | B | foo | bar | baz : [\n\t...\n]\n```\nmeans if current module name is foo or bar or baz then A is equal to current module name\nand B will correspond other names from group foo|bar|baz without current module name.\n\nVariable name can be only single uppercase character. You can use variable name in section rule and inside section.\n\nYou can use variables for different module level for example\n\n```\nX|mod_a|mod_b.domain.Y : [\n\tX.infra.Y allow\n\tX.infra.ANY deny\n]\n```\n\n   \nCAUTION. As .INI configparser ignores indentation use `[ ... , .. ]` flow for lists as in example.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "1.0.0",
    "split_keywords": [
        "flake8",
        "plugin",
        "linting",
        "import",
        "deprecate import"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8ebf59b8814d23995b1890268c8e4f9da326211037d7dbfba5a64dfcb3ac2d8e",
                "md5": "2a441c879c5d4949f4c41cfb891d1700",
                "sha256": "c13d6dbdc202f3b925392da0ab9b112418da72f4f30a85a121c07cc65831cb55"
            },
            "downloads": -1,
            "filename": "flake8_import_rules-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a441c879c5d4949f4c41cfb891d1700",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 6123,
            "upload_time": "2023-04-24T16:12:23",
            "upload_time_iso_8601": "2023-04-24T16:12:23.721664Z",
            "url": "https://files.pythonhosted.org/packages/8e/bf/59b8814d23995b1890268c8e4f9da326211037d7dbfba5a64dfcb3ac2d8e/flake8_import_rules-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1bcafc7227c5508b8ba1582202b2455b65b0979c6986cc2aa3be69fc243215b",
                "md5": "0b997b6f6de7a6778215f88a80e24799",
                "sha256": "39b53226ed4945ccb2cf6e888fb2f6d3c0c41a1f8eb0aa7a47f9a65e2f49dcbf"
            },
            "downloads": -1,
            "filename": "flake8_import_rules-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0b997b6f6de7a6778215f88a80e24799",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 5296,
            "upload_time": "2023-04-24T16:12:27",
            "upload_time_iso_8601": "2023-04-24T16:12:27.466744Z",
            "url": "https://files.pythonhosted.org/packages/a1/bc/afc7227c5508b8ba1582202b2455b65b0979c6986cc2aa3be69fc243215b/flake8_import_rules-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-24 16:12:27",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "flake8-import-rules"
}
        
VL
Elapsed time: 0.06418s