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+
610import json
711import os
812import findimports
13+ import requests
914
1015BUNDLE_DATA = "latest_bundle_data.json"
1116BUNDLE_TAG = "latest_bundle_tag.json"
1823
1924
2025def 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
2834LATEST_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-
4537def 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
117109def 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
132125def 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
149143def get_learn_guide_projects ():
144+ """Get the list of all folders in the learn guide"""
150145 return os .listdir (LEARN_GUIDE_REPO )
151146
152147
153148def 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 ()
0 commit comments