Skip to content

Commit a7cb561

Browse files
method to download binaries to appropriate location
1 parent 01d521a commit a7cb561

7 files changed

Lines changed: 117 additions & 68 deletions

File tree

.github/workflows/release-python.yml

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ name: Release Python SDK
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: 'Package version - PEP440 compliant [N!]N(.N)*[{a|b|rc}N][.postN][.devN]'
8-
required: true
9-
default: ' '
10-
release:
11-
types: [published]
12-
push:
13-
branches:
14-
- main
5+
# release:
6+
# types: [published]
7+
workflow_run:
8+
workflows: ["Release Platform Libraries"]
9+
branches: [main]
10+
types:
11+
- completed
1512

1613
jobs:
1714
release_pypi:
@@ -32,24 +29,7 @@ jobs:
3229
- name: Build, Test, Pack
3330
run: ./devops/BuildPython.ps1 -GitTag "${{ github.ref }}" -PackageVersion "${{ github.event.inputs.version }}"
3431
shell: pwsh
35-
- name: Push packages to release
36-
if: |
37-
(github.event_name == 'release' &&
38-
github.event.action == 'published')
39-
uses: svenstaro/upload-release-action@v2
40-
with:
41-
repo_token: ${{ secrets.GITHUB_TOKEN }}
42-
file: ./python/dist/*
43-
file_glob: true
44-
asset_name: "python"
45-
tag: ${{ github.ref }}
46-
overwrite: true
47-
body: "Python SDK package"
4832
- name: Publish distribution 📦 to PyPI
49-
if: |
50-
(github.event_name == 'release' &&
51-
github.event.action == 'published') ||
52-
github.event.inputs.version != ''
5333
uses: pypa/gh-action-pypi-publish@master
5434
with:
5535
user: __token__

devops/BuildPython.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Install-Requirements {
2626
python -m pip install -r requirements.txt
2727
python -m pip install pytest pytest-cov build
2828

29-
python ./okapi/generate_proto_files.py
29+
python ./devops/generate_proto_files.py
3030
}
3131
function Run-Tests {
3232
python -m pytest --cache-clear ./tests --junitxml=$TestOutput --cov=.

devops/build_sdks.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Build the various language SDK packages for release
3+
"""
4+
import argparse
5+
import os
6+
7+
import requests
8+
9+
10+
def parse_version_tag():
11+
raise NotImplementedError
12+
13+
14+
def build_golang():
15+
raise NotImplementedError
16+
17+
18+
def build_python():
19+
# TODO - Update version in setup.cfg
20+
# TODO - Copy in the binaries
21+
raise NotImplementedError
22+
23+
24+
25+
26+
27+
def get_github_version(github_token: str = None) -> str:
28+
github_token = github_token
29+
github_release_request = requests.get('https://api.github.com/repos/trinsic-id/okapi/releases/latest',
30+
headers={'Autorization': github_token})
31+
github_json = github_release_request.json()
32+
version = github_json['tag_name'].lstrip('v')
33+
return version
34+
35+
36+
def parse_arguments():
37+
parser = argparse.ArgumentParser(description='Process SDK building')
38+
parser.add_argument('--git-tag', help='Git tag')
39+
parser.add_argument('--package-version', help='Manual override package version')
40+
parser.add_argument('--github-token', help='github token')
41+
# TODO - allow specifying what to build?
42+
43+
44+
def main():
45+
# TODO - Get command line arguments
46+
# Update version information
47+
# Build and upload
48+
pass
49+
50+
51+
if __name__ == "__main__":
52+
main()

python/okapi/generate_proto_files.py

Lines changed: 0 additions & 38 deletions
This file was deleted.

python/okapi/okapi_utils.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
import io
2+
import zipfile
3+
4+
import requests
5+
import shutil
16
import threading
7+
from os import listdir
28
from typing import Any, Optional, List, Dict, Union, Type, TypeVar
39
import platform
410
import ctypes
5-
from os.path import join, abspath, dirname
11+
from os.path import join, abspath, dirname, isdir
612

713
import betterproto
814
from betterproto.lib.google.protobuf import Struct, Value, ListValue
@@ -140,6 +146,51 @@ def load_library() -> ctypes.CDLL:
140146
return OKAPI_DLL['library']
141147

142148

149+
def download_binaries():
150+
"""
151+
Download the latest released binaries from github
152+
"""
153+
latest_release = requests.get('https://api.github.com/repos/trinsic-id/okapi/releases/latest').json()
154+
latest_assets = requests.get(latest_release['assets_url']).json()
155+
libs_asset = [asset for asset in latest_assets if asset['name'] == 'libs.zip'][0]
156+
# Download zip
157+
zip_download = requests.get(libs_asset['browser_download_url'], stream=True)
158+
z = zipfile.ZipFile(io.BytesIO(zip_download.content))
159+
extract_dir = abspath(join(dirname(abspath(__file__)), 'okapi'))
160+
z.extractall(extract_dir)
161+
# Remove the binaries for other environments.
162+
copy_from, copy_to = get_os_arch_binary(extract_dir)
163+
shutil.copy2(copy_from, copy_to)
164+
cleanup_zip_download(copy_to)
165+
166+
167+
def cleanup_zip_download(copy_to):
168+
# Delete folders
169+
for folder_name in listdir(copy_to):
170+
full_path = join(copy_to, folder_name)
171+
if isdir(full_path):
172+
shutil.rmtree(full_path)
173+
174+
175+
def get_os_arch_binary(extract_dir):
176+
copy_from = ''
177+
copy_to = join(extract_dir, 'libs')
178+
os_name = platform.system().lower()
179+
processor_name = platform.machine().lower()
180+
if os_name == 'windows':
181+
copy_from = join(copy_to, 'windows', 'okapi.dll')
182+
elif os_name == 'linux':
183+
if processor_name == 'amd64':
184+
copy_from = join(copy_to, 'linux', 'libokapi.so')
185+
elif processor_name == 'armv7':
186+
copy_from = join(copy_to, 'linux-armv7', 'libokapi.so')
187+
elif processor_name == 'aarch64':
188+
copy_from = join(copy_to, 'linux-aarch64', 'libokapi.so')
189+
elif os_name == 'darwin':
190+
copy_from = join(copy_to, 'macos', 'libokapi.dylib')
191+
return copy_from, copy_to
192+
193+
143194
def wrap_native_function(function_name: str, *, arg_types: Optional[List[Any]] = None,
144195
return_type: Optional[Any] = None):
145196
library_function = getattr(load_library(), function_name)

python/requirements.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
base58~=2.1.0
22
betterproto~=2.0.0b3
3-
grpcio-tools~=1.40.0
3+
grpcio-tools~=1.40.0
4+
grpclib~=0.4.2
5+
requests~=2.22.0
6+
setuptools~=58.2.0

python/setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ python_requires = >=3.6
2121
install_requires =
2222
protobuf>=3.17.3
2323
betterproto>=2.0.0b3
24+
requests>=2.22.0
2425

2526
[options.packages.find]
2627
exclude = tests

0 commit comments

Comments
 (0)