Skip to content

Commit

Permalink
Refactor into _extract_tarballname helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr authored Nov 22, 2024
1 parent 3e3ffe4 commit 4e1a936
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pyodide_build/buildpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ def _make_whlfile(
)


def _extract_tarballname(url: str, headers: dict) -> str:
tarballname = url.split("/")[-1]

if "Content-Disposition" in headers:
msg = Message()
msg["Content-Disposition"] = headers["Content-Disposition"]

filename = msg.get_filename()
if filename is not None:
tarballname = filename

return tarballname


class RecipeBuilder:
"""
A class to build a Pyodide meta.yaml recipe.
Expand Down Expand Up @@ -323,14 +337,7 @@ def _download_and_extract(self) -> None:

self.build_dir.mkdir(parents=True, exist_ok=True)

tarballname = url.split("/")[-1]
if "Content-Disposition" in response.headers:
msg = Message()
msg["Content-Disposition"] = response.headers["Content-Disposition"]
filename = msg.get_filename()
if filename is not None:
tarballname = filename

tarballname = _extract_tarballname(url, response.headers)
tarballpath = self.build_dir / tarballname
tarballpath.write_bytes(response.content)

Expand Down

0 comments on commit 4e1a936

Please sign in to comment.