Skip to content

Commit 3d7ff7c

Browse files
authored
Merge pull request #25 from openziti/get-ziti-library-during-setup
Get ziti library during setup
2 parents 89f22f8 + 4bccffc commit 3d7ff7c

File tree

4 files changed

+77
-97
lines changed

4 files changed

+77
-97
lines changed

.github/workflows/wheels.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ jobs:
2828
python-version: '3.x'
2929

3030
- name: Install Python Tools
31-
run: python -m pip install -U pip setuptools wheel auditwheel
32-
33-
- name: Get Ziti SDK C
34-
run: |
35-
python tools/get_zitilib.py
31+
run: python -m pip install -U pip setuptools
3632

3733
- name: Run Integration Tests
3834
if: ${{ env.HAVE_TEST_ID == 'true' }}
@@ -47,23 +43,18 @@ jobs:
4743
pip install .
4844
python -m unittest tests/ziti_tests.py
4945
50-
- name: Build wheels
51-
run: |
52-
pip wheel . -w ./wheelhouse --build-option --plat-name=${{ matrix.spec.target }}
53-
54-
- name: Audit wheel
55-
if: startsWith(matrix.spec.name, 'linux')
46+
- name: Build distro
5647
run: |
57-
auditwheel show ./wheelhouse/*
58-
auditwheel repair --plat=${{ matrix.spec.target }} ./wheelhouse/*
48+
python setup.py sdist
5949
6050
- uses: actions/upload-artifact@v3
51+
if: startsWith(matrix.spec.name, 'linux')
6152
with:
62-
name: ${{ matrix.spec.name }}
63-
path: ./wheelhouse/*.whl
53+
name: openziiti-sdist
54+
path: ./dist/*
6455

6556
publish:
66-
runs-on: ubuntu-18.04
57+
runs-on: ubuntu-20.04
6758
needs: [ build_wheels ]
6859
steps:
6960
- name: Download artifacts

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ tag_prefix = v
3838
parentdir_prefix = openziti-
3939

4040
[openziti]
41-
ziti_sdk_version = 0.29.3
41+
ziti_sdk_version = 0.29.6

setup.py

Lines changed: 69 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,85 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import setuptools
15+
import platform
1616
from setuptools import setup
17+
from setuptools.command.build_ext import build_ext
18+
from setuptools.extension import Extension
19+
from urllib.request import Request, urlopen
20+
import zipfile
21+
from io import BytesIO
22+
1723
import versioneer
1824

1925
# read the contents of your README file
2026
from pathlib import Path
2127
this_directory = Path(__file__).parent
2228
long_description = (this_directory / "README.md").read_text()
2329

30+
ZITI_SDK_BASE = 'https://github.com/openziti/ziti-sdk-c/releases/download'
31+
32+
33+
class GetZitilib(build_ext):
34+
35+
def build_extension(self, ext) -> None:
36+
ziti_ver = self.get_sdk_version()
37+
osname, arch, libname = self.get_platform()
38+
sdk_distro = self.download_sdk(ziti_ver, osname, arch)
39+
self.extract_zitilib(sdk_distro, libname, self.build_lib)
40+
41+
def get_platform(self):
42+
osname = platform.system()
43+
mach = platform.machine()
44+
arch, _ = platform.architecture()
45+
46+
if osname == 'Linux':
47+
if mach.startswith('arm'):
48+
if arch == '32bit':
49+
mach = 'arm'
50+
elif arch == '64bit':
51+
mach = 'arm64'
52+
return osname, mach, 'libziti.so'
53+
54+
if osname == 'Darwin':
55+
return osname, mach, 'libziti.dylib'
56+
57+
if osname == 'Windows':
58+
return osname, mach, 'ziti.dll'
59+
60+
def get_sdk_version(self):
61+
opts = self.distribution.get_option_dict('openziti')
62+
_, ver = opts['ziti_sdk_version']
63+
return ver
64+
65+
def extract_zitilib(self, distro, libname, target):
66+
with zipfile.ZipFile(BytesIO(distro)) as zipf:
67+
return zipf.extract(member=f'lib/{libname}', path=f'{target}/openziti')
68+
69+
def download_sdk(self, version, osname, arch):
70+
filename = f'{ZITI_SDK_BASE}/{version}/ziti-sdk-{version}-{osname}-{arch}.zip'
71+
headers = {}
72+
req = Request(url=filename, headers=headers)
73+
with urlopen(req) as response:
74+
length = response.getheader('content-length')
75+
if response.status != 200:
76+
raise Exception(f'Could not download "{filename}"')
77+
print(f"Downloading {length} from {filename}")
78+
return response.read()
79+
80+
class ZitilibExt(Extension):
81+
def __init__(self, name, sourcedir=''):
82+
Extension.__init__(self, name, sources=[])
83+
84+
85+
cmds = dict(build_ext=GetZitilib)
86+
cmds = versioneer.get_cmdclass(cmds)
87+
2488
setup(
2589
version=versioneer.get_version(),
26-
cmdclass=versioneer.get_cmdclass(),
90+
cmdclass=cmds,
91+
ext_modules=[
92+
ZitilibExt('_get_ziti_lib'),
93+
],
2794

2895
packages=['openziti'],
29-
include_package_data=True,
30-
package_data={
31-
"openziti": ["lib/*"],
32-
},
3396
)

tools/get_zitilib.py

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

0 commit comments

Comments
 (0)