|
11 | 11 | from multiprocessing import Pool
|
12 | 12 | import json
|
13 | 13 | import os
|
14 |
| -import traceback |
15 | 14 |
|
16 | 15 | import click
|
17 | 16 | from PIL import Image, ImageDraw, ImageFont
|
|
43 | 42 | bundle_data = json.load(f)
|
44 | 43 | f.close()
|
45 | 44 |
|
46 |
| -def ASSET(x): |
| 45 | + |
| 46 | +def asset_path(x): |
| 47 | + """Return the location of a file shipped with the screenshot maker""" |
47 | 48 | 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")) |
51 | 49 |
|
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")) |
58 | 50 |
|
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")) |
62 | 65 |
|
63 | 66 | FILE_TYPE_ICON_MAP = {
|
64 | 67 | "py": file_icon,
|
@@ -291,7 +294,6 @@ def make_libraries(libraries, position):
|
291 | 294 |
|
292 | 295 | final_list_to_render = sort_libraries(libs)
|
293 | 296 |
|
294 |
| - |
295 | 297 | if "code.py" in project_files:
|
296 | 298 | project_files.remove("code.py")
|
297 | 299 |
|
@@ -320,45 +322,57 @@ def make_libraries(libraries, position):
|
320 | 322 | (PADDING, PADDING + (LINE_SPACING * (7 + project_files_count))),
|
321 | 323 | )
|
322 | 324 |
|
323 |
| - img.save( |
324 |
| - "generated_images/{}.png".format(image_name) |
325 |
| - ) |
| 325 | + img.save("generated_images/{}.png".format(image_name)) |
| 326 | + |
326 | 327 |
|
327 |
| -def generate_learn_requirement_image( |
| 328 | +def generate_learn_requirement_image( # pylint: disable=invalid-name |
328 | 329 | learn_guide_project,
|
329 | 330 | ):
|
| 331 | + """Generate an image for a single learn project""" |
330 | 332 | image_name = learn_guide_project.replace("/", "_")
|
331 | 333 | libs = get_libs_for_project(learn_guide_project)
|
332 | 334 | project_files = get_files_for_project(learn_guide_project)
|
333 | 335 | generate_requirement_image(project_files, libs, image_name)
|
334 | 336 |
|
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 | + ) |
340 | 345 | libs = get_libs_for_example(example_path)
|
341 | 346 | project_files = get_files_for_example(example_path)
|
342 | 347 | generate_requirement_image(project_files, libs, image_name)
|
343 | 348 |
|
| 349 | + |
344 | 350 | @click.group(invoke_without_command=True)
|
345 | 351 | @click.pass_context
|
346 | 352 | def cli(ctx):
|
| 353 | + """Main entry point; invokes the learn subcommand if nothing is specified""" |
347 | 354 | if ctx.invoked_subcommand is None:
|
348 | 355 | learn()
|
349 | 356 |
|
| 357 | + |
350 | 358 | @cli.command()
|
351 | 359 | 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 | + ): |
354 | 365 | pass
|
355 | 366 |
|
| 367 | + |
356 | 368 | @cli.command()
|
357 |
| -@click.argument('paths', nargs=-1) |
| 369 | +@click.argument("paths", nargs=-1) |
358 | 370 | 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): |
361 | 374 | pass
|
362 | 375 |
|
| 376 | + |
363 | 377 | if __name__ == "__main__":
|
364 |
| - cli() |
| 378 | + cli() # pylint: disable=no-value-for-parameter |
0 commit comments