Skip to content

Commit 85e8935

Browse files
authored
fix(cli/migrate): change grit binaries download source (#1649)
1 parent 40f4cdb commit 85e8935

File tree

1 file changed

+23
-43
lines changed

1 file changed

+23
-43
lines changed

src/openai/cli/_tools/migrate.py

+23-43
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import sys
5-
import json
65
import shutil
76
import tarfile
87
import platform
@@ -85,7 +84,9 @@ def install() -> Path:
8584
if sys.platform == "win32":
8685
raise CLIError("Windows is not supported yet in the migration CLI")
8786

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"
8990

9091
dir_name = _cache_dir() / "openai-python"
9192
install_dir = dir_name / ".install"
@@ -109,27 +110,14 @@ def install() -> Path:
109110
arch = _get_arch()
110111
_debug(f"Using architecture {arch}")
111112

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"
114115

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")
116117
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}")
133121
with open(temp_file, "wb") as file:
134122
for chunk in download_response.iter_bytes():
135123
file.write(chunk)
@@ -143,8 +131,7 @@ def install() -> Path:
143131
else:
144132
archive.extractall(unpacked_dir)
145133

146-
for item in unpacked_dir.iterdir():
147-
item.rename(target_dir / item.name)
134+
_move_files_recursively(unpacked_dir, target_dir)
148135

149136
shutil.rmtree(unpacked_dir)
150137
os.remove(temp_file)
@@ -155,30 +142,23 @@ def install() -> Path:
155142
return target_path
156143

157144

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+
158153
def _get_arch() -> str:
159154
architecture = platform.machine().lower()
160155

161-
# Map the architecture names to Node.js equivalents
156+
# Map the architecture names to Grit equivalents
162157
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",
167162
}
168163

169164
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

Comments
 (0)