Skip to content

Commit ea37919

Browse files
committed
Make pylint-compliant. Remove some uneeded files
1 parent c63aa7f commit ea37919

File tree

5 files changed

+48
-83
lines changed

5 files changed

+48
-83
lines changed

README.md

-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ One directory above the root of this repo.
1414

1515
With that pointed at a learn guide repo you can run:
1616

17-
```
18-
python get_bundle_data.py
19-
```
20-
to download `latest_bundle_data.json`
21-
22-
Once this file is present run
2317
```
2418
python create_requirement_images.py
2519
```

create_requirement_images.py

+28-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#!/usr/bin/env python3
22

3+
"""
4+
Create requirement screenshots for learn guide projects
5+
"""
6+
37
# SPDX-FileCopyrightText: 2021 foamyguy
48
#
59
# SPDX-License-Identifier: MIT
@@ -63,63 +67,68 @@
6367
"json": file_icon,
6468
}
6569

66-
for img in FILE_TYPE_ICON_MAP.values():
67-
img.load()
70+
# If this is not done, the images fail to load in the subprocesses.
71+
for file_icon in FILE_TYPE_ICON_MAP.values():
72+
file_icon.load()
73+
6874

75+
def generate_requirement_image(
76+
learn_guide_project,
77+
): # pylint: disable=too-many-statements
78+
"""Generate a single requirement image"""
6979

70-
def generate_requirement_image(learn_guide_project):
7180
def make_line(
7281
requirement_name, position=(0, 0), icon=None, hidden=False, triangle_icon=None
73-
):
82+
): # pylint: disable=too-many-branches
7483
if triangle_icon:
75-
im.paste(
84+
img.paste(
7685
triangle_icon,
7786
(position[0] - 24, position[1] + (LINE_SPACING - 24) // 2),
7887
mask=triangle_icon,
7988
)
80-
if icon == None:
89+
if icon is None:
8190
if requirement_name.endswith(".mpy") or requirement_name.endswith(".py"):
8291
if hidden:
83-
im.paste(
92+
img.paste(
8493
file_hidden_icon,
8594
(position[0], position[1] + (LINE_SPACING - 24) // 2),
8695
mask=file_hidden_icon,
8796
)
8897
else:
89-
im.paste(
98+
img.paste(
9099
file_icon,
91100
(position[0], position[1] + (LINE_SPACING - 24) // 2),
92101
mask=file_icon,
93102
)
94103

95104
elif "." in requirement_name[-5:]:
96105
if hidden:
97-
im.paste(
106+
img.paste(
98107
file_empty_hidden_icon,
99108
(position[0], position[1] + (LINE_SPACING - 24) // 2),
100109
mask=file_empty_icon,
101110
)
102111
else:
103-
im.paste(
112+
img.paste(
104113
file_empty_icon,
105114
(position[0], position[1] + (LINE_SPACING - 24) // 2),
106115
mask=file_empty_icon,
107116
)
108117
else:
109118
if hidden:
110-
im.paste(
119+
img.paste(
111120
folder_hidden_icon,
112121
(position[0], position[1] + (LINE_SPACING - 24) // 2),
113122
mask=folder_hidden_icon,
114123
)
115124
else:
116-
im.paste(
125+
img.paste(
117126
folder_icon,
118127
(position[0], position[1] + (LINE_SPACING - 24) // 2),
119128
mask=folder_icon,
120129
)
121130
else:
122-
im.paste(
131+
img.paste(
123132
icon, (position[0], position[1] + (LINE_SPACING - 24) // 2), mask=icon
124133
)
125134

@@ -193,10 +202,7 @@ def make_header(position, learn_guide_project):
193202
for i, file in enumerate(sorted(project_files_to_draw)):
194203
cur_file_extension = file.split(".")[-1]
195204

196-
if cur_file_extension in FILE_TYPE_ICON_MAP:
197-
cur_file_icon = FILE_TYPE_ICON_MAP[cur_file_extension]
198-
else:
199-
cur_file_icon = file_empty_icon
205+
cur_file_icon = FILE_TYPE_ICON_MAP.get(cur_file_extension, file_empty_icon)
200206
make_line(
201207
file,
202208
(position[0] + INDENT_SIZE, position[1] + (LINE_SPACING * (6 + i))),
@@ -305,8 +311,8 @@ def make_libraries(libraries, position):
305311
+ len(final_list_to_render) * LINE_SPACING
306312
+ (project_files_count) * LINE_SPACING
307313
)
308-
im = Image.new("RGB", (OUT_WIDTH, image_height), "#303030")
309-
draw = ImageDraw.Draw(im)
314+
img = Image.new("RGB", (OUT_WIDTH, image_height), "#303030")
315+
draw = ImageDraw.Draw(img)
310316

311317
make_background_highlights(
312318
7 + len(final_list_to_render) + project_files_count,
@@ -319,9 +325,9 @@ def make_libraries(libraries, position):
319325
(PADDING, PADDING + (LINE_SPACING * (7 + project_files_count))),
320326
)
321327

322-
im.save("generated_images/{}.png".format(learn_guide_project))
323-
except SyntaxError as e:
324-
print(e)
328+
img.save("generated_images/{}.png".format(learn_guide_project))
329+
except SyntaxError as exc:
330+
print(exc)
325331
traceback.print_exc()
326332
print("SyntaxError finding imports for {}".format(learn_guide_project))
327333

get_bundle_data.py

-25
This file was deleted.

get_imports.py

+20-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
# SPDX-FileCopyrightText: 2021 foamyguy
2+
# SPDX-FileCopyrightText: 2019 Nicholas Tollervey, written for Adafruit Industries
23
#
34
# SPDX-License-Identifier: MIT
45

5-
import requests
6+
"""
7+
Get the list of required libraries based on a file's imports
8+
"""
9+
610
import json
711
import os
812
import findimports
13+
import requests
914

1015
BUNDLE_DATA = "latest_bundle_data.json"
1116
BUNDLE_TAG = "latest_bundle_tag.json"
@@ -18,30 +23,17 @@
1823

1924

2025
def get_bundle(tag):
21-
url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json"
26+
"""Download the given bundle's data to BUNDLE_DATA"""
27+
url = f"https://adafruit-circuit-python.s3.amazonaws.com/bundles/adafruit/adafruit-circuitpython-bundle-{tag}.json" # pylint: disable=line-too-long
2228
print(f"get bundle metadata from {url}")
2329
r = requests.get(url)
24-
with open(BUNDLE_DATA, "wb") as f:
25-
f.write(r.content)
30+
with open(BUNDLE_DATA, "wb") as bundle_file:
31+
bundle_file.write(r.content)
2632

2733

2834
LATEST_BUNDLE_VERSION = ""
2935

3036

31-
def get_latest_tag():
32-
"""
33-
Find the value of the latest tag for the Adafruit CircuitPython library
34-
bundle.
35-
:return: The most recent tag value for the project.
36-
"""
37-
global LATEST_BUNDLE_VERSION
38-
if not LATEST_BUNDLE_VERSION:
39-
LATEST_BUNDLE_VERSION = get_latest_release_from_url(
40-
"https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest"
41-
)
42-
return LATEST_BUNDLE_VERSION
43-
44-
4537
def get_latest_release_from_url(url):
4638
"""
4739
Find the tag name of the latest release by using HTTP HEAD and decoding the redirect.
@@ -65,7 +57,7 @@ def get_latest_tag():
6557
bundle.
6658
:return: The most recent tag value for the project.
6759
"""
68-
global LATEST_BUNDLE_VERSION
60+
global LATEST_BUNDLE_VERSION # pylint: disable=global-statement
6961
if LATEST_BUNDLE_VERSION == "":
7062
LATEST_BUNDLE_VERSION = get_latest_release_from_url(
7163
"https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest"
@@ -85,7 +77,7 @@ def ensure_latest_bundle():
8577
with open(BUNDLE_TAG, encoding="utf-8") as data:
8678
try:
8779
old_tag = json.load(data)["tag"]
88-
except json.decoder.JSONDecodeError as ex:
80+
except json.decoder.JSONDecodeError as _:
8981
# Sometimes (why?) the JSON file becomes corrupt. In which case
9082
# log it and carry on as if setting up for first time.
9183
print(f"Could not parse {BUNDLE_TAG:r}")
@@ -95,7 +87,7 @@ def ensure_latest_bundle():
9587
get_bundle(tag)
9688
with open(BUNDLE_TAG, "w", encoding="utf-8") as data:
9789
json.dump({"tag": tag}, data)
98-
except requests.exceptions.HTTPError as ex:
90+
except requests.exceptions.HTTPError as _:
9991
# See #20 for reason this this
10092
print(
10193
(
@@ -115,6 +107,7 @@ def ensure_latest_bundle():
115107

116108

117109
def get_files_for_project(project_name):
110+
"""Get the set of files for a learn project"""
118111
found_files = set()
119112
project_dir = "{}/{}/".format(LEARN_GUIDE_REPO, project_name)
120113
for file in os.listdir(project_dir):
@@ -130,6 +123,7 @@ def get_files_for_project(project_name):
130123

131124

132125
def get_libs_for_project(project_name):
126+
"""Get the set of libraries for a learn project"""
133127
found_libs = set()
134128
found_imports = []
135129
project_dir = "{}{}/".format(LEARN_GUIDE_REPO, project_name)
@@ -147,20 +141,19 @@ def get_libs_for_project(project_name):
147141

148142

149143
def get_learn_guide_projects():
144+
"""Get the list of all folders in the learn guide"""
150145
return os.listdir(LEARN_GUIDE_REPO)
151146

152147

153148
def get_learn_guide_cp_projects():
149+
"""Get the list of all circuitpython projects, according to some heuristics"""
154150
cp_projects = []
155151

156-
def has_py_file(dir):
157-
dir_files = os.listdir(dir)
152+
def has_py_file(location):
153+
dir_files = os.listdir(location)
158154
for file in dir_files:
159155
if file.endswith(".py"):
160-
if ".circuitpython.skip" not in dir_files:
161-
return True
162-
else:
163-
return False
156+
return ".circuitpython.skip" not in dir_files
164157
return False
165158

166159
all_projects = get_learn_guide_projects()

python_generator/.gitignore.license

-3
This file was deleted.

0 commit comments

Comments
 (0)