16
16
import requests
17
17
import semver
18
18
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
19
25
20
26
def get_git_command (command ):
21
27
"""Execute and return the result of a git command without error."""
@@ -75,41 +81,47 @@ def date_to_version(tag):
75
81
SET_VERSION_PATTERN = "\n __version__ = '{}'\n "
76
82
THIS_REPOSITORY = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
77
83
78
- PLATFORMS = ["mpy6 " , "mpy7 " , "mpy8 " ]
84
+ PLATFORMS = ["mpy7 " , "mpy8 " , "mpy9 " ]
79
85
PLATFORM_NAMES = {
80
86
"py" : "py" ,
81
- "mpy6" : "6.x-mpy" ,
82
87
"mpy7" : "7.x-mpy" ,
83
88
"mpy8" : "8.x-mpy" ,
89
+ "mpy9" : "9.x-mpy" ,
84
90
}
85
91
86
92
# https://adafruit-circuit-python.s3.amazonaws.com/index.html?prefix=bin/mpy-cross/
87
93
# TODO: identify current OS and pick one
88
94
MPYCROSS_URL = "https://adafruit-circuit-python.s3.amazonaws.com/bin/mpy-cross/"
89
95
MPYCROSSES = {
90
96
"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" ] ,
94
100
},
95
101
"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" ] ,
99
105
},
100
106
"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"] ,
104
110
},
105
111
"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" ] ,
109
115
},
110
116
}
111
117
MPYCROSS = MPYCROSSES [sys .platform ]
112
118
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
+
113
125
114
126
def file_version_tag (path ):
115
127
"""
@@ -180,9 +192,9 @@ def init_directories():
180
192
for platform in ["py" ] + PLATFORMS :
181
193
bun_dir = BUNDLE_DIR .format (platform = PLATFORM_NAMES [platform ])
182
194
zip_file = BUNDLE_ZIP .format (platform = PLATFORM_NAMES [platform ])
183
- if os .path .isdir (bun_dir ):
195
+ while os .path .isdir (bun_dir ):
184
196
shutil .rmtree (bun_dir )
185
- if os .path .isfile (zip_file ):
197
+ while os .path .isfile (zip_file ):
186
198
os .unlink (zip_file )
187
199
188
200
@@ -278,27 +290,34 @@ def make_the_mpy_bundles():
278
290
279
291
# download the mpycrosses
280
292
for cross in MPYCROSS :
281
- cross_file = os . path . join ( BUILD_DEPS , MPYCROSS [ cross ] )
293
+ cross_file = MPYCROSS_FILE ( cross )
282
294
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 )
284
298
response = requests .get (url )
285
299
with open (cross_file , "wb" ) as cross_fp :
286
300
cross_fp .write (response .content )
287
301
fstats = os .stat (cross_file )
288
302
os .chmod (cross_file , fstats .st_mode | stat .S_IEXEC )
303
+ else :
304
+ debug ("Exists: " + os .path .basename (cross_file ))
289
305
290
306
# duplicate the py dir to mpy dirs
291
307
pwd = os .getcwd ()
292
308
for platform in PLATFORMS :
293
- cross = os . path . join ( BUILD_DEPS , MPYCROSS [ platform ] )
309
+ cross = MPYCROSS_FILE ( platform )
294
310
cross = os .path .abspath (cross )
295
311
bun_dir = BUNDLE_DIR .format (platform = PLATFORM_NAMES [platform ])
296
312
lib_dir = BUNDLE_LIB_DIR .format (platform = PLATFORM_NAMES [platform ])
313
+ debug (f"{ platform } : Duplicating" )
314
+ debug (f" { lib_dir } " )
297
315
shutil .copytree (fmt (BUNDLE_DIR ), bun_dir )
298
316
# run mpy-cross in each of those
299
317
os .chdir (lib_dir )
300
318
for lib_file in glob .glob (os .path .join ("*.py" )):
301
319
mpy_file = lib_file .replace (".py" , ".mpy" )
320
+ debug (f" • MPY file: { mpy_file } " )
302
321
subprocess .call ([cross , lib_file , "-o" , mpy_file ])
303
322
os .unlink (lib_file )
304
323
os .chdir (pwd )
@@ -312,6 +331,8 @@ def do_the_zips():
312
331
bun_dir = BUNDLE_DIR .format (platform = PLATFORM_NAMES [platform ])
313
332
zip_file = BUNDLE_ZIP .format (platform = PLATFORM_NAMES [platform ])
314
333
all_files = list_all_files (bun_dir )
334
+ debug ("Making zip" )
335
+ debug (f" { zip_file } " )
315
336
with zipfile .ZipFile (zip_file , "w" ) as bundle :
316
337
# metadata (bundler version)
317
338
# build_metadata = {"build-tools-version": build_tools_version}
0 commit comments