1
1
# SPDX-FileCopyrightText: 2021 foamyguy
2
+ # SPDX-FileCopyrightText: 2019 Nicholas Tollervey, written for Adafruit Industries
2
3
#
3
4
# SPDX-License-Identifier: MIT
4
5
5
- import requests
6
+ """
7
+ Get the list of required libraries based on a file's imports
8
+ """
9
+
6
10
import json
7
11
import os
8
12
import findimports
13
+ import requests
9
14
10
15
BUNDLE_DATA = "latest_bundle_data.json"
11
16
BUNDLE_TAG = "latest_bundle_tag.json"
18
23
19
24
20
25
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
22
28
print (f"get bundle metadata from { url } " )
23
29
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 )
26
32
27
33
28
34
LATEST_BUNDLE_VERSION = ""
29
35
30
36
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
-
45
37
def get_latest_release_from_url (url ):
46
38
"""
47
39
Find the tag name of the latest release by using HTTP HEAD and decoding the redirect.
@@ -65,7 +57,7 @@ def get_latest_tag():
65
57
bundle.
66
58
:return: The most recent tag value for the project.
67
59
"""
68
- global LATEST_BUNDLE_VERSION
60
+ global LATEST_BUNDLE_VERSION # pylint: disable=global-statement
69
61
if LATEST_BUNDLE_VERSION == "" :
70
62
LATEST_BUNDLE_VERSION = get_latest_release_from_url (
71
63
"https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases/latest"
@@ -85,7 +77,7 @@ def ensure_latest_bundle():
85
77
with open (BUNDLE_TAG , encoding = "utf-8" ) as data :
86
78
try :
87
79
old_tag = json .load (data )["tag" ]
88
- except json .decoder .JSONDecodeError as ex :
80
+ except json .decoder .JSONDecodeError as _ :
89
81
# Sometimes (why?) the JSON file becomes corrupt. In which case
90
82
# log it and carry on as if setting up for first time.
91
83
print (f"Could not parse { BUNDLE_TAG :r} " )
@@ -95,7 +87,7 @@ def ensure_latest_bundle():
95
87
get_bundle (tag )
96
88
with open (BUNDLE_TAG , "w" , encoding = "utf-8" ) as data :
97
89
json .dump ({"tag" : tag }, data )
98
- except requests .exceptions .HTTPError as ex :
90
+ except requests .exceptions .HTTPError as _ :
99
91
# See #20 for reason this this
100
92
print (
101
93
(
@@ -115,6 +107,7 @@ def ensure_latest_bundle():
115
107
116
108
117
109
def get_files_for_project (project_name ):
110
+ """Get the set of files for a learn project"""
118
111
found_files = set ()
119
112
project_dir = "{}/{}/" .format (LEARN_GUIDE_REPO , project_name )
120
113
for file in os .listdir (project_dir ):
@@ -130,6 +123,7 @@ def get_files_for_project(project_name):
130
123
131
124
132
125
def get_libs_for_project (project_name ):
126
+ """Get the set of libraries for a learn project"""
133
127
found_libs = set ()
134
128
found_imports = []
135
129
project_dir = "{}{}/" .format (LEARN_GUIDE_REPO , project_name )
@@ -147,20 +141,19 @@ def get_libs_for_project(project_name):
147
141
148
142
149
143
def get_learn_guide_projects ():
144
+ """Get the list of all folders in the learn guide"""
150
145
return os .listdir (LEARN_GUIDE_REPO )
151
146
152
147
153
148
def get_learn_guide_cp_projects ():
149
+ """Get the list of all circuitpython projects, according to some heuristics"""
154
150
cp_projects = []
155
151
156
- def has_py_file (dir ):
157
- dir_files = os .listdir (dir )
152
+ def has_py_file (location ):
153
+ dir_files = os .listdir (location )
158
154
for file in dir_files :
159
155
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
164
157
return False
165
158
166
159
all_projects = get_learn_guide_projects ()
0 commit comments