7
7
It is distributed under the MIT License, provided this attribution is retained.
8
8
"""
9
9
10
+ import argparse
10
11
import os
12
+ import requests
11
13
import sys
12
- import argparse
13
14
import shutil
14
15
15
16
17
+ YAK_URL = r"https://files.mcneel.com/yak/tools/latest/yak.exe"
18
+ FILENAME = "yak.exe"
19
+
20
+
21
+ def _download_yak_executable (target_dir : str ):
22
+ response = requests .get (YAK_URL )
23
+ if response .status_code != 200 :
24
+ raise ValueError (
25
+ f"Failed to download the yak.exe from url:{ YAK_URL } with error : { response .status_code } "
26
+ )
27
+
28
+ with open (os .path .join (target_dir , FILENAME ), "wb" ) as f :
29
+ f .write (response .content )
30
+
31
+
32
+ def _set_version_in_manifest (manifest_path : str , version : str ):
33
+ with open (manifest_path , "r" ) as f :
34
+ lines = f .readlines ()
35
+
36
+ new_lines = []
37
+ for line in lines :
38
+ if "{{ version }}" in line :
39
+ new_lines .append (line .replace ("{{ version }}" , version ))
40
+ else :
41
+ new_lines .append (line )
42
+
43
+ with open (manifest_path , "w" ) as f :
44
+ f .writelines (new_lines )
45
+
46
+
16
47
def main (
17
48
gh_components_dir : str ,
18
49
build_dir : str ,
19
50
manifest_path : str ,
20
51
logo_path : str ,
21
52
readme_path : str ,
22
53
license_path : str ,
54
+ version : str ,
23
55
) -> bool :
24
56
current_file_path = os .path .abspath (__file__ )
25
- current_directory = os .path .dirname (current_file_path )
26
57
build_dir = os .path .abspath (build_dir )
27
58
28
59
#####################################################################
@@ -41,7 +72,8 @@ def main(
41
72
print (f"Failed to delete { file_path } : { e } " )
42
73
return False
43
74
44
- shutil .copy (manifest_path , build_dir )
75
+ manifest_target = shutil .copy (manifest_path , build_dir )
76
+ _set_version_in_manifest (manifest_target , version )
45
77
shutil .copy (logo_path , build_dir )
46
78
path_miscdir : str = os .path .join (build_dir , "misc" )
47
79
os .makedirs (path_miscdir , exist_ok = False )
@@ -58,11 +90,16 @@ def main(
58
90
#####################################################################
59
91
# Yak exe
60
92
#####################################################################
61
- yak_exe_path : str = os .path .join (current_directory , "yaker" , "exec" , "Yak.exe" )
62
- yak_exe_path = os .path .abspath (yak_exe_path )
63
- if not os .path .isfile (yak_exe_path ):
64
- print (f"Yak.exe not found at { yak_exe_path } ." )
93
+
94
+ try :
95
+ _download_yak_executable (build_dir )
96
+ except ValueError as e :
97
+ print (f"Failed to download yak.exe: { e } " )
65
98
return False
99
+
100
+ yak_exe_path : str = os .path .join (build_dir , "yak.exe" )
101
+ yak_exe_path = os .path .abspath (yak_exe_path )
102
+
66
103
path_current : str = os .getcwd ()
67
104
os .chdir (build_dir )
68
105
os .system ("cd" )
@@ -124,6 +161,12 @@ def main(
124
161
default = "./README.md" ,
125
162
help = "The path to the readme file." ,
126
163
)
164
+ parser .add_argument (
165
+ "--version" ,
166
+ type = str ,
167
+ required = True ,
168
+ help = "The semver version string of the package." ,
169
+ )
127
170
128
171
args = parser .parse_args ()
129
172
parse_errors = []
@@ -147,6 +190,8 @@ def main(
147
190
is_gh_components_dir_correct = False
148
191
149
192
is_build_dir_correct = True
193
+
194
+ # TODO: is this the same as above?
150
195
if os .path .isdir (args .build_dir ):
151
196
for f in os .listdir (args .build_dir ):
152
197
file_path = os .path .join (args .build_dir , f )
@@ -216,6 +261,7 @@ def main(
216
261
logo_path = args .logo_path ,
217
262
readme_path = args .readme_path ,
218
263
license_path = args .license_path ,
264
+ version = args .version ,
219
265
)
220
266
if res :
221
267
print ("[x] Yakerize task completed." )
0 commit comments