Skip to content

Commit

Permalink
feat: wheels releases (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm committed Feb 28, 2023
1 parent 62017e6 commit 965cf95
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 23 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@ name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- "src/**"
- "requirements/**"
- ".github/actions/setup-repo/"
- "pyproject.toml"
- ".github/workflows/ci.yml"
schedule:
- cron: "0 6 * * 1/2" # Every other day 6AM UTC

Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,10 @@ concurrency:
cancel-in-progress: true

on:
schedule:
- cron: "0 0 * * 1/2" # Every other day 12AM UTC
push:
branches: [main]
pull_request:
branches: [main]
paths:
- "src/**"
- "requirements/**"
- ".github/actions/**"
- "pyproject.toml"
- ".github/workflows/style.yml"
schedule:
- cron: "0 0 * * 1/2" # Every other day 12AM UTC

env:
LINES: 200
Expand Down
84 changes: 84 additions & 0 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: wheels

on:
workflow_dispatch:
push:
pull_request:
types: [labeled, opened, synchronized, reopened]

concurrency:
group: wheels-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

env:
LINES: 200
COLUMNS: 200

# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#defaultsrun
defaults:
run:
shell: bash --noprofile --norc -exo pipefail {0}

jobs:
build:
# Similar to numpy/numpy wheels actions setup.
name: Build wheels for python${{ matrix.python }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 20
if: "!github.event.repository.fork" # Don't run on fork repository
strategy:
fail-fast: false
matrix:
python: ["3.8", "3.9", "3.10", "3.11"]
os: ["ubuntu-latest", "macos-latest"]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all tags and branches
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Clang [Linux]
if: runner.os == 'Linux'
uses: egor-tensin/setup-clang@v1
- name: Set up Clang [MacOS]
if: ${{ startsWith(matrix.os, 'macos') }}
run: brew install llvm
- name: Build wheels
run: |
./tools/bazel build //:whispercpp_wheel
- name: Get output wheel path
id: bazel-bin
run: |
echo "path=$(./tools/bazel info bazel-bin)" >> "$GITHUB_OUTPUT"
ls -rthla $(./tools/bazel info bazel-bin)
- uses: actions/upload-artifact@v3
with:
name: cp-python${{ matrix.python }}-${{ matrix.os }}
path: ${{ steps.bazel-bin.outputs.path }}/*.whl

publish:
needs: [build]
name: Publish wheels to PyPI
runs-on: ubuntu-latest
if: github.repository_owner == 'aarnphm'
steps:
- uses: actions/download-artifact@v3
- name: Display structure of downloaded files
run: |
apt-get install -y tree
tree
- name: Publish built wheels
uses: pypa/gh-action-pypi-publish@release/v1
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
with:
password: ${{ secrets.PYPI_API_TOKEN }}


4 changes: 3 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_python//python:packaging.bzl", "py_wheel")
load("@com_github_bentoml_plugins//rules/py:packaging.bzl", "py_package")
load("@python_abi//:abi.bzl", "python_abi")

package(default_visibility = ["//visibility:public"])

Expand Down Expand Up @@ -90,6 +91,7 @@ py_package(

py_wheel(
name = "whispercpp_wheel",
abi = python_abi(),
author = "Aaron Pham",
author_email = "[email protected]",
classifiers = [
Expand Down Expand Up @@ -120,7 +122,7 @@ py_wheel(
"//:x86_64-pc-windows-msvc": "win_amd64",
"//:x86_64-unknown-linux-gnu": "manylinux2014_x86_64",
}),
python_tag = "py3",
python_tag = python_abi(),
strip_path_prefixes = ["src"],
version = "0.0.1",
visibility = ["//:__subpackages__"],
Expand Down
7 changes: 7 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ install_deps()
load("@pybind11_bazel//:python_configure.bzl", "python_configure")

python_configure(name = "local_config_python")

load("//rules:python.bzl", "declare_python_abi")

declare_python_abi(
name = "python_abi",
python_version = "3",
)
4 changes: 2 additions & 2 deletions rules/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ package(default_visibility = ["//:__subpackages__"])
exports_files(["deps.bzl"])

bzl_library(
name = "packaging.bzl",
srcs = ["packaging.bzl"],
name = "python.bzl",
srcs = ["python.bzl"],
)
47 changes: 47 additions & 0 deletions rules/python.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
abi_bzl_template = """\
def python_abi():
return "{python_abi}"
"""

def _get_python_bin(ctx):
python_version = ctx.attr.python_version
if python_version != "2" and python_version != "3":
fail("python_version must be one of: '2', '3'")

# we reuse the PYTHON_BIN_PATH environment variable from pybind11 so that the
# ABI tag we detect is always compatible with the version of python that was
# used for the build.
python_bin = ctx.os.environ.get("PYTHON_BIN_PATH")
if python_bin != None:
return python_bin

python_bin = ctx.which("python" + python_version)
if python_bin != None:
return python_bin

fail("Failed to find python binary.")

def _get_python_abi(ctx, python_bin):
result = ctx.execute([
python_bin,
"-c",
"import platform;" +
"assert platform.python_implementation() == 'CPython';" +
"version = platform.python_version_tuple();" +
"print(f'cp{version[0]}{version[1]}')",
])
return result.stdout.splitlines()[0]

def _declare_python_abi_impl(ctx):
python_bin = _get_python_bin(ctx)
python_abi = _get_python_abi(ctx, python_bin)
ctx.file("BUILD")
ctx.file("abi.bzl", abi_bzl_template.format(python_abi = python_abi))

declare_python_abi = repository_rule(
implementation = _declare_python_abi_impl,
attrs = {
"python_version": attr.string(mandatory = True),
},
local = True,
)

0 comments on commit 965cf95

Please sign in to comment.