Skip to content

Commit f0220bc

Browse files
authored
Merge pull request #85 from gforcada/drop-py2-py36
Major cleanup: python versions, versions pinned and github actions
2 parents 762a3c8 + 16d70c3 commit f0220bc

11 files changed

Lines changed: 530 additions & 587 deletions

File tree

.github/workflows/lint_python.yml

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

.github/workflows/testing.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Testing
2+
on: [pull_request, push]
3+
env:
4+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5+
jobs:
6+
test:
7+
name: Testing on
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: [3.9, 3.8, 3.7, pypy-3.9]
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: ${{ matrix.python-version }}
18+
- name: Cache packages
19+
uses: actions/cache@v3
20+
with:
21+
path: ~/.cache/pip
22+
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
23+
restore-keys: |
24+
${{ runner.os }}-pip-${{ matrix.python-version }}-
25+
- name: pip version
26+
run: pip --version
27+
- name: Install dependencies
28+
run: python -m pip install -r requirements.txt
29+
# formatters
30+
- name: Run pyupgrade
31+
if: matrix.python-version == '3.9'
32+
run: pyupgrade --py37-plus *.py
33+
- name: Run isort
34+
if: matrix.python-version == '3.9'
35+
run: isort --check-only *.py
36+
- name: Run black
37+
if: matrix.python-version == '3.9'
38+
run: black --check --skip-string-normalization *.py
39+
# linters
40+
- name: Lint with bandit
41+
if: matrix.python-version == '3.9'
42+
run: bandit --skip B101 *.py # B101 is assert statements
43+
- name: Lint with codespell
44+
if: matrix.python-version == '3.9'
45+
run: codespell *.rst *.py
46+
- name: Lint with flake8
47+
if: matrix.python-version == '3.9'
48+
run: flake8 *.py --count --max-complexity=18 --max-line-length=88 --show-source --statistics
49+
- name: Lint with mypy
50+
if: matrix.python-version == '3.9'
51+
run: |
52+
mkdir --parents --verbose .mypy_cache
53+
mypy --ignore-missing-imports --install-types --non-interactive *.py || true
54+
- name: Lint with safety
55+
if: matrix.python-version == '3.9'
56+
run: safety check || true
57+
# tests and coverage
58+
- name: Test
59+
run: pytest run_tests.py --cov --cov-report term-missing
60+
- name: Coverage
61+
run: coveralls --service=github

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.cache
55
.coverage
66
.installed.cfg
7-
.tox
7+
.hypothesis
88
bin
99
develop-eggs
1010
include

CHANGES.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Changelog
1414

1515
- Make black and isort mandatory. [cclauss]
1616

17+
- Drop python 2.7 and 3.6. [gforcada]
18+
19+
- Overhaul GitHub actions to test on actual supported python versions. [gforcada]
20+
1721
1.5.3 (2020-05-14)
1822
------------------
1923

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Install with pip::
7575

7676
Requirements
7777
------------
78-
- Python 2.7, 3.6, 3.7, 3.8, 3.9
78+
- Python 3.7, 3.8, 3.9
7979
- flake8
8080

8181
License

flake8_builtins.py

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
# -*- coding: utf-8 -*-
21
import ast
2+
import builtins
33
import inspect
44
import sys
55

6-
7-
try:
8-
from flake8.engine import pep8 as stdin_utils
9-
except ImportError:
10-
from flake8 import utils as stdin_utils
11-
6+
from flake8 import utils as stdin_utils
127

138
WHITE_LIST = {
149
'__name__',
@@ -18,29 +13,15 @@
1813
}
1914

2015

21-
if sys.version_info >= (3, 0):
22-
import builtins
23-
24-
BUILTINS = [a[0] for a in inspect.getmembers(builtins) if a[0] not in WHITE_LIST]
25-
PY3 = True
26-
else:
27-
import __builtin__
28-
29-
BUILTINS = [a[0] for a in inspect.getmembers(__builtin__) if a[0] not in WHITE_LIST]
30-
PY3 = False
31-
32-
if sys.version_info >= (3, 6):
33-
AnnAssign = ast.AnnAssign
34-
else: # There was no `AnnAssign` before python3.6
35-
AnnAssign = type('AnnAssign', (ast.AST,), {})
16+
BUILTINS = [a[0] for a in inspect.getmembers(builtins) if a[0] not in WHITE_LIST]
3617

3718
if sys.version_info >= (3, 8):
3819
NamedExpr = ast.NamedExpr
3920
else: # There was no walrus operator before python3.8
4021
NamedExpr = type('NamedExpr', (ast.AST,), {})
4122

4223

43-
class BuiltinsChecker(object):
24+
class BuiltinsChecker:
4425
name = 'flake8_builtins'
4526
version = '1.5.2'
4627
assign_msg = 'A001 variable "{0}" is shadowing a python builtin'
@@ -86,7 +67,7 @@ def run(self):
8667

8768
value = None
8869
for statement in ast.walk(tree):
89-
if isinstance(statement, (ast.Assign, AnnAssign, NamedExpr)):
70+
if isinstance(statement, (ast.Assign, ast.AnnAssign, NamedExpr)):
9071
value = self.check_assignment(statement)
9172

9273
elif isinstance(statement, function_nodes):
@@ -111,8 +92,7 @@ def run(self):
11192
value = self.check_class(statement)
11293

11394
if value:
114-
for line, offset, msg, rtype in value:
115-
yield line, offset, msg, rtype
95+
yield from value
11696

11797
def check_assignment(self, statement):
11898
msg = self.assign_msg
@@ -130,7 +110,7 @@ def check_assignment(self, statement):
130110
stack.extend(list(item.elts))
131111
elif isinstance(item, ast.Name) and item.id in BUILTINS:
132112
yield self.error(item, message=msg, variable=item.id)
133-
elif PY3 and isinstance(item, ast.Starred):
113+
elif isinstance(item, ast.Starred):
134114
if hasattr(item.value, 'id') and item.value.id in BUILTINS:
135115
yield self.error(
136116
statement,
@@ -148,23 +128,18 @@ def check_function_definition(self, statement):
148128

149129
yield self.error(statement, message=msg, variable=statement.name)
150130

151-
if PY3:
152-
all_arguments = []
153-
all_arguments.extend(statement.args.args)
154-
all_arguments.extend(getattr(statement.args, 'kwonlyargs', []))
155-
all_arguments.extend(getattr(statement.args, 'posonlyargs', []))
131+
all_arguments = []
132+
all_arguments.extend(statement.args.args)
133+
all_arguments.extend(getattr(statement.args, 'kwonlyargs', []))
134+
all_arguments.extend(getattr(statement.args, 'posonlyargs', []))
156135

157-
for arg in all_arguments:
158-
if isinstance(arg, ast.arg) and arg.arg in BUILTINS:
159-
yield self.error(
160-
arg,
161-
message=self.argument_msg,
162-
variable=arg.arg,
163-
)
164-
else:
165-
for arg in statement.args.args:
166-
if isinstance(arg, ast.Name) and arg.id in BUILTINS:
167-
yield self.error(arg, message=self.argument_msg)
136+
for arg in all_arguments:
137+
if isinstance(arg, ast.arg) and arg.arg in BUILTINS:
138+
yield self.error(
139+
arg,
140+
message=self.argument_msg,
141+
variable=arg.arg,
142+
)
168143

169144
def check_for_loop(self, statement):
170145
stack = [statement.target]
@@ -174,7 +149,7 @@ def check_for_loop(self, statement):
174149
stack.extend(list(item.elts))
175150
elif isinstance(item, ast.Name) and item.id in BUILTINS:
176151
yield self.error(statement, variable=item.id)
177-
elif PY3 and isinstance(item, ast.Starred):
152+
elif isinstance(item, ast.Starred):
178153
if hasattr(item.value, 'id') and item.value.id in BUILTINS:
179154
yield self.error(
180155
statement,
@@ -184,44 +159,31 @@ def check_for_loop(self, statement):
184159
stack.extend(list(item.value.elts))
185160

186161
def check_with(self, statement):
187-
if not PY3:
188-
var = statement.optional_vars
162+
for item in statement.items:
163+
var = item.optional_vars
189164
if isinstance(var, (ast.Tuple, ast.List)):
190165
for element in var.elts:
191166
if isinstance(element, ast.Name) and element.id in BUILTINS:
192167
yield self.error(statement, variable=element.id)
168+
elif (
169+
isinstance(element, ast.Starred)
170+
and element.value.id in BUILTINS
171+
):
172+
yield self.error(
173+
element,
174+
variable=element.value.id,
175+
)
193176

194177
elif isinstance(var, ast.Name) and var.id in BUILTINS:
195178
yield self.error(statement, variable=var.id)
196-
else:
197-
for item in statement.items:
198-
var = item.optional_vars
199-
if isinstance(var, (ast.Tuple, ast.List)):
200-
for element in var.elts:
201-
if isinstance(element, ast.Name) and element.id in BUILTINS:
202-
yield self.error(statement, variable=element.id)
203-
elif (
204-
isinstance(element, ast.Starred)
205-
and element.value.id in BUILTINS
206-
):
207-
yield self.error(
208-
element,
209-
variable=element.value.id,
210-
)
211-
212-
elif isinstance(var, ast.Name) and var.id in BUILTINS:
213-
yield self.error(statement, variable=var.id)
214179

215180
def check_exception(self, statement):
216181
exception_name = statement.name
217-
value = ''
218-
if isinstance(exception_name, ast.Name):
219-
value = exception_name.id
220-
elif isinstance(exception_name, str): # Python +3.x
221-
value = exception_name
222-
223-
if value in BUILTINS:
224-
yield self.error(statement, variable=value)
182+
if exception_name is None:
183+
return
184+
185+
if exception_name in BUILTINS:
186+
yield self.error(statement, variable=exception_name)
225187

226188
def check_comprehension(self, statement):
227189
for generator in statement.generators:

requirements.in

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
bandit
2+
black
3+
codespell
14
coveralls
25
flake8-blind-except
3-
flake8-coding
4-
flake8-commas
6+
flake8-bugbear
7+
flake8-comprehensions
58
flake8-debugger
69
flake8-deprecated
710
flake8-isort
811
flake8-pep3101
9-
flake8-polyfill
1012
flake8-print
1113
flake8-quotes
12-
flake8-string-format
1314
flake8-todo
14-
futures; python_version < '3.0'
15-
hypothesis; python_version >= '3.6'
16-
hypothesmith; python_version >= '3.6'
17-
mock ; python_version < '3.0'
18-
pytest<5; python_version < '3.0'
19-
pytest>5; python_version >= '3.0'
15+
importlib-metadata; python_version < '3.8'
16+
isort
17+
mypy
18+
pytest
2019
pytest-cov
21-
more-itertools==5.0.0
22-
zipp ; python_version >= '3.0'
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)