21
21
# THE SOFTWARE.
22
22
23
23
from adabot import github_requests as github
24
+ from adabot import circuitpython_libraries
24
25
import os
25
26
import subprocess
26
27
import shlex
@@ -46,6 +47,51 @@ def fetch_bundle(bundle, bundle_path):
46
47
git .submodule ("update" )
47
48
os .chdir (working_directory )
48
49
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
49
95
50
96
class Submodule :
51
97
def __init__ (self , directory ):
@@ -97,14 +143,15 @@ def update_bundle(bundle_path):
97
143
git .submodule ("foreach" , "git" , "fetch" )
98
144
# sh fails to find the subcommand so we use subprocess.
99
145
subprocess .run (shlex .split ("git submodule foreach 'git checkout -q `git rev-list --tags --max-count=1`'" ), stdout = subprocess .DEVNULL )
100
-
101
146
status = StringIO ()
102
147
result = git .status ("--short" , _out = status )
103
148
updates = []
104
149
status = status .getvalue ().strip ()
105
150
if status :
106
151
for status_line in status .split ("\n " ):
107
152
action , directory = status_line .split ()
153
+ if directory .endswith ("library_list.md" ):
154
+ continue
108
155
if action != "M" or not directory .startswith ("libraries" ):
109
156
raise RuntimeError ("Unsupported updates" )
110
157
@@ -120,6 +167,13 @@ def update_bundle(bundle_path):
120
167
summary = "\n " .join (diff_lines [1 :- 1 ])
121
168
updates .append ((url [:- 4 ], old_commit , new_commit , summary ))
122
169
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
+
123
177
return updates
124
178
125
179
def commit_updates (bundle_path , update_info ):
0 commit comments