From 2b073585fde9ea63b94bd74aba47fe1975ea37a2 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Tue, 13 Aug 2024 18:20:00 -0700 Subject: [PATCH 1/4] fix: switch to new GritQL release source --- src/openai/cli/_tools/migrate.py | 57 ++++++++++---------------------- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/src/openai/cli/_tools/migrate.py b/src/openai/cli/_tools/migrate.py index 7c10bb7f85..1076bec61e 100644 --- a/src/openai/cli/_tools/migrate.py +++ b/src/openai/cli/_tools/migrate.py @@ -84,8 +84,10 @@ def install() -> Path: """Installs the Grit CLI and returns the location of the binary""" if sys.platform == "win32": raise CLIError("Windows is not supported yet in the migration CLI") + + _debug("Using Grit installer from GitHub") - platform = "macos" if sys.platform == "darwin" else "linux" + platform = "apple-darwin" if sys.platform == "darwin" else "linux" dir_name = _cache_dir() / "openai-python" install_dir = dir_name / ".install" @@ -109,27 +111,14 @@ def install() -> Path: arch = _get_arch() _debug(f"Using architecture {arch}") - file_name = f"marzano-{platform}-{arch}" - meta_url = f"https://api.keygen.sh/v1/accounts/{KEYGEN_ACCOUNT}/artifacts/{file_name}" + file_name = f"marzano-{arch}-{platform}" + download_url = f"https://github.com/getgrit/gritql/releases/latest/download/{file_name}.tar.gz" - sys.stdout.write(f"Retrieving Grit CLI metadata from {meta_url}\n") + sys.stdout.write(f"Downloading Grit CLI from {download_url}\n") with httpx.Client() as client: - response = client.get(meta_url) # pyright: ignore[reportUnknownMemberType] - - data = response.json() - errors = data.get("errors") - if errors: - for error in errors: - sys.stdout.write(f"{error}\n") - - raise CLIError("Could not locate Grit CLI binary - see above errors") - - write_manifest(install_dir, data["data"]["relationships"]["release"]["data"]["id"]) - - link = data["data"]["links"]["redirect"] - _debug(f"Redirect URL {link}") - - download_response = client.get(link) # pyright: ignore[reportUnknownMemberType] + download_response = client.get(download_url, follow_redirects=True) + if download_response.status_code != 200: + raise CLIError(f"Failed to download Grit CLI from {download_url}") with open(temp_file, "wb") as file: for chunk in download_response.iter_bytes(): file.write(chunk) @@ -143,8 +132,7 @@ def install() -> Path: else: archive.extractall(unpacked_dir) - for item in unpacked_dir.iterdir(): - item.rename(target_dir / item.name) + move_files_recursively(unpacked_dir, target_dir) shutil.rmtree(unpacked_dir) os.remove(temp_file) @@ -154,31 +142,22 @@ def install() -> Path: return target_path +def move_files_recursively(source_dir: Path, target_dir: Path): + for item in source_dir.iterdir(): + if item.is_file(): + item.rename(target_dir / item.name) + elif item.is_dir(): + move_files_recursively(item, target_dir) def _get_arch() -> str: architecture = platform.machine().lower() - # Map the architecture names to Node.js equivalents + # Map the architecture names to Grit equivalents arch_map = { "x86_64": "x64", "amd64": "x64", "armv7l": "arm", - "aarch64": "arm64", + "arm64": "aarch64", } return arch_map.get(architecture, architecture) - - -def write_manifest(install_path: Path, release: str) -> None: - manifest = { - "installPath": str(install_path), - "binaries": { - "marzano": { - "name": "marzano", - "release": release, - }, - }, - } - manifest_path = Path(install_path) / "manifests.json" - with open(manifest_path, "w") as f: - json.dump(manifest, f, indent=2) From 19a2f111ada8f116450cb60d75f6de2a59849ae6 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Tue, 13 Aug 2024 18:22:10 -0700 Subject: [PATCH 2/4] fix: adjust for linux too --- src/openai/cli/_tools/migrate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/openai/cli/_tools/migrate.py b/src/openai/cli/_tools/migrate.py index 1076bec61e..0d612c99f8 100644 --- a/src/openai/cli/_tools/migrate.py +++ b/src/openai/cli/_tools/migrate.py @@ -87,7 +87,7 @@ def install() -> Path: _debug("Using Grit installer from GitHub") - platform = "apple-darwin" if sys.platform == "darwin" else "linux" + platform = "apple-darwin" if sys.platform == "darwin" else "unknown-linux-gnu" dir_name = _cache_dir() / "openai-python" install_dir = dir_name / ".install" @@ -154,9 +154,9 @@ def _get_arch() -> str: # Map the architecture names to Grit equivalents arch_map = { - "x86_64": "x64", - "amd64": "x64", - "armv7l": "arm", + "x86_64": "x86_64", + "amd64": "x86_64", + "armv7l": "aarch64", "arm64": "aarch64", } From 2dabdbde21b4232fb29ec26bfc751260a4d041e0 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Tue, 13 Aug 2024 18:24:19 -0700 Subject: [PATCH 3/4] fix: formatting --- src/openai/cli/_tools/migrate.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/openai/cli/_tools/migrate.py b/src/openai/cli/_tools/migrate.py index 0d612c99f8..110d72d646 100644 --- a/src/openai/cli/_tools/migrate.py +++ b/src/openai/cli/_tools/migrate.py @@ -2,7 +2,6 @@ import os import sys -import json import shutil import tarfile import platform @@ -84,7 +83,7 @@ def install() -> Path: """Installs the Grit CLI and returns the location of the binary""" if sys.platform == "win32": raise CLIError("Windows is not supported yet in the migration CLI") - + _debug("Using Grit installer from GitHub") platform = "apple-darwin" if sys.platform == "darwin" else "unknown-linux-gnu" @@ -132,7 +131,7 @@ def install() -> Path: else: archive.extractall(unpacked_dir) - move_files_recursively(unpacked_dir, target_dir) + _move_files_recursively(unpacked_dir, target_dir) shutil.rmtree(unpacked_dir) os.remove(temp_file) @@ -142,12 +141,14 @@ def install() -> Path: return target_path -def move_files_recursively(source_dir: Path, target_dir: Path): + +def _move_files_recursively(source_dir: Path, target_dir: Path): for item in source_dir.iterdir(): if item.is_file(): item.rename(target_dir / item.name) elif item.is_dir(): - move_files_recursively(item, target_dir) + _move_files_recursively(item, target_dir) + def _get_arch() -> str: architecture = platform.machine().lower() From 767f796d4c8d5d05e8bab21eae30154f696b8042 Mon Sep 17 00:00:00 2001 From: Morgante Pell Date: Tue, 13 Aug 2024 19:26:02 -0700 Subject: [PATCH 4/4] fix: linting --- src/openai/cli/_tools/migrate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openai/cli/_tools/migrate.py b/src/openai/cli/_tools/migrate.py index 110d72d646..7a0b0f90f6 100644 --- a/src/openai/cli/_tools/migrate.py +++ b/src/openai/cli/_tools/migrate.py @@ -142,7 +142,7 @@ def install() -> Path: return target_path -def _move_files_recursively(source_dir: Path, target_dir: Path): +def _move_files_recursively(source_dir: Path, target_dir: Path) -> None: for item in source_dir.iterdir(): if item.is_file(): item.rename(target_dir / item.name)