2121# THE SOFTWARE.
2222
2323from adabot import github_requests as github
24+ from adabot import circuitpython_libraries
2425import os
2526import subprocess
2627import shlex
@@ -46,6 +47,51 @@ def fetch_bundle(bundle, bundle_path):
4647 git .submodule ("update" )
4748 os .chdir (working_directory )
4849
50+ def check_lib_links_md (bundle_path ):
51+ if not "Adafruit_CircuitPython_Bundle" in bundle_path :
52+ return []
53+ submodules_list = sorted (circuitpython_libraries .get_bundle_submodules (),
54+ key = lambda module : module [1 ]["path" ])
55+
56+ lib_count = len (submodules_list )
57+ # used to generate commit message by comparing new libs to current list
58+ try :
59+ with open (os .path .join (bundle_path , "circuitpython_library_list.md" ), 'r' ) as f :
60+ read_lines = f .read ().splitlines ()
61+ except :
62+ read_lines = []
63+ pass
64+
65+ write_drivers = []
66+ write_helpers = []
67+ updates_made = []
68+ for submodule in submodules_list :
69+ url = submodule [1 ]["url" ]
70+ url_name = url [url .rfind ("/" ) + 1 :(url .rfind ("." ) if url .rfind ("." ) > url .rfind ("/" ) else len (url ))]
71+ pypi_name = ""
72+ if circuitpython_libraries .repo_is_on_pypi ({"name" : url_name }):
73+ pypi_name = " ([PyPi](https://pypi.org/project/{}))" .format (url_name .replace ("_" , "-" ).lower ())
74+ title = url_name .replace ("_" , " " )
75+ list_line = "* [{0}]({1}){2}" .format (title , url , pypi_name )
76+ if list_line not in read_lines :
77+ updates_made .append (url_name )
78+ if "drivers" in submodule [1 ]["path" ]:
79+ write_drivers .append (list_line )
80+ elif "helpers" in submodule [1 ]["path" ]:
81+ write_helpers .append (list_line )
82+
83+ with open (os .path .join (bundle_path , "circuitpython_library_list.md" ), 'w' ) as f :
84+ f .write ("# Adafruit CircuitPython Libraries\n " )
85+ f .write ("\n \n " )
86+ f .write ("Here is a listing of current Adafruit CircuitPython Libraries. There are {} libraries available.\n \n " .format (lib_count ))
87+ f .write ("## Drivers:\n " )
88+ for line in sorted (write_drivers ):
89+ f .write (line + "\n " )
90+ f .write ("\n ## Helpers:\n " )
91+ for line in sorted (write_helpers ):
92+ f .write (line + "\n " )
93+
94+ return updates_made
4995
5096class Submodule :
5197 def __init__ (self , directory ):
@@ -97,14 +143,15 @@ def update_bundle(bundle_path):
97143 git .submodule ("foreach" , "git" , "fetch" )
98144 # sh fails to find the subcommand so we use subprocess.
99145 subprocess .run (shlex .split ("git submodule foreach 'git checkout -q `git rev-list --tags --max-count=1`'" ), stdout = subprocess .DEVNULL )
100-
101146 status = StringIO ()
102147 result = git .status ("--short" , _out = status )
103148 updates = []
104149 status = status .getvalue ().strip ()
105150 if status :
106151 for status_line in status .split ("\n " ):
107152 action , directory = status_line .split ()
153+ if directory .endswith ("library_list.md" ):
154+ continue
108155 if action != "M" or not directory .startswith ("libraries" ):
109156 raise RuntimeError ("Unsupported updates" )
110157
@@ -120,6 +167,13 @@ def update_bundle(bundle_path):
120167 summary = "\n " .join (diff_lines [1 :- 1 ])
121168 updates .append ((url [:- 4 ], old_commit , new_commit , summary ))
122169 os .chdir (working_directory )
170+ lib_list_updates = check_lib_links_md (bundle_path )
171+ if lib_list_updates :
172+ updates .append (("https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md" ,
173+ "NA" ,
174+ "NA" ,
175+ " > Added the following libraries: {}" .format (", " .join (lib_list_updates ))))
176+
123177 return updates
124178
125179def commit_updates (bundle_path , update_info ):
0 commit comments