Skip to content

Commit

Permalink
Merge pull request #25 from openziti/get-ziti-library-during-setup
Browse files Browse the repository at this point in the history
Get ziti library during setup
  • Loading branch information
ekoby authored Aug 22, 2022
2 parents 89f22f8 + 4bccffc commit 3d7ff7c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 97 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ jobs:
python-version: '3.x'

- name: Install Python Tools
run: python -m pip install -U pip setuptools wheel auditwheel

- name: Get Ziti SDK C
run: |
python tools/get_zitilib.py
run: python -m pip install -U pip setuptools

- name: Run Integration Tests
if: ${{ env.HAVE_TEST_ID == 'true' }}
Expand All @@ -47,23 +43,18 @@ jobs:
pip install .
python -m unittest tests/ziti_tests.py
- name: Build wheels
run: |
pip wheel . -w ./wheelhouse --build-option --plat-name=${{ matrix.spec.target }}
- name: Audit wheel
if: startsWith(matrix.spec.name, 'linux')
- name: Build distro
run: |
auditwheel show ./wheelhouse/*
auditwheel repair --plat=${{ matrix.spec.target }} ./wheelhouse/*
python setup.py sdist
- uses: actions/upload-artifact@v3
if: startsWith(matrix.spec.name, 'linux')
with:
name: ${{ matrix.spec.name }}
path: ./wheelhouse/*.whl
name: openziiti-sdist
path: ./dist/*

publish:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
needs: [ build_wheels ]
steps:
- name: Download artifacts
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ tag_prefix = v
parentdir_prefix = openziti-

[openziti]
ziti_sdk_version = 0.29.3
ziti_sdk_version = 0.29.6
75 changes: 69 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,85 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import setuptools
import platform
from setuptools import setup
from setuptools.command.build_ext import build_ext
from setuptools.extension import Extension
from urllib.request import Request, urlopen
import zipfile
from io import BytesIO

import versioneer

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

ZITI_SDK_BASE = 'https://github.com/openziti/ziti-sdk-c/releases/download'


class GetZitilib(build_ext):

def build_extension(self, ext) -> None:
ziti_ver = self.get_sdk_version()
osname, arch, libname = self.get_platform()
sdk_distro = self.download_sdk(ziti_ver, osname, arch)
self.extract_zitilib(sdk_distro, libname, self.build_lib)

def get_platform(self):
osname = platform.system()
mach = platform.machine()
arch, _ = platform.architecture()

if osname == 'Linux':
if mach.startswith('arm'):
if arch == '32bit':
mach = 'arm'
elif arch == '64bit':
mach = 'arm64'
return osname, mach, 'libziti.so'

if osname == 'Darwin':
return osname, mach, 'libziti.dylib'

if osname == 'Windows':
return osname, mach, 'ziti.dll'

def get_sdk_version(self):
opts = self.distribution.get_option_dict('openziti')
_, ver = opts['ziti_sdk_version']
return ver

def extract_zitilib(self, distro, libname, target):
with zipfile.ZipFile(BytesIO(distro)) as zipf:
return zipf.extract(member=f'lib/{libname}', path=f'{target}/openziti')

def download_sdk(self, version, osname, arch):
filename = f'{ZITI_SDK_BASE}/{version}/ziti-sdk-{version}-{osname}-{arch}.zip'
headers = {}
req = Request(url=filename, headers=headers)
with urlopen(req) as response:
length = response.getheader('content-length')
if response.status != 200:
raise Exception(f'Could not download "{filename}"')
print(f"Downloading {length} from {filename}")
return response.read()

class ZitilibExt(Extension):
def __init__(self, name, sourcedir=''):
Extension.__init__(self, name, sources=[])


cmds = dict(build_ext=GetZitilib)
cmds = versioneer.get_cmdclass(cmds)

setup(
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
cmdclass=cmds,
ext_modules=[
ZitilibExt('_get_ziti_lib'),
],

packages=['openziti'],
include_package_data=True,
package_data={
"openziti": ["lib/*"],
},
)
74 changes: 0 additions & 74 deletions tools/get_zitilib.py

This file was deleted.

0 comments on commit 3d7ff7c

Please sign in to comment.