Skip to content

Commit 3e020c0

Browse files
authored
Merge pull request #9 from adafruit/pylint-update
Pylint update
2 parents 01eb182 + 8c7209c commit 3e020c0

File tree

6 files changed

+123
-107
lines changed

6 files changed

+123
-107
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_bitmapsaver.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,39 +54,44 @@
5454

5555

5656
def _write_bmp_header(output_file, filesize):
57-
output_file.write(bytes('BM', 'ascii'))
58-
output_file.write(struct.pack('<I', filesize))
59-
output_file.write(b'\00\x00')
60-
output_file.write(b'\00\x00')
61-
output_file.write(struct.pack('<I', 54))
57+
output_file.write(bytes("BM", "ascii"))
58+
output_file.write(struct.pack("<I", filesize))
59+
output_file.write(b"\00\x00")
60+
output_file.write(b"\00\x00")
61+
output_file.write(struct.pack("<I", 54))
62+
6263

6364
def _write_dib_header(output_file, width, height):
64-
output_file.write(struct.pack('<I', 40))
65-
output_file.write(struct.pack('<I', width))
66-
output_file.write(struct.pack('<I', height))
67-
output_file.write(struct.pack('<H', 1))
68-
output_file.write(struct.pack('<H', 24))
65+
output_file.write(struct.pack("<I", 40))
66+
output_file.write(struct.pack("<I", width))
67+
output_file.write(struct.pack("<I", height))
68+
output_file.write(struct.pack("<H", 1))
69+
output_file.write(struct.pack("<H", 24))
6970
for _ in range(24):
70-
output_file.write(b'\x00')
71+
output_file.write(b"\x00")
72+
7173

7274
def _bytes_per_row(source_width):
7375
pixel_bytes = 3 * source_width
7476
padding_bytes = (4 - (pixel_bytes % 4)) % 4
7577
return pixel_bytes + padding_bytes
7678

79+
7780
def _rotated_height_and_width(pixel_source):
7881
# flip axis if the display is rotated
7982
if isinstance(pixel_source, Display) and (pixel_source.rotation % 180 != 0):
8083
return (pixel_source.height, pixel_source.width)
8184
return (pixel_source.width, pixel_source.height)
8285

86+
8387
def _rgb565_to_bgr_tuple(color):
84-
blue = (color << 3) & 0x00F8 # extract each of the RGB tripple into it's own byte
88+
blue = (color << 3) & 0x00F8 # extract each of the RGB tripple into it's own byte
8589
green = (color >> 3) & 0x00FC
8690
red = (color >> 8) & 0x00F8
8791
return (blue, green, red)
8892

89-
#pylint:disable=too-many-locals
93+
94+
# pylint:disable=too-many-locals
9095
def _write_pixels(output_file, pixel_source, palette):
9196
saving_bitmap = isinstance(pixel_source, Bitmap)
9297
width, height = _rotated_height_and_width(pixel_source)
@@ -96,22 +101,25 @@ def _write_pixels(output_file, pixel_source, palette):
96101
buffer_index = 0
97102
if saving_bitmap:
98103
for x in range(width):
99-
pixel = pixel_source[x, y-1]
104+
pixel = pixel_source[x, y - 1]
100105
color = palette[pixel]
101106
for _ in range(3):
102107
row_buffer[buffer_index] = color & 0xFF
103108
color >>= 8
104109
buffer_index += 1
105110
else:
106-
data = pixel_source.fill_row(y-1, result_buffer)
111+
data = pixel_source.fill_row(y - 1, result_buffer)
107112
for i in range(width):
108113
pixel565 = (data[i * 2] << 8) + data[i * 2 + 1]
109114
for b in _rgb565_to_bgr_tuple(pixel565):
110115
row_buffer[buffer_index] = b & 0xFF
111116
buffer_index += 1
112117
output_file.write(row_buffer)
113118
gc.collect()
114-
#pylint:enable=too-many-locals
119+
120+
121+
# pylint:enable=too-many-locals
122+
115123

116124
def save_pixels(file_or_filename, pixel_source=board.DISPLAY, palette=None):
117125
"""Save pixels to a 24 bit per pixel BMP file.
@@ -124,12 +132,12 @@ def save_pixels(file_or_filename, pixel_source=board.DISPLAY, palette=None):
124132
"""
125133
if isinstance(pixel_source, Bitmap):
126134
if not isinstance(palette, Palette):
127-
raise ValueError('Third argument must be a Palette for a Bitmap save')
135+
raise ValueError("Third argument must be a Palette for a Bitmap save")
128136
elif not isinstance(pixel_source, Display):
129-
raise ValueError('Second argument must be a Bitmap or Display')
137+
raise ValueError("Second argument must be a Bitmap or Display")
130138
try:
131139
if isinstance(file_or_filename, str):
132-
output_file = open(file_or_filename, 'wb')
140+
output_file = open(file_or_filename, "wb")
133141
else:
134142
output_file = file_or_filename
135143

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
autodoc_mock_imports = ["displayio", "digitalio", "busio", "board"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'Adafruit BitmapSaver Library'
38-
copyright = u'2019 Dave Astels'
39-
author = u'Dave Astels'
41+
project = "Adafruit BitmapSaver Library"
42+
copyright = "2019 Dave Astels"
43+
author = "Dave Astels"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = "1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = "1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,68 +88,76 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

100105
# Add any paths that contain custom static files (such as style sheets) here,
101106
# relative to this directory. They are copied after the builtin static files,
102107
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
108+
html_static_path = ["_static"]
104109

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitBitmapsaverLibrarydoc'
117+
htmlhelp_basename = "AdafruitBitmapsaverLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'AdafruitBitmapSaverLibrary.tex', u'AdafruitBitmapSaver Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitBitmapSaverLibrary.tex",
143+
"AdafruitBitmapSaver Library Documentation",
144+
author,
145+
"manual",
146+
),
140147
]
141148

142149
# -- Options for manual page output ---------------------------------------
143150

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'AdafruitBitmapSaverlibrary', u'Adafruit BitmapSaver Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitBitmapSaverlibrary",
157+
"Adafruit BitmapSaver Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'AdafruitBitmapSaverLibrary', u'Adafruit BitmapSaver Library Documentation',
158-
author, 'AdafruitBitmapSaverLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitBitmapSaverLibrary",
172+
"Adafruit BitmapSaver Library Documentation",
173+
author,
174+
"AdafruitBitmapSaverLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

examples/bitmapsaver_screenshot_simpletest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
"""Example of taking a screenshot."""
2424

25-
#pylint:disable=invalid-name
25+
# pylint:disable=invalid-name
2626
import board
2727
import digitalio
2828
import busio
@@ -37,6 +37,6 @@
3737
vfs = storage.VfsFat(sdcard)
3838
storage.mount(vfs, "/sd")
3939

40-
print('Taking Screenshot...')
41-
save_pixels('/sd/screenshot.bmp')
42-
print('Screenshot taken')
40+
print("Taking Screenshot...")
41+
save_pixels("/sd/screenshot.bmp")
42+
print("Screenshot taken")

examples/bitmapsaver_simpletest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
import storage
3131
from adafruit_bitmapsaver import save_pixels
3232

33-
#pylint:disable=invalid-name
33+
# pylint:disable=invalid-name
3434

35-
print('Setting up SD card')
35+
print("Setting up SD card")
3636
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
3737
cs = digitalio.DigitalInOut(board.SD_CS)
3838
sdcard = adafruit_sdcard.SDCard(spi, cs)
@@ -51,7 +51,7 @@
5151

5252
colors = (BLACK, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, WHITE)
5353

54-
print('Building sample bitmap and palette')
54+
print("Building sample bitmap and palette")
5555
bitmap = Bitmap(16, 16, 9)
5656
palette = Palette(len(colors))
5757
for i, c in enumerate(colors):
@@ -68,5 +68,5 @@
6868
else:
6969
bitmap[x, y] = 0
7070

71-
print('Saving bitmap')
72-
save_pixels('/sd/test.bmp', bitmap, palette)
71+
print("Saving bitmap")
72+
save_pixels("/sd/test.bmp", bitmap, palette)

0 commit comments

Comments
 (0)