From 4a778690490aced8e7aa896896ce170046c8fb45 Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Mon, 20 Jan 2020 21:55:17 +1100 Subject: [PATCH] Build Python per version --- .github/workflows/python.yml | 8 ++++++-- .github/workflows/ruby.yml | 1 + python/hyperbuild/__init__.py | 29 +++++++++++++++++++---------- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 0cf7179..8a8c93f 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -11,6 +11,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] + python: [3.5, 3.6, 3.7, 3.8] include: - os: ubuntu-latest ARCH: linux-x86_64 @@ -33,7 +34,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v1 with: - python-version: '3.5' + python-version: ${{ matrix.python }} architecture: 'x64' - name: Set up Rust uses: actions-rs/toolchain@v1 @@ -50,7 +51,9 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_REGION: us-west-2 - run: aws s3 cp ./python/target/release/${{ matrix.LIBFILE }} s3://${{ secrets.AWS_S3_BUCKET }}/hyperbuild/bin/python/${{ steps.version.outputs.VERSION }}/${{ matrix.ARCH }}/hyperbuild.${{ matrix.PYEXT }} + PYTHON_VERSION: ${{ matrix.python }} + # Convert dots to underscores in Python version as Python uses dots to represent import hierarchy. + run: aws s3 cp ./python/target/release/${{ matrix.LIBFILE }} s3://${{ secrets.AWS_S3_BUCKET }}/hyperbuild/bin/python/${{ steps.version.outputs.VERSION }}/${{ matrix.ARCH }}-${PYTHON_VERSION//./_}/hyperbuild.${{ matrix.PYEXT }} package: runs-on: ubuntu-latest needs: build @@ -66,6 +69,7 @@ jobs: python-version: '3.5' architecture: 'x64' - name: Install Python dependencies + # chrislennon/action-aws-cli@v1.1 interferes with installed Python libraries. run: | pip install --upgrade awscli pip install --upgrade wheel diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index f6bfac9..d97134c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -21,6 +21,7 @@ jobs: FILE: 'libhyperbuild_ruby_lib.dylib' steps: - uses: actions/checkout@v1 + # Install Ruby manually as actions/setup-ruby@v1 does not compile with `--enable-shared`. - name: Prepare for rbenv run: | cat << 'EOF' >> "$HOME/.bash_profile" diff --git a/python/hyperbuild/__init__.py b/python/hyperbuild/__init__.py index d7c72c9..6e10d1e 100644 --- a/python/hyperbuild/__init__.py +++ b/python/hyperbuild/__init__.py @@ -1,16 +1,20 @@ -import platform import importlib +import inspect +import os +import platform +import sys + def _load_native_module(): - os_raw = platform.system() - if os_raw == "Linux": - os = "linux" - elif os_raw == "Darwin": - os = "macos" - elif os_raw == "Windows": - os = "windows" + os_name_raw = platform.system() + if os_name_raw == "Linux": + os_name = "linux" + elif os_name_raw == "Darwin": + os_name = "macos" + elif os_name_raw == "Windows": + os_name = "windows" else: - os = "unknown" + os_name = "unknown" os_arch_raw = platform.machine() if os_arch_raw == "AMD64" or os_arch_raw == "x86_64": @@ -18,6 +22,11 @@ def _load_native_module(): else: os_arch = "unknown" - return importlib.import_module(os + "-" + os_arch + ".hyperbuild") + this_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0])) + sys.path.insert(0, this_folder) + module = importlib.import_module(''.join([os_name, "-", os_arch, '-', sys.version_info.major, '_', sys.version_info.minor, ".hyperbuild"])) + sys.path.pop(0) + return module + minify = _load_native_module().minify