|
| 1 | +"""This package contains the utility functions to fetch the wrappers\ |
| 2 | + from the wasm-test-harness repo.""" |
| 3 | +import io |
| 4 | +import os |
| 5 | +import zipfile |
| 6 | +from urllib.error import HTTPError |
| 7 | +from urllib.request import urlopen |
| 8 | + |
| 9 | + |
| 10 | +def get_path_to_test_wrappers() -> str: |
| 11 | + """Get the path to the test wrappers.""" |
| 12 | + return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "wrappers")) |
| 13 | + |
| 14 | + |
| 15 | +def fetch_file(url: str) -> bytes: |
| 16 | + """Fetch a file using HTTP.""" |
| 17 | + with urlopen(url) as response: |
| 18 | + if response.status != 200: |
| 19 | + raise HTTPError( |
| 20 | + url, response.status, "Failed to fetch file", response.headers, None |
| 21 | + ) |
| 22 | + return response.read() |
| 23 | + |
| 24 | + |
| 25 | +def unzip_file(file_buffer: bytes, destination: str) -> None: |
| 26 | + """Unzip a file to a destination.""" |
| 27 | + with zipfile.ZipFile(io.BytesIO(file_buffer), "r") as zip_ref: |
| 28 | + zip_ref.extractall(destination) |
| 29 | + |
| 30 | + |
| 31 | +def fetch_wrappers() -> None: |
| 32 | + """Fetch the wrappers from the wasm-test-harness repo.""" |
| 33 | + tag = "0.1.0" |
| 34 | + repo_name = "wasm-test-harness" |
| 35 | + url = f"https://github.com/polywrap/{repo_name}/releases/download/{tag}/wrappers" |
| 36 | + |
| 37 | + buffer = fetch_file(url) |
| 38 | + zip_built_folder = get_path_to_test_wrappers() |
| 39 | + unzip_file(buffer, zip_built_folder) |
0 commit comments