From d35e881bb75cc94f456d34f894a44778d81c54dc Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Sun, 12 Jul 2020 00:47:17 +1000 Subject: [PATCH] Use per-platform Python wheels --- .github/workflows/python.yml | 66 +++++++++-------------------------- python/Cargo.toml | 9 +++-- python/MANIFEST.in | 1 - python/README.md | 1 + python/hyperbuild/__init__.py | 33 ------------------ python/setup.py | 24 ------------- python/src/lib.rs | 2 +- 7 files changed, 25 insertions(+), 111 deletions(-) delete mode 100644 python/MANIFEST.in create mode 120000 python/README.md delete mode 100644 python/hyperbuild/__init__.py delete mode 100644 python/setup.py diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 51e162d..601397a 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -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 diff --git a/python/Cargo.toml b/python/Cargo.toml index 737b8cc..20be2db 100644 --- a/python/Cargo.toml +++ b/python/Cargo.toml @@ -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 "] edition = "2018" [lib] -name = "hyperbuild_python_lib" +name = "minify_html" crate-type = ["cdylib"] [dependencies] diff --git a/python/MANIFEST.in b/python/MANIFEST.in deleted file mode 100644 index bb75c0f..0000000 --- a/python/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -recursive-include hyperbuild *.so *.pyd diff --git a/python/README.md b/python/README.md new file mode 120000 index 0000000..32d46ee --- /dev/null +++ b/python/README.md @@ -0,0 +1 @@ +../README.md \ No newline at end of file diff --git a/python/hyperbuild/__init__.py b/python/hyperbuild/__init__.py deleted file mode 100644 index bbd6c75..0000000 --- a/python/hyperbuild/__init__.py +++ /dev/null @@ -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 diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index 6629428..0000000 --- a/python/setup.py +++ /dev/null @@ -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', -) diff --git a/python/src/lib.rs b/python/src/lib.rs index b9625b6..ac139a1 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -16,7 +16,7 @@ fn minify(code: String, minify_js: bool) -> PyResult { } #[pymodule] -fn hyperbuild(_py: Python, m: &PyModule) -> PyResult<()> { +fn minify_html(_py: Python, m: &PyModule) -> PyResult<()> { m.add_wrapped(wrap_pyfunction!(minify))?; Ok(())