77It is distributed under the MIT License, provided this attribution is retained.
88"""
99
10+ import argparse
1011import os
12+ import requests
1113import sys
12- import argparse
1314import shutil
1415
1516
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+
1647def main (
1748 gh_components_dir : str ,
1849 build_dir : str ,
1950 manifest_path : str ,
2051 logo_path : str ,
2152 readme_path : str ,
2253 license_path : str ,
54+ version : str ,
2355) -> bool :
2456 current_file_path = os .path .abspath (__file__ )
25- current_directory = os .path .dirname (current_file_path )
2657 build_dir = os .path .abspath (build_dir )
2758
2859 #####################################################################
@@ -41,7 +72,8 @@ def main(
4172 print (f"Failed to delete { file_path } : { e } " )
4273 return False
4374
44- shutil .copy (manifest_path , build_dir )
75+ manifest_target = shutil .copy (manifest_path , build_dir )
76+ _set_version_in_manifest (manifest_target , version )
4577 shutil .copy (logo_path , build_dir )
4678 path_miscdir : str = os .path .join (build_dir , "misc" )
4779 os .makedirs (path_miscdir , exist_ok = False )
@@ -58,11 +90,16 @@ def main(
5890 #####################################################################
5991 # Yak exe
6092 #####################################################################
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 } " )
6598 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+
66103 path_current : str = os .getcwd ()
67104 os .chdir (build_dir )
68105 os .system ("cd" )
@@ -124,6 +161,12 @@ def main(
124161 default = "./README.md" ,
125162 help = "The path to the readme file." ,
126163 )
164+ parser .add_argument (
165+ "--version" ,
166+ type = str ,
167+ required = True ,
168+ help = "The semver version string of the package." ,
169+ )
127170
128171 args = parser .parse_args ()
129172 parse_errors = []
@@ -147,6 +190,8 @@ def main(
147190 is_gh_components_dir_correct = False
148191
149192 is_build_dir_correct = True
193+
194+ # TODO: is this the same as above?
150195 if os .path .isdir (args .build_dir ):
151196 for f in os .listdir (args .build_dir ):
152197 file_path = os .path .join (args .build_dir , f )
@@ -216,6 +261,7 @@ def main(
216261 logo_path = args .logo_path ,
217262 readme_path = args .readme_path ,
218263 license_path = args .license_path ,
264+ version = args .version ,
219265 )
220266 if res :
221267 print ("[x] Yakerize task completed." )
0 commit comments