1616import requests
1717import semver
1818
19+ if sys .argv and sys .argv [- 1 ].upper () == "DEBUG" :
20+ def debug (text ):
21+ print (text )
22+ else :
23+ def debug (text ):
24+ pass
1925
2026def get_git_command (command ):
2127 """Execute and return the result of a git command without error."""
@@ -75,41 +81,47 @@ def date_to_version(tag):
7581SET_VERSION_PATTERN = "\n __version__ = '{}'\n "
7682THIS_REPOSITORY = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
7783
78- PLATFORMS = ["mpy6 " , "mpy7 " , "mpy8 " ]
84+ PLATFORMS = ["mpy7 " , "mpy8 " , "mpy9 " ]
7985PLATFORM_NAMES = {
8086 "py" : "py" ,
81- "mpy6" : "6.x-mpy" ,
8287 "mpy7" : "7.x-mpy" ,
8388 "mpy8" : "8.x-mpy" ,
89+ "mpy9" : "9.x-mpy" ,
8490}
8591
8692# https://adafruit-circuit-python.s3.amazonaws.com/index.html?prefix=bin/mpy-cross/
8793# TODO: identify current OS and pick one
8894MPYCROSS_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bin/mpy-cross/"
8995MPYCROSSES = {
9096 "darwin" : {
91- "mpy6 " : " mpy-cross-macos-catalina-6.3.0" ,
92- "mpy7 " : " mpy-cross-macos-universal-7.3.0" ,
93- "mpy8 " : " mpy-cross-macos-11-8 .0.0-beta.0-x64" ,
97+ "mpy7 " : [ "macos-11" , " mpy-cross-macos-11-8.0.2-universal" ] ,
98+ "mpy8 " : [ "macos-11" , " mpy-cross-macos-11-8.0.2-universal" ] ,
99+ "mpy9 " : [ "macos-11" , " mpy-cross-macos-11-9 .0.0-alpha.2-universal" ] ,
94100 },
95101 "linux" : {
96- "mpy6 " : " mpy-cross.static-amd64-linux-6 .3.0" ,
97- "mpy7 " : " mpy-cross.static-amd64-linux-7.3.0" ,
98- "mpy8 " : " mpy-cross.static-amd64- linux-8 .0.0-beta.0" ,
102+ "mpy7 " : [ "linux-amd64" , " mpy-cross.static-amd64-linux-7 .3.3" ] ,
103+ "mpy8 " : [ "linux-amd64" , " mpy-cross.static-amd64-linux-8.0.2" ] ,
104+ "mpy9 " : [ "linux-amd64" , " mpy-cross- linux-amd64-9 .0.0-alpha.2.static" ] ,
99105 },
100106 "win32" : {
101- "mpy6 " : " mpy-cross.static-x64-windows-6 .3.0 .exe" ,
102- "mpy7 " : " mpy-cross.static-x64- windows-7.3.0. exe" ,
103- "mpy8 " : " mpy-cross.static-x64- windows-8 .0.0-beta.0. exe" ,
107+ "mpy7 " : [ "windows" , " mpy-cross.static-x64-windows-7 .3.3 .exe"] ,
108+ "mpy8 " : [ "windows" , " mpy-cross- windows-8.1.0-beta.0.static. exe"] ,
109+ "mpy9 " : [ "windows" , " mpy-cross- windows-9 .0.0-alpha.2.static. exe"] ,
104110 },
105111 "raspbian" : {
106- "mpy6 " : " mpy-cross.static-raspbian-6 .3.0" ,
107- "mpy7 " : " mpy-cross.static-raspbian-7.3.0" ,
108- "mpy8 " : " mpy-cross.static- raspbian-8 .0.0-beta.0" ,
112+ "mpy7 " : [ "linux-raspbian" , " mpy-cross.static-raspbian-7 .3.0"] ,
113+ "mpy8 " : [ "linux-raspbian" , " mpy-cross.static-raspbian-8.0.2" ] ,
114+ "mpy9 " : [ "linux-raspbian" , " mpy-cross-linux- raspbian-9 .0.0-alpha.2.static-raspbian" ] ,
109115 },
110116}
111117MPYCROSS = MPYCROSSES [sys .platform ]
112118
119+ def MPYCROSS_LINK (version ):
120+ return MPYCROSS_URL + "/" .join (MPYCROSS [version ])
121+
122+ def MPYCROSS_FILE (version ):
123+ return os .path .join (BUILD_DEPS , MPYCROSS [version ][- 1 ])
124+
113125
114126def file_version_tag (path ):
115127 """
@@ -180,9 +192,9 @@ def init_directories():
180192 for platform in ["py" ] + PLATFORMS :
181193 bun_dir = BUNDLE_DIR .format (platform = PLATFORM_NAMES [platform ])
182194 zip_file = BUNDLE_ZIP .format (platform = PLATFORM_NAMES [platform ])
183- if os .path .isdir (bun_dir ):
195+ while os .path .isdir (bun_dir ):
184196 shutil .rmtree (bun_dir )
185- if os .path .isfile (zip_file ):
197+ while os .path .isfile (zip_file ):
186198 os .unlink (zip_file )
187199
188200
@@ -278,27 +290,34 @@ def make_the_mpy_bundles():
278290
279291 # download the mpycrosses
280292 for cross in MPYCROSS :
281- cross_file = os . path . join ( BUILD_DEPS , MPYCROSS [ cross ] )
293+ cross_file = MPYCROSS_FILE ( cross )
282294 if not os .path .isfile (cross_file ):
283- url = MPYCROSS_URL + MPYCROSS [cross ]
295+ debug ("Dowloading" )
296+ debug (cross_file )
297+ url = MPYCROSS_LINK (cross )
284298 response = requests .get (url )
285299 with open (cross_file , "wb" ) as cross_fp :
286300 cross_fp .write (response .content )
287301 fstats = os .stat (cross_file )
288302 os .chmod (cross_file , fstats .st_mode | stat .S_IEXEC )
303+ else :
304+ debug ("Exists: " + os .path .basename (cross_file ))
289305
290306 # duplicate the py dir to mpy dirs
291307 pwd = os .getcwd ()
292308 for platform in PLATFORMS :
293- cross = os . path . join ( BUILD_DEPS , MPYCROSS [ platform ] )
309+ cross = MPYCROSS_FILE ( platform )
294310 cross = os .path .abspath (cross )
295311 bun_dir = BUNDLE_DIR .format (platform = PLATFORM_NAMES [platform ])
296312 lib_dir = BUNDLE_LIB_DIR .format (platform = PLATFORM_NAMES [platform ])
313+ debug (f"{ platform } : Duplicating" )
314+ debug (f" { lib_dir } " )
297315 shutil .copytree (fmt (BUNDLE_DIR ), bun_dir )
298316 # run mpy-cross in each of those
299317 os .chdir (lib_dir )
300318 for lib_file in glob .glob (os .path .join ("*.py" )):
301319 mpy_file = lib_file .replace (".py" , ".mpy" )
320+ debug (f" • MPY file: { mpy_file } " )
302321 subprocess .call ([cross , lib_file , "-o" , mpy_file ])
303322 os .unlink (lib_file )
304323 os .chdir (pwd )
@@ -312,6 +331,8 @@ def do_the_zips():
312331 bun_dir = BUNDLE_DIR .format (platform = PLATFORM_NAMES [platform ])
313332 zip_file = BUNDLE_ZIP .format (platform = PLATFORM_NAMES [platform ])
314333 all_files = list_all_files (bun_dir )
334+ debug ("Making zip" )
335+ debug (f" { zip_file } " )
315336 with zipfile .ZipFile (zip_file , "w" ) as bundle :
316337 # metadata (bundler version)
317338 # build_metadata = {"build-tools-version": build_tools_version}
0 commit comments