Skip to content

Commit a4ed6b7

Browse files
authored
Flake8 (#723)
1 parent a56da3f commit a4ed6b7

23 files changed

+249
-253
lines changed

.flake8.cfg

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[flake8]
2+
max-line-length = 120
3+
max-complexity = 40
4+
ignore =
5+
W504
6+
exclude =
7+
.git
8+
./ev3dev2/auto.py
9+
./tests/fake-sys/
10+
./venv

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ clean:
2323

2424
format:
2525
yapf --style .yapf.cfg --in-place --exclude tests/fake-sys/ --recursive .
26+
python3 -m flake8 --config=.flake8.cfg .

debian/changelog

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ python-ev3dev2 (2.1.0) UNRELEASED; urgency=medium
77
* MoveDifferential use gyro for better accuracy. Make MoveTank and
88
MoveDifferential "turn" APIs more consistent.
99
* MoveTank turn_degrees convert speed to SpeedValue object
10+
* correct flake8 errors
1011

1112
[Matěj Volf]
1213
* LED animation fix duration None

docs/conf.py

+52-54
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,28 @@
1515

1616
import sys
1717
import os
18-
import shlex
1918
import subprocess
19+
import sphinx_bootstrap_theme
20+
from recommonmark.parser import CommonMarkParser
21+
from recommonmark.transform import AutoStructify
2022

2123
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
22-
from git_version import git_version
24+
from git_version import git_version # noqa: E402
2325

2426
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
2527

2628
if on_rtd:
2729
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'sphinx_bootstrap_theme', 'recommonmark', 'evdev'])
2830

29-
import sphinx_bootstrap_theme
30-
from recommonmark.parser import CommonMarkParser
31-
from recommonmark.transform import AutoStructify
32-
3331
# If extensions (or modules to document with autodoc) are in another directory,
3432
# add these directories to sys.path here. If the directory is relative to the
3533
# documentation root, use os.path.abspath to make it absolute, like shown here.
36-
#sys.path.insert(0, os.path.abspath('.'))
34+
# sys.path.insert(0, os.path.abspath('.'))
3735

3836
# -- General configuration ------------------------------------------------
3937

4038
# If your documentation needs a minimal Sphinx version, state it here.
41-
#needs_sphinx = '1.0'
39+
# needs_sphinx = '1.0'
4240

4341
# Add any Sphinx extension module names here, as strings. They can be
4442
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
@@ -61,7 +59,7 @@
6159
source_suffix = ['.rst', '.md']
6260

6361
# The encoding of source files.
64-
#source_encoding = 'utf-8-sig'
62+
# source_encoding = 'utf-8-sig'
6563

6664
# The master toctree document.
6765
master_doc = 'index'
@@ -89,37 +87,37 @@
8987

9088
# There are two options for replacing |today|: either, you set today to some
9189
# non-false value, then it is used:
92-
#today = ''
90+
# today = ''
9391
# Else, today_fmt is used as the format for a strftime call.
94-
#today_fmt = '%B %d, %Y'
92+
# today_fmt = '%B %d, %Y'
9593

9694
# List of patterns, relative to source directory, that match files and
9795
# directories to ignore when looking for source files.
9896
exclude_patterns = ['_build']
9997

10098
# The reST default role (used for this markup: `text`) to use for all
10199
# documents.
102-
#default_role = None
100+
# default_role = None
103101

104102
# If true, '()' will be appended to :func: etc. cross-reference text.
105-
#add_function_parentheses = True
103+
# add_function_parentheses = True
106104

107105
# If true, the current module name will be prepended to all description
108106
# unit titles (such as .. function::).
109-
#add_module_names = True
107+
# add_module_names = True
110108

111109
# If true, sectionauthor and moduleauthor directives will be shown in the
112110
# output. They are ignored by default.
113-
#show_authors = False
111+
# show_authors = False
114112

115113
# The name of the Pygments (syntax highlighting) style to use.
116114
pygments_style = 'sphinx'
117115

118116
# A list of ignored prefixes for module index sorting.
119-
#modindex_common_prefix = []
117+
# modindex_common_prefix = []
120118

121119
# If true, keep warnings as "system message" paragraphs in the built documents.
122-
#keep_warnings = False
120+
# keep_warnings = False
123121

124122
# If true, `todo` and `todoList` produce output, else they produce nothing.
125123
todo_include_todos = False
@@ -138,26 +136,26 @@
138136
# Theme options are theme-specific and customize the look and feel of a theme
139137
# further. For a list of options available for each theme, see the
140138
# documentation.
141-
#html_theme_options = {}
139+
# html_theme_options = {}
142140

143141
# Add any paths that contain custom themes here, relative to this directory.
144-
#html_theme_path = []
142+
# html_theme_path = []
145143

146144
# The name for this set of Sphinx documents. If None, it defaults to
147145
# "<project> v<release> documentation".
148-
#html_title = None
146+
# html_title = None
149147

150148
# A shorter title for the navigation bar. Default is the same as html_title.
151-
#html_short_title = None
149+
# html_short_title = None
152150

153151
# The name of an image file (relative to this directory) to place at the top
154152
# of the sidebar.
155-
#html_logo = None
153+
# html_logo = None
156154

157155
# The name of an image file (within the static path) to use as favicon of the
158156
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
159157
# pixels large.
160-
#html_favicon = None
158+
# html_favicon = None
161159

162160
# Add any paths that contain custom static files (such as style sheets) here,
163161
# relative to this directory. They are copied after the builtin static files,
@@ -167,62 +165,62 @@
167165
# Add any extra paths that contain custom files (such as robots.txt or
168166
# .htaccess) here, relative to this directory. These files are copied
169167
# directly to the root of the documentation.
170-
#html_extra_path = []
168+
# html_extra_path = []
171169

172170
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
173171
# using the given strftime format.
174-
#html_last_updated_fmt = '%b %d, %Y'
172+
# html_last_updated_fmt = '%b %d, %Y'
175173

176174
# If true, SmartyPants will be used to convert quotes and dashes to
177175
# typographically correct entities.
178-
#html_use_smartypants = True
176+
# html_use_smartypants = True
179177

180178
# Custom sidebar templates, maps document names to template names.
181-
#html_sidebars = {}
179+
# html_sidebars = {}
182180

183181
# Additional templates that should be rendered to pages, maps page names to
184182
# template names.
185-
#html_additional_pages = {}
183+
# html_additional_pages = {}
186184

187185
# If false, no module index is generated.
188-
#html_domain_indices = True
186+
# html_domain_indices = True
189187

190188
# If false, no index is generated.
191-
#html_use_index = True
189+
# html_use_index = True
192190

193191
# If true, the index is split into individual pages for each letter.
194-
#html_split_index = False
192+
# html_split_index = False
195193

196194
# If true, links to the reST sources are added to the pages.
197-
#html_show_sourcelink = True
195+
# html_show_sourcelink = True
198196

199197
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
200-
#html_show_sphinx = True
198+
# html_show_sphinx = True
201199

202200
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
203-
#html_show_copyright = True
201+
# html_show_copyright = True
204202

205203
# If true, an OpenSearch description file will be output, and all pages will
206204
# contain a <link> tag referring to it. The value of this option must be the
207205
# base URL from which the finished HTML is served.
208-
#html_use_opensearch = ''
206+
# html_use_opensearch = ''
209207

210208
# This is the file name suffix for HTML files (e.g. ".xhtml").
211-
#html_file_suffix = None
209+
# html_file_suffix = None
212210

213211
# Language to be used for generating the HTML full-text search index.
214212
# Sphinx supports the following languages:
215213
# 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
216214
# 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
217-
#html_search_language = 'en'
215+
# html_search_language = 'en'
218216

219217
# A dictionary with options for the search language support, empty by default.
220218
# Now only 'ja' uses this config value
221-
#html_search_options = {'type': 'default'}
219+
# html_search_options = {'type': 'default'}
222220

223221
# The name of a javascript file (relative to the configuration directory) that
224222
# implements a search results scorer. If empty, the default will be used.
225-
#html_search_scorer = 'scorer.js'
223+
# html_search_scorer = 'scorer.js'
226224

227225
# Output file base name for HTML help builder.
228226
htmlhelp_basename = 'python-ev3devdoc'
@@ -231,16 +229,16 @@
231229

232230
latex_elements = {
233231
# The paper size ('letterpaper' or 'a4paper').
234-
#'papersize': 'letterpaper',
232+
# 'papersize': 'letterpaper',
235233

236234
# The font size ('10pt', '11pt' or '12pt').
237-
#'pointsize': '10pt',
235+
# 'pointsize': '10pt',
238236

239237
# Additional stuff for the LaTeX preamble.
240-
#'preamble': '',
238+
# 'preamble': '',
241239

242240
# Latex figure (float) alignment
243-
#'figure_align': 'htbp',
241+
# 'figure_align': 'htbp',
244242
}
245243

246244
# Grouping the document tree into LaTeX files. List of tuples
@@ -252,23 +250,23 @@
252250

253251
# The name of an image file (relative to this directory) to place at the top of
254252
# the title page.
255-
#latex_logo = None
253+
# latex_logo = None
256254

257255
# For "manual" documents, if this is true, then toplevel headings are parts,
258256
# not chapters.
259-
#latex_use_parts = False
257+
# latex_use_parts = False
260258

261259
# If true, show page references after internal links.
262-
#latex_show_pagerefs = False
260+
# latex_show_pagerefs = False
263261

264262
# If true, show URL addresses after external links.
265-
#latex_show_urls = False
263+
# latex_show_urls = False
266264

267265
# Documents to append as an appendix to all manuals.
268-
#latex_appendices = []
266+
# latex_appendices = []
269267

270268
# If false, no module index is generated.
271-
#latex_domain_indices = True
269+
# latex_domain_indices = True
272270

273271
# -- Options for manual page output ---------------------------------------
274272

@@ -277,7 +275,7 @@
277275
man_pages = [(master_doc, 'python-ev3dev', 'python-ev3dev Documentation', [author], 1)]
278276

279277
# If true, show URL addresses after external links.
280-
#man_show_urls = False
278+
# man_show_urls = False
281279

282280
# -- Options for Texinfo output -------------------------------------------
283281

@@ -290,16 +288,16 @@
290288
]
291289

292290
# Documents to append as an appendix to all manuals.
293-
#texinfo_appendices = []
291+
# texinfo_appendices = []
294292

295293
# If false, no module index is generated.
296-
#texinfo_domain_indices = True
294+
# texinfo_domain_indices = True
297295

298296
# How to display URL addresses: 'footnote', 'no', or 'inline'.
299-
#texinfo_show_urls = 'footnote'
297+
# texinfo_show_urls = 'footnote'
300298

301299
# If true, do not generate a @detailmenu in the "Top" node's menu.
302-
#texinfo_no_detailmenu = False
300+
# texinfo_no_detailmenu = False
303301

304302
autodoc_member_order = 'bysource'
305303

ev3dev2/__init__.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@
2424
# -----------------------------------------------------------------------------
2525

2626
import sys
27+
import os
28+
import io
29+
import fnmatch
30+
import re
31+
import stat
32+
import errno
33+
from os.path import abspath
34+
35+
try:
36+
# if we are in a released build, there will be an auto-generated "version"
37+
# module
38+
from .version import __version__
39+
except ImportError:
40+
__version__ = "<unknown>"
2741

2842
if sys.version_info < (3, 4):
2943
raise SystemError('Must be using Python 3.4 or higher')
@@ -40,22 +54,6 @@ def chain_exception(exception, cause):
4054
raise exception from cause
4155

4256

43-
try:
44-
# if we are in a released build, there will be an auto-generated "version"
45-
# module
46-
from .version import __version__
47-
except ImportError:
48-
__version__ = "<unknown>"
49-
50-
import os
51-
import io
52-
import fnmatch
53-
import re
54-
import stat
55-
import errno
56-
from os.path import abspath
57-
58-
5957
def get_current_platform():
6058
"""
6159
Look in /sys/class/board-info/ to determine the platform type.
@@ -125,7 +123,7 @@ def matches(attribute, pattern):
125123
try:
126124
with io.FileIO(attribute) as f:
127125
value = f.read().strip().decode()
128-
except:
126+
except Exception:
129127
return False
130128

131129
if isinstance(pattern, list):

ev3dev2/button.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@
2424
# -----------------------------------------------------------------------------
2525

2626
import sys
27-
28-
if sys.version_info < (3, 4):
29-
raise SystemError('Must be using Python 3.4 or higher')
30-
3127
from ev3dev2.stopwatch import StopWatch
3228
from ev3dev2 import get_current_platform, is_micropython, library_load_warning_message
3329
from logging import getLogger
3430

35-
log = getLogger(__name__)
36-
3731
# Import the button filenames, this is platform specific
3832
platform = get_current_platform()
3933

@@ -58,6 +52,11 @@
5852
else:
5953
raise Exception("Unsupported platform '%s'" % platform)
6054

55+
if sys.version_info < (3, 4):
56+
raise SystemError('Must be using Python 3.4 or higher')
57+
58+
log = getLogger(__name__)
59+
6160

6261
class MissingButton(Exception):
6362
pass
@@ -199,7 +198,7 @@ def backspace(self):
199198

200199

201200
# micropython implementation
202-
if is_micropython():
201+
if is_micropython(): # noqa: C901
203202

204203
try:
205204
# This is a linux-specific module.

0 commit comments

Comments
 (0)