Use per-platform Python wheels
This commit is contained in:
parent
fa5cd831e4
commit
d35e881bb7
|
@ -25,22 +25,12 @@ jobs:
|
|||
PYEXT: 'so'
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Get version
|
||||
id: version
|
||||
shell: bash
|
||||
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')"
|
||||
- name: Get native module file name
|
||||
id: native_file
|
||||
shell: bash
|
||||
env:
|
||||
PYTHON_VERSION: ${{ matrix.python }}
|
||||
# PowerShell doesn't support `${...}` syntax.
|
||||
run: echo ::set-output name=NAME::${{ matrix.ARCH }}-${PYTHON_VERSION//./_}/hyperbuild.${{ matrix.PYEXT }}
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: ${{ matrix.python }}
|
||||
architecture: 'x64'
|
||||
|
||||
- name: Set up Rust (macOS, Linux)
|
||||
if: runner.os != 'Windows'
|
||||
uses: actions-rs/toolchain@v1
|
||||
|
@ -48,6 +38,7 @@ jobs:
|
|||
toolchain: stable
|
||||
profile: minimal
|
||||
default: true
|
||||
|
||||
- name: Set up Rust (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
uses: actions-rs/toolchain@v1
|
||||
|
@ -55,55 +46,33 @@ jobs:
|
|||
toolchain: stable-gnu
|
||||
profile: minimal
|
||||
default: true
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '^1.14.0'
|
||||
|
||||
- name: Set up GCC (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: .\.github\workflows\gcc.ps1
|
||||
|
||||
- name: Run prebuild steps
|
||||
shell: bash
|
||||
run: bash ./prebuild.sh
|
||||
|
||||
- name: Build native module
|
||||
working-directory: ./python
|
||||
run: cargo build --release
|
||||
- name: Install B2 CLI (macOS, Linux)
|
||||
|
||||
- name: Install Python build tools (macOS, Linux)
|
||||
if: runner.os != 'Windows'
|
||||
run: |
|
||||
sudo pip install setuptools
|
||||
sudo pip install --upgrade b2
|
||||
- name: Install B2 CLI (Windows)
|
||||
run: sudo pip install --upgrade maturin setuptools wheel twine
|
||||
- name: Install Python build tools (Windows)
|
||||
if: runner.os == 'Windows'
|
||||
run: |
|
||||
pip install --upgrade b2
|
||||
- name: Upload to B2
|
||||
# Convert dots to underscores in Python version as Python uses dots to represent import hierarchy.
|
||||
run: |
|
||||
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
||||
b2 upload-file ${{ secrets.CICD_CLI_B2_BUCKET_NAME }} ./python/target/release/${{ matrix.LIBFILE }} hyperbuild/bin/python/${{ steps.version.outputs.VERSION }}/${{ steps.native_file.outputs.NAME }}
|
||||
package:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Get version
|
||||
id: version
|
||||
shell: bash
|
||||
run: echo ::set-output name=VERSION::"$([[ "$GITHUB_REF" == refs/tags/v* ]] && echo ${GITHUB_REF#refs/tags/v} || echo '0.0.0')"
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v1
|
||||
with:
|
||||
python-version: '3.5'
|
||||
architecture: 'x64'
|
||||
- name: Install Python dependencies
|
||||
run: |
|
||||
pip install --upgrade wheel
|
||||
pip install --upgrade setuptools
|
||||
pip install --upgrade twine
|
||||
- name: Install B2 CLI
|
||||
run: sudo pip install --upgrade b2
|
||||
run: pip install --upgrade maturin setuptools wheel twine
|
||||
|
||||
- name: Pack and publish package
|
||||
shell: bash
|
||||
working-directory: ./python
|
||||
run: |
|
||||
cat << 'EOF' > "$HOME/.pypirc"
|
||||
|
@ -111,10 +80,7 @@ jobs:
|
|||
username = __token__
|
||||
password = ${{ secrets.PYPI_API_TOKEN }}
|
||||
EOF
|
||||
cp ../README.md .
|
||||
b2 authorize-account ${{ secrets.CICD_CLI_B2_KEY_ID }} ${{ secrets.CICD_CLI_B2_APPLICATION_KEY }}
|
||||
b2 sync b2://${{ secrets.CICD_CLI_B2_BUCKET_NAME }}/hyperbuild/bin/python/${{ steps.version.outputs.VERSION }}/ ./hyperbuild/.
|
||||
python setup.py sdist bdist_wheel
|
||||
if [[ "${{ steps.version.outputs.VERSION }}" != "0.0.0" ]]; then
|
||||
python -m twine upload dist/*
|
||||
maturin build --release --strip
|
||||
if [[ "$GITHUB_REF" == refs/tags/v* ]]; then
|
||||
python -m twine upload target/wheels/*
|
||||
fi
|
||||
|
|
|
@ -1,12 +1,17 @@
|
|||
[package]
|
||||
name = "hyperbuild-python"
|
||||
publish = false
|
||||
name = "minify-html"
|
||||
description = "Fast allocation-less HTML minifier with smart whitespace handling"
|
||||
license = "MIT"
|
||||
homepage = "https://github.com/wilsonzlin/hyperbuild"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/wilsonzlin/hyperbuild.git"
|
||||
version = "0.2.4"
|
||||
authors = ["Wilson Lin <code@wilsonl.in>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
name = "hyperbuild_python_lib"
|
||||
name = "minify_html"
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
recursive-include hyperbuild *.so *.pyd
|
|
@ -0,0 +1 @@
|
|||
../README.md
|
|
@ -1,33 +0,0 @@
|
|||
import importlib
|
||||
import inspect
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
|
||||
|
||||
def _load_native_module():
|
||||
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_name = "unknown"
|
||||
|
||||
os_arch_raw = platform.machine()
|
||||
if os_arch_raw == "AMD64" or os_arch_raw == "x86_64":
|
||||
os_arch = "x86_64"
|
||||
else:
|
||||
os_arch = "unknown"
|
||||
|
||||
this_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile(inspect.currentframe()))[0]))
|
||||
pyv = sys.version_info
|
||||
sys.path.insert(0, this_folder)
|
||||
module = importlib.import_module(''.join([os_name, "-", os_arch, '-', str(pyv.major), '_', str(pyv.minor), ".hyperbuild"]))
|
||||
sys.path.pop(0)
|
||||
return module
|
||||
|
||||
|
||||
minify = _load_native_module().minify
|
|
@ -1,24 +0,0 @@
|
|||
import setuptools
|
||||
|
||||
with open("README.md", "r") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setuptools.setup(
|
||||
name="hyperbuild",
|
||||
version="0.2.4",
|
||||
author="Wilson Lin",
|
||||
author_email="code@wilsonl.in",
|
||||
description="Fast allocation-less HTML minifier with smart whitespace handling",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/wilsonzlin/hyperbuild",
|
||||
packages=["hyperbuild"],
|
||||
include_package_data=True,
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
python_requires='>=3.5',
|
||||
)
|
|
@ -16,7 +16,7 @@ fn minify(code: String, minify_js: bool) -> PyResult<String> {
|
|||
}
|
||||
|
||||
#[pymodule]
|
||||
fn hyperbuild(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
fn minify_html(_py: Python, m: &PyModule) -> PyResult<()> {
|
||||
m.add_wrapped(wrap_pyfunction!(minify))?;
|
||||
|
||||
Ok(())
|
||||
|
|
Loading…
Reference in New Issue