Skip to content

Commit fd0bb36

Browse files
committed
pylint. removed unused things
1 parent fdb99fa commit fd0bb36

File tree

1 file changed

+14
-79
lines changed

1 file changed

+14
-79
lines changed

size_tools.py

+14-79
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,6 @@
2222
__repo__ = "https://github.com/circuitpython/CircuitPython_Org_size_tools.git"
2323

2424
import os
25-
import zipfile
26-
import requests
27-
import toml
28-
29-
30-
def download_latest_bundle():
31-
"""
32-
download teh latest bundle zip and extract it.
33-
34-
:return: string download_filename: the name of downloaded bundle zip file.
35-
"""
36-
json_resp = requests.get(
37-
"https://api.github.com/repos/adafruit/Adafruit_CircuitPython_Bundle/releases/latest"
38-
).json()
39-
40-
for asset in json_resp["assets"]:
41-
if "adafruit-circuitpython-bundle-8" in asset["name"]:
42-
# print(asset["browser_download_url"])
43-
bundle_zip = requests.get(
44-
asset["browser_download_url"], allow_redirects=True
45-
)
46-
download_filename = asset["browser_download_url"].split("/")[-1]
47-
48-
with open(download_filename, "wb") as bundle_out:
49-
bundle_out.write(bundle_zip.content)
50-
bundle_out.close()
51-
with zipfile.ZipFile(download_filename, "r") as zip_ref:
52-
zip_ref.extractall(".")
53-
# shutil.move(f'{download_filename.replace(".zip", "")}/lib/', ".")
54-
# shutil.move(f'{download_filename.replace(".zip", "")}/examples/', ".")
55-
return download_filename
5625

5726

5827
def find_v8_mpy_zip():
@@ -114,6 +83,7 @@ def measure_sizes():
11483
11584
:return: None
11685
"""
86+
# pylint: disable=too-many-locals, invalid-name, too-many-statements
11787

11888
original_working_dir = os.getcwd()
11989
_cur_version_size = -1
@@ -128,13 +98,6 @@ def measure_sizes():
12898
PERCENT_STRINGS_FLAG_VALUE = 50 # percent of mpy file(s) to trigger comment
12999

130100
output_str = ""
131-
# read module name from pyproject.toml
132-
pyproject_data = toml.load("pyproject.toml")
133-
if "packages" in pyproject_data["tool"]["setuptools"]:
134-
135-
module_name = pyproject_data["tool"]["setuptools"]["packages"][0]
136-
elif "py-modules" in pyproject_data["tool"]["setuptools"]:
137-
module_name = pyproject_data["tool"]["setuptools"]["py-modules"][0]
138101

139102
# New Version:
140103
found_v8_mpy_zip = find_v8_mpy_zip()
@@ -214,47 +177,22 @@ def measure_sizes():
214177
f"strings percentage of mpy: {_cur_version_strings_percentage:.2f}%\n"
215178
)
216179

217-
"""
218-
output_str += "\n---\n\n"
219-
220-
output_str += "Main Branch Version:\n"
221-
#downloaded_filename = download_latest_bundle()
222-
os.chdir(downloaded_filename.replace(".zip", ""))
223-
os.chdir("lib")
224-
single_mpy_file = f"./{module_name}.mpy"
225-
if os.path.exists(single_mpy_file):
226-
# if it's a single mpy file
227-
228-
file_stats = os.stat(single_mpy_file)
229-
output_str += f"mpy file size: {file_stats.st_size} bytes\n"
230-
_cur_version_size = file_stats.st_size
231-
232-
os.system(f"strings {single_mpy_file} > published_strings_output.txt")
233-
string_file_stats = os.stat("published_strings_output.txt")
234-
output_str += f"strings output size: {string_file_stats.st_size} bytes\n"
235-
output_str += f"strings percentage of mpy: {(string_file_stats.st_size / file_stats.st_size) * 100.0:.2f}%\n"
236-
_cur_version_strings_size = string_file_stats.st_size
237-
238-
else: # single mpy file not found
239-
package_name = single_mpy_file.replace(".mpy", "")
240-
os.chdir(package_name)
241-
file_size, strings_size = get_sizes_from_dir("./", verbose=False)
180+
_filesize_diff = _changed_version_size - _cur_version_size
181+
_filesize_dif_percent = (_filesize_diff / _cur_version_size) * 100.0
242182

243-
_changed_version_size = file_size
244-
_changed_version_strings_size = strings_size
245-
output_str += f"total mpy files size: {file_size} bytes\n"
246-
output_str += f"strings output size: {strings_size} bytes\n"
247-
if file_size != 0:
248-
output_str += f"strings percentage of mpy: {(strings_size / file_size) * 100.0:.2f}%\n"
249-
"""
183+
_strings_diff = _changed_version_strings_size - _cur_version_strings_size
184+
_strings_diff_percent = (_strings_diff / _cur_version_strings_size) * 100.0
250185

186+
_strings_percentage_diff = (
187+
_changed_version_strings_percentage - _cur_version_strings_percentage
188+
)
251189
output_str += "\n---\n\n"
252190
output_str += "Summary:\n"
191+
output_str += f"mpy file size difference: {_filesize_diff}bytes | {_filesize_dif_percent:.2f}%\n"
192+
output_str += f"mpy strings size difference: {_strings_diff} bytes | {_strings_diff_percent:.2f}%\n"
253193
output_str += (
254-
f"Mpy File Size Difference: {_changed_version_size - _cur_version_size}\n"
194+
f"mpy strings percentage difference: {_strings_percentage_diff:.2f}%\n"
255195
)
256-
output_str += f"Mpy Strings Size Difference: {_changed_version_strings_size - _cur_version_strings_size}\n"
257-
output_str += f"Mpy Strings Percentage Difference: {_changed_version_strings_percentage - _cur_version_strings_percentage:.2f}%\n"
258196

259197
_is_changed_from_current = False
260198
_is_above_baseline = False
@@ -271,17 +209,14 @@ def measure_sizes():
271209
if _changed_version_strings_percent > PERCENT_STRINGS_FLAG_VALUE:
272210
_is_over_string_percentage = True
273211

274-
_filesize_diff = abs(_changed_version_size - _cur_version_size)
275-
_filesize_dif_percent = (_filesize_diff / _cur_version_size) * 100.0
276212
# print(f"{_filesize_dif_percent} > {PERCENT_DIFF_FLAG_VALUE}")
277-
if _filesize_dif_percent > PERCENT_DIFF_FLAG_VALUE:
213+
if abs(_filesize_dif_percent) > PERCENT_DIFF_FLAG_VALUE:
278214
_is_changed_from_current = True
279215

280216
if _is_above_baseline or _is_changed_from_current or _is_over_string_percentage:
281217
os.chdir(original_working_dir)
282-
f = open("sizes.txt", "w")
283-
f.write(output_str)
284-
f.close()
218+
with open("sizes.txt", "w") as f:
219+
f.write(output_str)
285220

286221
print(output_str)
287222

0 commit comments

Comments
 (0)