Skip to content

Commit 6eb4800

Browse files
authored
Merge pull request #117 from gforcada/overhaul
Overhaul
2 parents ef9ae20 + 4114d4a commit 6eb4800

13 files changed

+596
-341
lines changed

.github/workflows/tests.yml

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,91 @@
1-
name: Tests
2-
1+
name: Testing
32
on:
43
push:
54
branches: [master]
65
pull_request:
76
branches: [master]
8-
paths:
9-
- "flake8_isort.py"
10-
- "test_flake8_isort.py"
11-
- "setup.py"
12-
- ".github/workflows/tests.yml"
13-
7+
env:
8+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
149
jobs:
15-
tests:
10+
test:
11+
name: py-${{ matrix.python-version }}/isort-${{ matrix.isort }}/flake8-${{ matrix.flake8 }}
1612
runs-on: ubuntu-latest
17-
name: Python ${{ matrix.python-version }} x isort ${{ matrix.isort }} x flake8 ${{ matrix.flake8 }}
18-
1913
strategy:
2014
matrix:
21-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', 'pypy3']
22-
isort: [4.3.21, 5.10.1]
23-
flake8: [3.9.2, 4.0.1, 5.0.4]
15+
python-version: ["3.10", 3.9, 3.8, 3.7, pypy-3.9]
16+
isort: [5.10.1]
17+
flake8: [5.0.4]
18+
include:
19+
- python-version: 3.9
20+
isort: 5.10.1
21+
flake8: 4.0.1
22+
qa: 'true'
23+
- python-version: 3.9
24+
isort: 5.10.1
25+
flake8: 3.9.2
2426

27+
- python-version: 3.9
28+
isort: 4.3.21
29+
flake8: 5.0.4
30+
- python-version: 3.9
31+
isort: 4.3.21
32+
flake8: 4.0.1
33+
- python-version: 3.9
34+
isort: 4.3.21
35+
flake8: 3.9.2
2536
steps:
26-
- uses: actions/checkout@v2
27-
- uses: actions/setup-python@v2
37+
- uses: actions/checkout@v3
38+
- name: Set up Python
39+
uses: actions/setup-python@v4
2840
with:
2941
python-version: ${{ matrix.python-version }}
30-
architecture: x64
31-
- name: Install matrix dependencies
32-
run: pip install 'isort==${{ matrix.isort }}' 'flake8==${{ matrix.flake8 }}'
42+
- name: Cache packages
43+
uses: actions/cache@v3
44+
with:
45+
path: ~/.cache/pip
46+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
47+
restore-keys: |
48+
${{ runner.os }}-pip-${{ matrix.python-version }}-
49+
- name: pip version
50+
run: pip --version
51+
- name: Install dependencies
52+
run: |
53+
python -m pip install -r requirements.txt
54+
pip install 'isort==${{ matrix.isort }}' 'flake8==${{ matrix.flake8 }}'
3355
# isort 4.x requires `toml` to be able to read pyproject.toml, so install it...
3456
- name: Install toml if required
3557
run: pip install toml
3658
if: matrix.isort == '4.3.21'
37-
- name: Install dependencies
38-
run: pip install .[test]
39-
- name: flake8
40-
run: flake8 *.py
41-
- name: pytest
42-
run: pytest -v --cov flake8_isort --cov-report term-missing
43-
- name: Upload coverage
59+
# formatters
60+
- name: Run pyupgrade
61+
if: matrix.qa == 'true'
62+
run: pyupgrade --py37-plus *.py
63+
- name: Run isort
64+
if: matrix.qa == 'true'
65+
run: isort --check-only *.py
66+
- name: Run black
67+
if: matrix.qa == 'true'
68+
run: black --check --skip-string-normalization *.py
69+
# linters
70+
- name: Lint with bandit
71+
if: matrix.qa == 'true'
72+
run: bandit --skip B101 *.py # B101 is assert statements
73+
- name: Lint with codespell
74+
if: matrix.qa == 'true'
75+
run: codespell *.rst *.py
76+
- name: Lint with flake8
77+
if: matrix.qa == 'true'
78+
run: flake8 *.py --count --max-complexity=18 --max-line-length=88 --show-source --statistics
79+
- name: Lint with mypy
80+
if: matrix.qa == 'true'
4481
run: |
45-
python -m pip install coveralls
46-
coveralls --service=github
47-
env:
48-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
mkdir --parents --verbose .mypy_cache
83+
mypy --ignore-missing-imports --install-types --non-interactive *.py || true
84+
- name: Lint with safety
85+
if: matrix.qa == 'true'
86+
run: safety check || true
87+
# tests and coverage
88+
- name: Test
89+
run: pytest run_tests.py --cov --cov-report term-missing
90+
- name: Coverage
91+
run: coveralls --service=github

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
*.egg-info
22
*.pyc
33

4+
.cache
45
.coverage
56
.installed.cfg
7+
.hypothesis
68
bin
79
develop-eggs
810
include

CHANGES.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ Changelog
66
4.2.1 (unreleased)
77
------------------
88

9-
- Nothing changed yet.
9+
- Update dependencies. [gforcada]
10+
11+
- Revamp GitHub actions. [gforcada]
12+
13+
- Drop python 3.6, and add python 3.10. [gforcada]
1014

15+
- Use linters and formatters to keep code sane and beautiful. [gforcada]
1116

1217
4.2.0 (2022-08-04)
1318
------------------

LICENSE.rst

Lines changed: 0 additions & 17 deletions
This file was deleted.

MANIFEST.in

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
include MANIFEST.in LICENSE *.rst *.py *.cfg *.ini
2-
exclude .installed.cfg .coveragerc *.pyc
1+
include MANIFEST.in
2+
include LICENSE
3+
include setup.cfg
4+
include *.rst
5+
include *.py
6+
include *requirements.txt
37

8+
exclude .installed.cfg
9+
exclude .coveragerc
10+
exclude *.pyc
11+
exclude *.in

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.. -*- coding: utf-8 -*-
22
3-
.. image:: https://github.com/gforcada/flake8-isort/actions/workflows/tests.yml/badge.svg?branch=master
4-
:target: https://github.com/gforcada/flake8-isort/actions/workflows/tests.yml
3+
.. image:: https://github.com/gforcada/flake8-isort/actions/workflows/testing.yml/badge.svg?branch=master
4+
:target: https://github.com/gforcada/flake8-isort/actions/workflows/testing.yml
55

6-
.. image:: https://coveralls.io/repos/gforcada/flake8-isort/badge.svg?branch=master&service=github
6+
.. image:: https://coveralls.io/repos/gforcada/flake8-isort/badge.svg?branch=master
77
:target: https://coveralls.io/github/gforcada/flake8-isort?branch=master
88

99
Flake8 meet isort
@@ -47,7 +47,7 @@ Error codes
4747

4848
Requirements
4949
------------
50-
- Python 2.7, 3.5, 3.6, pypy or pypy3
50+
- Python 3.7, 3.8, 3.9, 3.10 and pypy3
5151
- flake8
5252
- isort
5353

flake8_isort.py

Lines changed: 26 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
1-
# -*- coding: utf-8 -*-
2-
1+
import warnings
32
from contextlib import redirect_stdout
4-
from difflib import Differ
5-
from difflib import unified_diff
3+
from difflib import Differ, unified_diff
64
from io import StringIO
75
from pathlib import Path
86

97
import isort
10-
import warnings
118

129

13-
__version__ = '4.2.1.dev0'
14-
15-
16-
class Flake8IsortBase(object):
10+
class Flake8IsortBase:
1711
name = 'flake8_isort'
18-
version = __version__
19-
isort_unsorted = (
20-
'I001 isort found an import in the wrong position'
21-
)
22-
no_config_msg = (
23-
'I002 no configuration found (.isort.cfg or [isort] in configs)'
24-
)
25-
isort_blank_req = (
26-
'I003 isort expected 1 blank line in imports, found 0'
27-
)
28-
isort_blank_unexp = (
29-
'I004 isort found an unexpected blank line in imports'
30-
)
31-
isort_add_unexp = (
32-
'I005 isort found an unexpected missing import'
33-
)
12+
version = '4.2.1'
13+
isort_unsorted = 'I001 isort found an import in the wrong position'
14+
no_config_msg = 'I002 no configuration found (.isort.cfg or [isort] in configs)'
15+
isort_blank_req = 'I003 isort expected 1 blank line in imports, found 0'
16+
isort_blank_unexp = 'I004 isort found an unexpected blank line in imports'
17+
isort_add_unexp = 'I005 isort found an unexpected missing import'
3418

3519
show_traceback = False
3620
stdin_display_name = None
@@ -46,7 +30,7 @@ def add_options(cls, parser):
4630
'--isort-show-traceback',
4731
action='store_true',
4832
parse_from_config=True,
49-
help='Show full traceback with diff from isort'
33+
help='Show full traceback with diff from isort',
5034
)
5135

5236
@classmethod
@@ -101,9 +85,7 @@ def sortimports_linenum_msg(self, sort_result):
10185
diff = differ.compare(sort_result.in_lines, sort_result.out_lines)
10286

10387
line_num = 0
104-
additions = {
105-
'+ {}'.format(add_import) for add_import in sort_result.add_imports
106-
}
88+
additions = {f'+ {add_import}' for add_import in sort_result.add_imports}
10789
for line in diff:
10890
if line.startswith(' ', 0, 2):
10991
line_num += 1 # Ignore unchanged lines but increment line_num.
@@ -176,7 +158,8 @@ def _fixup_sortimports_wrapped(sort_imports):
176158
for idx, line in enumerate(sort_imports.out_lines):
177159
if '\n' in line:
178160
for new_idx, new_line in enumerate(
179-
sort_imports.out_lines.pop(idx).splitlines()):
161+
sort_imports.out_lines.pop(idx).splitlines()
162+
):
180163
sort_imports.out_lines.insert(idx + new_idx, new_line)
181164

182165

@@ -186,12 +169,10 @@ class Flake8Isort5(Flake8IsortBase):
186169
def run(self):
187170
if self.filename is not self.stdin_display_name:
188171
file_path = Path(self.filename)
189-
isort_config = isort.settings.Config(
190-
settings_path=file_path.parent)
172+
isort_config = isort.settings.Config(settings_path=file_path.parent)
191173
else:
192174
file_path = None
193-
isort_config = isort.settings.Config(
194-
settings_path=Path.cwd())
175+
isort_config = isort.settings.Config(settings_path=Path.cwd())
195176
input_string = ''.join(self.lines)
196177
traceback = ''
197178
isort_changed = False
@@ -204,19 +185,23 @@ def run(self):
204185
input_stream=input_stream,
205186
output_stream=output_stream,
206187
config=isort_config,
207-
file_path=file_path)
188+
file_path=file_path,
189+
)
208190
except isort.exceptions.FileSkipped:
209191
pass
210192
except isort.exceptions.ISortError as e:
211193
warnings.warn(e)
212194
if isort_changed:
213195
outlines = output_stream.getvalue()
214-
diff_delta = "".join(unified_diff(
215-
input_string.splitlines(keepends=True),
216-
outlines.splitlines(keepends=True),
217-
fromfile="{}:before".format(self.filename),
218-
tofile="{}:after".format(self.filename)))
219-
traceback = (isort_stdout.getvalue() + "\n" + diff_delta)
196+
diff_delta = ''.join(
197+
unified_diff(
198+
input_string.splitlines(keepends=True),
199+
outlines.splitlines(keepends=True),
200+
fromfile=f'{self.filename}:before',
201+
tofile=f'{self.filename}:after',
202+
)
203+
)
204+
traceback = f'{isort_stdout.getvalue()}\n{diff_delta}'
220205
for line_num, message in self.isort_linenum_msg(diff_delta):
221206
if self.show_traceback:
222207
message += traceback

requirements.in

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
bandit
2+
black
3+
codespell
4+
coveralls
5+
flake8-blind-except
6+
flake8-bugbear
7+
flake8-comprehensions
8+
flake8-debugger
9+
flake8-deprecated
10+
flake8-isort
11+
flake8-pep3101
12+
flake8-print
13+
flake8-quotes
14+
flake8-todo
15+
importlib-metadata; python_version < '3.8'
16+
isort
17+
mypy
18+
pytest
19+
pytest-cov
20+
pyupgrade
21+
safety
22+
typed-ast; python_version < '3.8' # dependency of black and mypy
23+
zipp; python_version < '3.8' # dependency of importlib-metadata

0 commit comments

Comments
 (0)