Skip to content

Commit ecada24

Browse files
committed
pylint, black, etc
1 parent d89eb35 commit ecada24

File tree

2 files changed

+48
-33
lines changed

2 files changed

+48
-33
lines changed

create_requirement_images.py

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from multiprocessing import Pool
1212
import json
1313
import os
14-
import traceback
1514

1615
import click
1716
from PIL import Image, ImageDraw, ImageFont
@@ -43,22 +42,26 @@
4342
bundle_data = json.load(f)
4443
f.close()
4544

46-
def ASSET(x):
45+
46+
def asset_path(x):
47+
"""Return the location of a file shipped with the screenshot maker"""
4748
return os.path.join(os.path.dirname(__file__), x)
48-
font = ImageFont.truetype(ASSET("Roboto-Regular.ttf"), 24)
49-
right_triangle = Image.open(ASSET("img/right_triangle.png"))
50-
down_triangle = Image.open(ASSET("img/down_triangle.png"))
5149

52-
folder_icon = Image.open(ASSET("img/folder.png"))
53-
folder_hidden_icon = Image.open(ASSET("img/folder_hidden.png"))
54-
file_icon = Image.open(ASSET("img/file.png"))
55-
file_hidden_icon = Image.open(ASSET("img/file_hidden.png"))
56-
file_empty_icon = Image.open(ASSET("img/file_empty.png"))
57-
file_empty_hidden_icon = Image.open(ASSET("img/file_empty_hidden.png"))
5850

59-
file_image_icon = Image.open(ASSET("img/file_image.png"))
60-
file_music_icon = Image.open(ASSET("img/file_music.png"))
61-
file_font_icon = Image.open(ASSET("img/file_font.png"))
51+
font = ImageFont.truetype(asset_path("Roboto-Regular.ttf"), 24)
52+
right_triangle = Image.open(asset_path("img/right_triangle.png"))
53+
down_triangle = Image.open(asset_path("img/down_triangle.png"))
54+
55+
folder_icon = Image.open(asset_path("img/folder.png"))
56+
folder_hidden_icon = Image.open(asset_path("img/folder_hidden.png"))
57+
file_icon = Image.open(asset_path("img/file.png"))
58+
file_hidden_icon = Image.open(asset_path("img/file_hidden.png"))
59+
file_empty_icon = Image.open(asset_path("img/file_empty.png"))
60+
file_empty_hidden_icon = Image.open(asset_path("img/file_empty_hidden.png"))
61+
62+
file_image_icon = Image.open(asset_path("img/file_image.png"))
63+
file_music_icon = Image.open(asset_path("img/file_music.png"))
64+
file_font_icon = Image.open(asset_path("img/file_font.png"))
6265

6366
FILE_TYPE_ICON_MAP = {
6467
"py": file_icon,
@@ -291,7 +294,6 @@ def make_libraries(libraries, position):
291294

292295
final_list_to_render = sort_libraries(libs)
293296

294-
295297
if "code.py" in project_files:
296298
project_files.remove("code.py")
297299

@@ -320,45 +322,57 @@ def make_libraries(libraries, position):
320322
(PADDING, PADDING + (LINE_SPACING * (7 + project_files_count))),
321323
)
322324

323-
img.save(
324-
"generated_images/{}.png".format(image_name)
325-
)
325+
img.save("generated_images/{}.png".format(image_name))
326+
326327

327-
def generate_learn_requirement_image(
328+
def generate_learn_requirement_image( # pylint: disable=invalid-name
328329
learn_guide_project,
329330
):
331+
"""Generate an image for a single learn project"""
330332
image_name = learn_guide_project.replace("/", "_")
331333
libs = get_libs_for_project(learn_guide_project)
332334
project_files = get_files_for_project(learn_guide_project)
333335
generate_requirement_image(project_files, libs, image_name)
334336

335-
def generate_example_requirement_image(
336-
example_path
337-
):
338-
image_name = "_".join(element for element in example_path.split('/')
339-
if element not in ('libraries', 'drivers', 'helpers', 'examples'))
337+
338+
def generate_example_requirement_image(example_path): # pylint: disable=invalid-name
339+
"""Generate an image for a library example"""
340+
image_name = "_".join(
341+
element
342+
for element in example_path.split("/")
343+
if element not in ("libraries", "drivers", "helpers", "examples")
344+
)
340345
libs = get_libs_for_example(example_path)
341346
project_files = get_files_for_example(example_path)
342347
generate_requirement_image(project_files, libs, image_name)
343348

349+
344350
@click.group(invoke_without_command=True)
345351
@click.pass_context
346352
def cli(ctx):
353+
"""Main entry point; invokes the learn subcommand if nothing is specified"""
347354
if ctx.invoked_subcommand is None:
348355
learn()
349356

357+
350358
@cli.command()
351359
def learn():
352-
with Pool() as p:
353-
for _ in p.imap(generate_learn_requirement_image, get_learn_guide_cp_projects()):
360+
"""Generate images for a learn-style repo"""
361+
with Pool() as pool:
362+
for _ in pool.imap(
363+
generate_learn_requirement_image, get_learn_guide_cp_projects()
364+
):
354365
pass
355366

367+
356368
@cli.command()
357-
@click.argument('paths', nargs=-1)
369+
@click.argument("paths", nargs=-1)
358370
def bundle(paths):
359-
with Pool() as p:
360-
for _ in p.imap(generate_example_requirement_image, paths):
371+
"""Generate images for a bundle-style repo"""
372+
with Pool() as pool:
373+
for _ in pool.imap(generate_example_requirement_image, paths):
361374
pass
362375

376+
363377
if __name__ == "__main__":
364-
cli()
378+
cli() # pylint: disable=no-value-for-parameter

get_imports.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
SHOWN_FILETYPES = ["py", "mpy", "bmp", "pcf", "bdf", "wav", "mp3", "json", "txt"]
2323
SHOWN_FILETYPES_EXAMPLE = [s for s in SHOWN_FILETYPES if s != "py"]
2424

25+
2526
def get_bundle(tag):
2627
"""Download the given bundle's data to BUNDLE_DATA"""
2728
url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long
@@ -139,9 +140,10 @@ def get_libs_for_project(project_name):
139140

140141
return found_libs
141142

143+
142144
def get_files_for_example(example_path):
143145
"""Get the set of files for a library example"""
144-
found_files = set(('code.py',))
146+
found_files = set(("code.py",))
145147
example_dir = os.path.dirname(example_path)
146148
for file in os.listdir(example_dir):
147149
if "." in file:
@@ -169,12 +171,11 @@ def get_libs_for_example(example_path):
169171
return found_libs
170172

171173

172-
173174
def get_learn_guide_cp_projects():
174175
"""Get the list of all circuitpython projects, according to some heuristics"""
175176
for dirpath, dirnames, filenames in os.walk(LEARN_GUIDE_REPO):
176177
# Don't consider hidden directories
177-
dirnames[:] = [d for d in dirnames if not d.startswith('.')]
178+
dirnames[:] = [d for d in dirnames if not d.startswith(".")]
178179

179180
# The top-level needs special treatment
180181
if dirpath == LEARN_GUIDE_REPO:

0 commit comments

Comments
 (0)