Skip to content

Commit 7723798

Browse files
committed
Add flake8 to tests and fix flake8 issues
1 parent f3c89e5 commit 7723798

23 files changed

Lines changed: 120 additions & 108 deletions

.github/workflows/run-qa.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Code quality
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request: {}
8+
9+
jobs:
10+
build:
11+
runs-on: ubutu-latest
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v4
15+
- name: Set up Python ${{ matrix.python-version }}
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.12'
19+
- name: Install dependencies
20+
run: make
21+
- name: Run code quality checks
22+
run: make flake8

.github/workflows/run-tests.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,24 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
python-version: [3.7, 3.8, 3.9, '3.10', '3.11', '3.12']
16+
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
1717
os: [ubuntu-latest, macOS-latest, windows-latest]
1818
include:
1919
# pypy3 on Windows currently fails trying to
2020
# run dnspython tests. Moving pypy3 to only test linux.
21-
- python-version: pypy-3.7
21+
- python-version: 'pypy-3.9'
2222
os: ubuntu-latest
23-
- python-version: pypy-3.8
23+
- python-version: 'pypy-3.10'
2424
os: ubuntu-latest
2525

2626
steps:
27-
- uses: actions/checkout@v2
27+
- name: Check out code
28+
uses: actions/checkout@v4
2829
- name: Set up Python ${{ matrix.python-version }}
29-
uses: actions/setup-python@v2
30+
uses: actions/setup-python@v4
3031
with:
3132
python-version: ${{ matrix.python-version }}
3233
- name: Install dependencies
33-
run: |
34-
make
34+
run: make
3535
- name: Run tests
36-
run: |
37-
make ci
36+
run: make ci

Makefile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
.PHONY: docs
21
init:
32
pip install -e .
43
pip install -r requirements-test.txt
54

6-
ci:
5+
.PHONY: tests
6+
7+
tests:
78
pytest
89

910
flake8:
10-
flake8 --ignore=E501,F401,E128,E402,E731,F821 src/formencode
11+
flake8 src tests
1112

1213
coverage:
1314
pytest --cov-config .coveragerc --verbose --cov-report term --cov-report xml --cov=formencode formencode
1415

1516
publish:
16-
pip install 'twine>=1.5.0' build
17+
pip install "twine>=4" build
1718
python -m build
1819
twine upload dist/*
1920
rm -fr build dist .egg src/FormEncode.egg-info
2021

22+
.PHONY: docs
23+
2124
docs:
2225
cd docs && make html
2326
@echo "\033[95m\n\nBuild successful! View the docs homepage at docs/_build/html/index.html.\n\033[0m"

setup.cfg

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ include_package_data = True
3939
where = src
4040

4141
[options.extras_require]
42-
testing =
42+
testing =
4343
pytest
4444
dnspython
4545
pycountry
@@ -73,4 +73,5 @@ max_line_length=88
7373

7474
[flake8]
7575
max-line-length = 88
76-
extend-ignore = E203
76+
extend-ignore = E203,E128,E402,E501,E731,F821,F401
77+

src/formencode/api.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def set_stdtranslation(domain="FormEncode", languages=None,
6363
except AttributeError: # Python 3
6464
_stdtrans = t.gettext
6565

66+
6667
set_stdtranslation()
6768

6869
# Dummy i18n translation function, nothing is translated here.
@@ -195,9 +196,7 @@ def unpack_errors(self, encode_variables=False, dict_char='.',
195196
return self.msg
196197

197198

198-
############################################################
199-
## Base Classes
200-
############################################################
199+
# Base Classes
201200

202201
class Validator(declarative.Declarative):
203202

@@ -239,8 +238,9 @@ def to_python(self, value, state=None):
239238
def from_python(self, value, state=None):
240239
return value
241240

242-
_message_vars_decode = None
243-
if six.text_type is not str:
241+
if six.text_type is str:
242+
_message_vars_decode = None
243+
else:
244244
def _message_vars_decode(self, message_vars):
245245
"""
246246
Under python2, a form value in web frameworks may be encoded as
@@ -258,7 +258,7 @@ def _message_vars_decode(self, message_vars):
258258
if isinstance(v, six.text_type):
259259
try:
260260
v2 = v.encode('utf-8')
261-
except Exception as e:
261+
except Exception:
262262
v2 = v
263263
if v == v2:
264264
message_vars[k] = v2
@@ -355,6 +355,7 @@ class _Identity(Validator):
355355
def __repr__(self):
356356
return 'validators.Identity'
357357

358+
358359
Identity = _Identity()
359360

360361

@@ -481,8 +482,7 @@ def __classinit__(cls, new_attrs):
481482
stacklevel=cls._inheritance_level + 2)
482483
setattr(cls, new, new_attrs[old])
483484
elif new in new_attrs:
484-
setattr(cls, old, deprecated(old=old, new=new)(
485-
new_attrs[new]))
485+
setattr(cls, old, deprecated(old=old, new=new)(new_attrs[new]))
486486

487487
def to_python(self, value, state=None):
488488
try:

src/formencode/compound.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77

88
__all__ = ['CompoundValidator', 'Any', 'All', 'Pipe']
99

10-
############################################################
11-
## Compound Validators
12-
############################################################
1310

11+
# Compound Validators
1412

1513
def to_python(validator, value, state):
1614
return validator.to_python(value, state)

src/formencode/declarative.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __sourcerepr__(self, source, binding=None):
189189
else:
190190
break
191191
args.extend('%s=%s' % (name, source.makeRepr(value))
192-
for (name, value) in six.iteritems(vals))
192+
for (name, value) in six.iteritems(vals))
193193
return '%s(%s)' % (self.__class__.__name__,
194194
', '.join(args))
195195

src/formencode/exc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Custom exceptions and warnings.
33
"""
44

5-
__all__ = ['FERunTimeWarning']
5+
__all__ = ['FERuntimeWarning']
66

77

88
class FERuntimeWarning(RuntimeWarning):

src/formencode/fieldstorage.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
## FormEncode, a Form processor
2-
## Copyright (C) 2003, Ian Bicking <ianb@colorstudy.com>
31
"""
42
Wrapper class for use with cgi.FieldStorage types for file uploads
53
"""
64

75

8-
import cgi
9-
10-
116
def convert_fieldstorage(fs):
127
return fs if fs.filename else None

src/formencode/foreach.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,5 @@ def _convert_to_list(self, value):
136136
for _n in value:
137137
break
138138
return value
139-
## @@: Should this catch any other errors?:
140-
except TypeError:
139+
except TypeError: # @@: Should this catch any other errors?
141140
return [value]

0 commit comments

Comments
 (0)