Skip to content

Commit

Permalink
fix: handle archives from github that are not named like their python…
Browse files Browse the repository at this point in the history
… packages

chaski was built with the incorrect assumption that python packages always match the name of their github repos. This was true for the packages we were supporting, but with the addition of rpds-py, which is named rpds on github, this became a problem.
  • Loading branch information
bruno-fs authored and infinitewarp committed Dec 17, 2024
1 parent 3b2d911 commit 014f93b
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import tarfile
from pathlib import Path
from tempfile import TemporaryDirectory

import requests
import typer
Expand Down Expand Up @@ -333,8 +334,27 @@ def _get_dependency(dependency_name: str, version: str) -> Path:
if not dl_resp.ok:
console.print(f"Failed to download {url}", style="red")
raise typer.Abort()
with tarfile.open(fileobj=io.BytesIO(dl_resp.content)) as tarball:
tarball.extractall(DEPENDENCIES_FOLDER)
with (
tarfile.open(fileobj=io.BytesIO(dl_resp.content)) as tarball,
TemporaryDirectory() as tmp_dir,
):
tarball.extractall(tmp_dir)
extracted_files = list(Path(tmp_dir).iterdir())
if len(extracted_files) != 1:
console.print(
f"github tarball for {dependency_name}-{dependency_name} contains more "
"than a single 'toplevel' file. Please update chaski to handle this.",
style="red",
)
typer.Abort()
if not extracted_files[0].is_dir():
console.print(
f"github tarball for {dependency_name}-{dependency_name} doesn't "
"contain a directory. Please update chaski to handle this.",
style="red",
)
typer.Abort()
shutil.move(extracted_files[0], archive)
return archive


Expand Down

0 comments on commit 014f93b

Please sign in to comment.