Skip to content

Commit 80bcc71

Browse files
authored
Merge pull request #88 from radarhere/lint
Lint fixes
2 parents 6e73670 + 909b012 commit 80bcc71

File tree

3 files changed

+70
-60
lines changed

3 files changed

+70
-60
lines changed

Diff for: doc/conf.py

+58-52
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import sys
1616
import os
1717

18+
import sane
19+
1820
# -- Mock module for _sane
1921
try:
2022
from unittest.mock import MagicMock
@@ -25,20 +27,24 @@ def __getattr__(cls, name):
2527
return Mock()
2628

2729
sys.modules.update([('_sane', Mock())])
28-
except:
30+
except Exception:
2931
pass
3032

3133

3234
# If extensions (or modules to document with autodoc) are in another directory,
3335
# add these directories to sys.path here. If the directory is relative to the
3436
# documentation root, use os.path.abspath to make it absolute, like shown here.
35-
libbuilddir = "lib.{p}-{v[0]}.{v[1]}".format(p=sysconfig.get_platform(), v=sys.version_info)
36-
sys.path.insert(0, os.path.join(os.path.abspath('.'), '..', 'build', libbuilddir))
37+
libbuilddir = "lib.{p}-{v[0]}.{v[1]}".format(
38+
p=sysconfig.get_platform(), v=sys.version_info
39+
)
40+
sys.path.insert(
41+
0, os.path.join(os.path.abspath('.'), '..', 'build', libbuilddir)
42+
)
3743

3844
# -- General configuration ------------------------------------------------
3945

4046
# If your documentation needs a minimal Sphinx version, state it here.
41-
#needs_sphinx = '1.0'
47+
# needs_sphinx = '1.0'
4248

4349
# Add any Sphinx extension module names here, as strings. They can be
4450
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
@@ -55,7 +61,7 @@ def __getattr__(cls, name):
5561
source_suffix = '.rst'
5662

5763
# The encoding of source files.
58-
#source_encoding = 'utf-8-sig'
64+
# source_encoding = 'utf-8-sig'
5965

6066
# The master toctree document.
6167
master_doc = 'index'
@@ -68,49 +74,48 @@ def __getattr__(cls, name):
6874
# |version| and |release|, also used in various other places throughout the
6975
# built documents.
7076
#
71-
import sane
7277
# The short X.Y version.
7378
version = sane.__version__
7479
# The full version, including alpha/beta/rc tags.
7580
release = sane.__version__
7681

7782
# The language for content autogenerated by Sphinx. Refer to documentation
7883
# for a list of supported languages.
79-
#language = None
84+
# language = None
8085

8186
# There are two options for replacing |today|: either, you set today to some
8287
# non-false value, then it is used:
83-
#today = ''
88+
# today = ''
8489
# Else, today_fmt is used as the format for a strftime call.
85-
#today_fmt = '%B %d, %Y'
90+
# today_fmt = '%B %d, %Y'
8691

8792
# List of patterns, relative to source directory, that match files and
8893
# directories to ignore when looking for source files.
8994
exclude_patterns = ['_build']
9095

9196
# The reST default role (used for this markup: `text`) to use for all
9297
# documents.
93-
#default_role = None
98+
# default_role = None
9499

95100
# If true, '()' will be appended to :func: etc. cross-reference text.
96-
#add_function_parentheses = True
101+
# add_function_parentheses = True
97102

98103
# If true, the current module name will be prepended to all description
99104
# unit titles (such as .. function::).
100-
#add_module_names = True
105+
# add_module_names = True
101106

102107
# If true, sectionauthor and moduleauthor directives will be shown in the
103108
# output. They are ignored by default.
104-
#show_authors = False
109+
# show_authors = False
105110

106111
# The name of the Pygments (syntax highlighting) style to use.
107112
pygments_style = 'sphinx'
108113

109114
# A list of ignored prefixes for module index sorting.
110-
#modindex_common_prefix = []
115+
# modindex_common_prefix = []
111116

112117
# If true, keep warnings as "system message" paragraphs in the built documents.
113-
#keep_warnings = False
118+
# keep_warnings = False
114119

115120

116121
# -- Options for HTML output ----------------------------------------------
@@ -122,26 +127,26 @@ def __getattr__(cls, name):
122127
# Theme options are theme-specific and customize the look and feel of a theme
123128
# further. For a list of options available for each theme, see the
124129
# documentation.
125-
#html_theme_options = {}
130+
# html_theme_options = {}
126131

127132
# Add any paths that contain custom themes here, relative to this directory.
128-
#html_theme_path = []
133+
# html_theme_path = []
129134

130135
# The name for this set of Sphinx documents. If None, it defaults to
131136
# "<project> v<release> documentation".
132-
#html_title = None
137+
# html_title = None
133138

134139
# A shorter title for the navigation bar. Default is the same as html_title.
135-
#html_short_title = None
140+
# html_short_title = None
136141

137142
# The name of an image file (relative to this directory) to place at the top
138143
# of the sidebar.
139-
#html_logo = None
144+
# html_logo = None
140145

141146
# The name of an image file (within the static path) to use as favicon of the
142147
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
143148
# pixels large.
144-
#html_favicon = None
149+
# html_favicon = None
145150

146151
# Add any paths that contain custom static files (such as style sheets) here,
147152
# relative to this directory. They are copied after the builtin static files,
@@ -151,48 +156,48 @@ def __getattr__(cls, name):
151156
# Add any extra paths that contain custom files (such as robots.txt or
152157
# .htaccess) here, relative to this directory. These files are copied
153158
# directly to the root of the documentation.
154-
#html_extra_path = []
159+
# html_extra_path = []
155160

156161
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
157162
# using the given strftime format.
158-
#html_last_updated_fmt = '%b %d, %Y'
163+
# html_last_updated_fmt = '%b %d, %Y'
159164

160165
# If true, SmartyPants will be used to convert quotes and dashes to
161166
# typographically correct entities.
162-
#html_use_smartypants = True
167+
# html_use_smartypants = True
163168

164169
# Custom sidebar templates, maps document names to template names.
165-
#html_sidebars = {}
170+
# html_sidebars = {}
166171

167172
# Additional templates that should be rendered to pages, maps page names to
168173
# template names.
169-
#html_additional_pages = {}
174+
# html_additional_pages = {}
170175

171176
# If false, no module index is generated.
172-
#html_domain_indices = True
177+
# html_domain_indices = True
173178

174179
# If false, no index is generated.
175-
#html_use_index = True
180+
# html_use_index = True
176181

177182
# If true, the index is split into individual pages for each letter.
178-
#html_split_index = False
183+
# html_split_index = False
179184

180185
# If true, links to the reST sources are added to the pages.
181-
#html_show_sourcelink = True
186+
# html_show_sourcelink = True
182187

183188
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
184-
#html_show_sphinx = True
189+
# html_show_sphinx = True
185190

186191
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
187-
#html_show_copyright = True
192+
# html_show_copyright = True
188193

189194
# If true, an OpenSearch description file will be output, and all pages will
190195
# contain a <link> tag referring to it. The value of this option must be the
191196
# base URL from which the finished HTML is served.
192-
#html_use_opensearch = ''
197+
# html_use_opensearch = ''
193198

194199
# This is the file name suffix for HTML files (e.g. ".xhtml").
195-
#html_file_suffix = None
200+
# html_file_suffix = None
196201

197202
# Output file base name for HTML help builder.
198203
htmlhelp_basename = 'python-sanedoc'
@@ -201,14 +206,14 @@ def __getattr__(cls, name):
201206
# -- Options for LaTeX output ---------------------------------------------
202207

203208
latex_elements = {
204-
# The paper size ('letterpaper' or 'a4paper').
205-
#'papersize': 'letterpaper',
209+
# The paper size ('letterpaper' or 'a4paper').
210+
# 'papersize': 'letterpaper',
206211

207-
# The font size ('10pt', '11pt' or '12pt').
208-
#'pointsize': '10pt',
212+
# The font size ('10pt', '11pt' or '12pt').
213+
# 'pointsize': '10pt',
209214

210-
# Additional stuff for the LaTeX preamble.
211-
#'preamble': '',
215+
# Additional stuff for the LaTeX preamble.
216+
# 'preamble': '',
212217
}
213218

214219
# Grouping the document tree into LaTeX files. List of tuples
@@ -221,23 +226,23 @@ def __getattr__(cls, name):
221226

222227
# The name of an image file (relative to this directory) to place at the top of
223228
# the title page.
224-
#latex_logo = None
229+
# latex_logo = None
225230

226231
# For "manual" documents, if this is true, then toplevel headings are parts,
227232
# not chapters.
228-
#latex_use_parts = False
233+
# latex_use_parts = False
229234

230235
# If true, show page references after internal links.
231-
#latex_show_pagerefs = False
236+
# latex_show_pagerefs = False
232237

233238
# If true, show URL addresses after external links.
234-
#latex_show_urls = False
239+
# latex_show_urls = False
235240

236241
# Documents to append as an appendix to all manuals.
237-
#latex_appendices = []
242+
# latex_appendices = []
238243

239244
# If false, no module index is generated.
240-
#latex_domain_indices = True
245+
# latex_domain_indices = True
241246

242247

243248
# -- Options for manual page output ---------------------------------------
@@ -250,7 +255,7 @@ def __getattr__(cls, name):
250255
]
251256

252257
# If true, show URL addresses after external links.
253-
#man_show_urls = False
258+
# man_show_urls = False
254259

255260

256261
# -- Options for Texinfo output -------------------------------------------
@@ -261,18 +266,19 @@ def __getattr__(cls, name):
261266
texinfo_documents = [
262267
('index', 'python-sane', 'python-sane Documentation',
263268
'Andrew Kuchling, Ralph Heinkel, Sandro Mani', 'python-sane',
264-
'Provides an interface to the SANE scanner and frame grabber interface for Linux',
269+
'Provides an interface to the SANE scanner and frame grabber interface for'
270+
' Linux',
265271
'Miscellaneous'),
266272
]
267273

268274
# Documents to append as an appendix to all manuals.
269-
#texinfo_appendices = []
275+
# texinfo_appendices = []
270276

271277
# If false, no module index is generated.
272-
#texinfo_domain_indices = True
278+
# texinfo_domain_indices = True
273279

274280
# How to display URL addresses: 'footnote', 'no', or 'inline'.
275-
#texinfo_show_urls = 'footnote'
281+
# texinfo_show_urls = 'footnote'
276282

277283
# If true, do not generate a @detailmenu in the "Top" node's menu.
278-
#texinfo_no_detailmenu = False
284+
# texinfo_no_detailmenu = False

Diff for: example.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,26 @@
3333
params = dev.get_parameters()
3434
try:
3535
dev.depth = depth
36-
except:
36+
except Exception:
3737
print('Cannot set depth, defaulting to %d' % params[3])
3838

3939
try:
4040
dev.mode = mode
41-
except:
41+
except Exception:
4242
print('Cannot set mode, defaulting to %s' % params[0])
4343

4444
try:
4545
dev.br_x = 320.
4646
dev.br_y = 240.
47-
except:
47+
except Exception:
4848
print('Cannot set scan area, using default')
4949

5050
params = dev.get_parameters()
51-
print('Device parameters:', params, "\n Resolutions %d, x %d, y %d "%(dev.resolution, dev.x_resolution, dev.y_resolution))
51+
print(
52+
'Device parameters:', params,
53+
'\n Resolutions %d, x %d, y %d '
54+
% (dev.resolution, dev.x_resolution, dev.y_resolution)
55+
)
5256

5357
#
5458
# Start a scan and get a PIL.Image object
@@ -72,7 +76,7 @@
7276
arr = (arr / 255).astype(numpy.uint8)
7377

7478
# reshape needed by PIL library
75-
arr=arr.reshape(arr.shape[2],arr.shape[1],arr.shape[0])
79+
arr = arr.reshape(arr.shape[2], arr.shape[1], arr.shape[0])
7680
if params[0] == 'color':
7781
im = Image.frombytes('RGB', arr.shape[1:], arr.tostring(), 'raw', 'RGB', 0,
7882
1)

Diff for: sane.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def __iter__(self):
118118
def __del__(self):
119119
try:
120120
self.device.cancel()
121-
except:
121+
except Exception:
122122
# In case device was already closed
123123
pass
124124

@@ -294,7 +294,7 @@ def snap(self, no_cancel=False, progress=None):
294294
"""
295295
try:
296296
from PIL import Image
297-
except:
297+
except ImportError:
298298
raise RuntimeError("Cannot import PIL.Image")
299299
result = self.dev.snap(no_cancel, False, progress)
300300
data, width, height, samples, sampleSize = result
@@ -323,7 +323,7 @@ def arr_snap(self, progress=None):
323323
"""
324324
try:
325325
import numpy
326-
except:
326+
except ImportError:
327327
raise RuntimeError("Cannot import numpy")
328328
result = self.dev.snap(False, True, progress)
329329
data, width, height, samples, sampleSize = result

0 commit comments

Comments
 (0)