Skip to content

Commit

Permalink
Support flake8 v5+ (#12)
Browse files Browse the repository at this point in the history
* Rename "I20xx" to "IMR2xx" in codes.
* Removed support for Python 3.7 and added 3.10 and 3.11.
* Fix requirement versions.
* Fix Github actions.
  • Loading branch information
atollk authored Jul 14, 2023
1 parent 795efbe commit cc215e5
Show file tree
Hide file tree
Showing 29 changed files with 239 additions and 225 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.8]
python-version: [3.11]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-flake8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.8]
python-version: [3.11]

steps:
- uses: actions/checkout@v1
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/python-pylint.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
name: pylint
on: [push, pull_request]

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.8]
python-version: [3.11]

steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: GitHub Action for pylint
uses: cclauss/[email protected]
with:
args: "pip install pylint -r requirements/py38.txt ; pylint flake8_import_restrictions/*.py -E"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint -r requirements/py311.txt
- name: pylint
run: |
python -m pylint flake8_import_restrictions/*.py -E
2 changes: 1 addition & 1 deletion .github/workflows/python-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.7, 3.8]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v1
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ and the `from` syntax (`from X.Y import Z [as foo]`). It talks about
segments (`as Z`).

## Options
For every error `I20xx` listed below, there are options `--i20xx_include` and `--i20xx_exclude`
For every error `IMR2xx` listed below, there are options `--imr2xx_include` and `--imr2xx_exclude`
which are passed a comma separated list of UNIX wildcard patterns each. The error
will then only be reported on imports of modules that match a include pattern but no exclude
pattern.

By default, I2000, I2001, I2002, I2021, I2023, I2041, and I2043 include all (`*`) modules. Only I2041 excludes the
By default, IMR200, IMR201, IMR202, IMR221, IMR223, IMR241, and IMR243 include all (`*`) modules. Only IMR241 excludes the
`typing` module from checks, the other errors have no excludes by default.

## General Import Errors

### I2000
### IMR200
Imports should only happen on module level, not locally.

```python
Expand All @@ -37,7 +37,7 @@ def f():
return os.path.join("a", "b")
```

### I2001
### IMR201
Alias identifiers defined from `as` segments should be at
least two characters long.

Expand All @@ -49,7 +49,7 @@ import os.path as p
import os.path as path
```

### I2002
### IMR202
Alias identifiers should not have the same name as the imported object.

```python
Expand All @@ -62,7 +62,7 @@ import sys

## `import` Syntax Errors

### I2020
### IMR220
When using the `import` syntax, if the imported module is a submodule,
i.e. not a top level module, an `as` segment should be present.

Expand All @@ -75,7 +75,7 @@ import sys
import os.path as path
```

### I2021
### IMR221
When using the `import` syntax, each import statement should
only import one module.

Expand All @@ -88,11 +88,11 @@ import sys
import os
```

### I2022
### IMR222
The `import` syntax should not be used.


### I2023
### IMR223
When using the `import` syntax, do not duplicate module names in the `as`
segment.

Expand All @@ -108,7 +108,7 @@ import os.path as ospath

## `from` Syntax Errors

### I2040
### IMR240
When using the `from` syntax, the `import` segment only contains one
import.

Expand All @@ -121,7 +121,7 @@ from os import path
from os import environ
```

### I2041
### IMR241
When using the `from` syntax, only submodules are imported, not
module elements.

Expand All @@ -133,7 +133,7 @@ from os.path import join
from os import path
```

### I2042
### IMR242
When using the `from` syntax, only module elements are imported,
not submodules.

Expand All @@ -145,7 +145,7 @@ from os import path
from os.path import join
```

### I2043
### IMR243
When using the `from` syntax, `import *` should not be used.

```python
Expand All @@ -156,7 +156,7 @@ from os.path import *
from os.path import join
```

### I2044
### IMR244
Relative imports should not be used.

```python
Expand All @@ -167,5 +167,5 @@ from . import foo
from flake8_import_restrictions import foo
```

### I2045
### IMR245
The `from` syntax should not be used.
Loading

0 comments on commit cc215e5

Please sign in to comment.