2
2
3
3
import os
4
4
import sys
5
- import json
6
5
import shutil
7
6
import tarfile
8
7
import platform
@@ -85,7 +84,9 @@ def install() -> Path:
85
84
if sys .platform == "win32" :
86
85
raise CLIError ("Windows is not supported yet in the migration CLI" )
87
86
88
- platform = "macos" if sys .platform == "darwin" else "linux"
87
+ _debug ("Using Grit installer from GitHub" )
88
+
89
+ platform = "apple-darwin" if sys .platform == "darwin" else "unknown-linux-gnu"
89
90
90
91
dir_name = _cache_dir () / "openai-python"
91
92
install_dir = dir_name / ".install"
@@ -109,27 +110,14 @@ def install() -> Path:
109
110
arch = _get_arch ()
110
111
_debug (f"Using architecture { arch } " )
111
112
112
- file_name = f"marzano-{ platform } -{ arch } "
113
- meta_url = f"https://api.keygen.sh/v1/accounts/ { KEYGEN_ACCOUNT } /artifacts/ { file_name } "
113
+ file_name = f"marzano-{ arch } -{ platform } "
114
+ download_url = f"https://github.com/getgrit/gritql/releases/latest/download/ { file_name } .tar.gz "
114
115
115
- sys .stdout .write (f"Retrieving Grit CLI metadata from { meta_url } \n " )
116
+ sys .stdout .write (f"Downloading Grit CLI from { download_url } \n " )
116
117
with httpx .Client () as client :
117
- response = client .get (meta_url ) # pyright: ignore[reportUnknownMemberType]
118
-
119
- data = response .json ()
120
- errors = data .get ("errors" )
121
- if errors :
122
- for error in errors :
123
- sys .stdout .write (f"{ error } \n " )
124
-
125
- raise CLIError ("Could not locate Grit CLI binary - see above errors" )
126
-
127
- write_manifest (install_dir , data ["data" ]["relationships" ]["release" ]["data" ]["id" ])
128
-
129
- link = data ["data" ]["links" ]["redirect" ]
130
- _debug (f"Redirect URL { link } " )
131
-
132
- download_response = client .get (link ) # pyright: ignore[reportUnknownMemberType]
118
+ download_response = client .get (download_url , follow_redirects = True )
119
+ if download_response .status_code != 200 :
120
+ raise CLIError (f"Failed to download Grit CLI from { download_url } " )
133
121
with open (temp_file , "wb" ) as file :
134
122
for chunk in download_response .iter_bytes ():
135
123
file .write (chunk )
@@ -143,8 +131,7 @@ def install() -> Path:
143
131
else :
144
132
archive .extractall (unpacked_dir )
145
133
146
- for item in unpacked_dir .iterdir ():
147
- item .rename (target_dir / item .name )
134
+ _move_files_recursively (unpacked_dir , target_dir )
148
135
149
136
shutil .rmtree (unpacked_dir )
150
137
os .remove (temp_file )
@@ -155,30 +142,23 @@ def install() -> Path:
155
142
return target_path
156
143
157
144
145
+ def _move_files_recursively (source_dir : Path , target_dir : Path ) -> None :
146
+ for item in source_dir .iterdir ():
147
+ if item .is_file ():
148
+ item .rename (target_dir / item .name )
149
+ elif item .is_dir ():
150
+ _move_files_recursively (item , target_dir )
151
+
152
+
158
153
def _get_arch () -> str :
159
154
architecture = platform .machine ().lower ()
160
155
161
- # Map the architecture names to Node.js equivalents
156
+ # Map the architecture names to Grit equivalents
162
157
arch_map = {
163
- "x86_64" : "x64 " ,
164
- "amd64" : "x64 " ,
165
- "armv7l" : "arm " ,
166
- "aarch64 " : "arm64 " ,
158
+ "x86_64" : "x86_64 " ,
159
+ "amd64" : "x86_64 " ,
160
+ "armv7l" : "aarch64 " ,
161
+ "arm64 " : "aarch64 " ,
167
162
}
168
163
169
164
return arch_map .get (architecture , architecture )
170
-
171
-
172
- def write_manifest (install_path : Path , release : str ) -> None :
173
- manifest = {
174
- "installPath" : str (install_path ),
175
- "binaries" : {
176
- "marzano" : {
177
- "name" : "marzano" ,
178
- "release" : release ,
179
- },
180
- },
181
- }
182
- manifest_path = Path (install_path ) / "manifests.json"
183
- with open (manifest_path , "w" ) as f :
184
- json .dump (manifest , f , indent = 2 )
0 commit comments