|
1 | 1 | import io
|
| 2 | +import os.path |
2 | 3 | import zipfile
|
3 | 4 |
|
4 | 5 | import requests
|
|
8 | 9 | from typing import Any, Optional, List, Dict, Union, Type, TypeVar
|
9 | 10 | import platform
|
10 | 11 | import ctypes
|
11 |
| -from os.path import join, abspath, dirname, isdir |
| 12 | +from os.path import join, abspath, dirname, isdir, basename |
12 | 13 |
|
13 | 14 | import betterproto
|
14 | 15 | from betterproto.lib.google.protobuf import Struct, Value, ListValue
|
@@ -146,20 +147,24 @@ def load_library() -> ctypes.CDLL:
|
146 | 147 | return OKAPI_DLL['library']
|
147 | 148 |
|
148 | 149 |
|
149 |
| -def download_binaries(): |
| 150 | +def download_binaries(force_download=True): |
150 | 151 | """
|
151 | 152 | Download the latest released binaries from github
|
152 | 153 | """
|
| 154 | + extract_dir = abspath(join(dirname(abspath(__file__)), 'okapi')) |
| 155 | + # Remove the binaries for other environments. |
| 156 | + copy_from, copy_to = get_os_arch_binary(extract_dir) |
| 157 | + |
| 158 | + if not force_download and os.path.exists(abspath(join(copy_to, basename(copy_from)))): |
| 159 | + return |
| 160 | + |
153 | 161 | latest_release = requests.get('https://api.github.com/repos/trinsic-id/okapi/releases/latest').json()
|
154 | 162 | latest_assets = requests.get(latest_release['assets_url']).json()
|
155 | 163 | libs_asset = [asset for asset in latest_assets if asset['name'] == 'libs.zip'][0]
|
156 | 164 | # Download zip
|
157 | 165 | zip_download = requests.get(libs_asset['browser_download_url'], stream=True)
|
158 | 166 | z = zipfile.ZipFile(io.BytesIO(zip_download.content))
|
159 |
| - extract_dir = abspath(join(dirname(abspath(__file__)), 'okapi')) |
160 | 167 | z.extractall(extract_dir)
|
161 |
| - # Remove the binaries for other environments. |
162 |
| - copy_from, copy_to = get_os_arch_binary(extract_dir) |
163 | 168 | shutil.copy2(copy_from, copy_to)
|
164 | 169 | cleanup_zip_download(copy_to)
|
165 | 170 |
|
|
0 commit comments