From 736b144698653c9ed728f9a5c6de268bccb4e116 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:38:51 -0800 Subject: [PATCH] fix(wheel): prepare for releases (#5) --- .github/actions/setup-repo/action.yml | 8 ---- .github/workflows/ci.yml | 2 + .github/workflows/style.yml | 7 ++++ .github/workflows/wheels.yml | 53 ++++++++++++++++++++------- README.md | 23 ++++++++++++ 5 files changed, 71 insertions(+), 22 deletions(-) diff --git a/.github/actions/setup-repo/action.yml b/.github/actions/setup-repo/action.yml index df7281a..da3ffa0 100644 --- a/.github/actions/setup-repo/action.yml +++ b/.github/actions/setup-repo/action.yml @@ -54,11 +54,3 @@ runs: - name: Make directory shell: bash run: mkdir -p "$HOME/.local/share/whispercpp" - - name: Setup node - uses: actions/setup-node@v3 - with: - node-version: "17" - - name: Install pyright - shell: bash - run: npm install -g npm@^7 pyright - diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01b09e2..868e328 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,6 +26,8 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] python-version: ["3.8", "3.9", "3.10", "3.11"] + exclude: + - python-version: "3.11" if: "!github.event.repository.fork" # Don't run on fork repository name: python${{ matrix.python-version }} integration tests (${{ matrix.os }}) diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 5a59155..e2d174c 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -49,6 +49,13 @@ jobs: isort --check . - name: Lint check run: ruff check src + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: "17" + - name: Install pyright + shell: bash + run: npm install -g npm@^7 pyright - name: Type check if: ${{ github.event_name == 'pull_request' }} run: git diff --name-only --diff-filter=AM "origin/$GITHUB_BASE_REF" -z -- '*.py{,i}' | xargs -0 --no-run-if-empty pyright diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index cef1a6b..875fd67 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -20,7 +20,7 @@ defaults: shell: bash --noprofile --norc -exo pipefail {0} jobs: - build: + build-wheels: # Similar to numpy/numpy wheels actions setup. name: Build wheels for python${{ matrix.python }} (${{ matrix.os }}) runs-on: ${{ matrix.os }} @@ -48,32 +48,57 @@ jobs: - 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: Copy built wheels to dist + id: bazel run: | - ./tools/bazel build //:whispercpp_wheel - - name: Get output wheel path - id: bazel-bin + path=$(./tools/bazel info bazel-bin) + workspace=$(./tools/bazel info workspace) + echo "path=$(echo $workspace)" >> "$GITHUB_OUTPUT" + + mkdir -p "$workspace/dist" + find "$path" -iname "*.whl" -exec cp {} "$workspace/dist/" \; + - uses: actions/upload-artifact@v3 + with: + path: ${{ steps.bazel.outputs.path }}/dist/* + + build-sdist: + name: Build source distribution + runs-on: ubuntu-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: "3.10" + - name: Build sdist run: | - echo "path=$(./tools/bazel info bazel-bin)" >> "$GITHUB_OUTPUT" - ls -rthla $(./tools/bazel info bazel-bin) + # TODO: when bazel support releasing sdist, we can remove this. + pip install build + + python -m build --sdist - uses: actions/upload-artifact@v3 with: - name: cp-python${{ matrix.python }}-${{ matrix.os }} - path: ${{ steps.bazel-bin.outputs.path }}/*.whl + path: dist/*.tar.gz publish: - needs: [build] + needs: [build-wheels, build-sdist] name: Publish wheels to PyPI runs-on: ubuntu-latest - if: github.repository_owner == 'aarnphm' + if: github.repository_owner == 'aarnphm' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') steps: - uses: actions/download-artifact@v3 + with: + name: artifact + path: dist + - name: Check release content + run: ls -rthla dist - 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 }} diff --git a/README.md b/README.md index 92aadf8..e7a415e 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,12 @@ _Pybind11 bindings for [whisper.cpp](https://github.com/ggerganov/whisper.cpp.gi Install with pip: +```bash +pip install whispercpp +``` + +To use the latest version, install from source: + ```bash pip install git+https://github.com/aarnphm/whispercpp.git ``` @@ -126,6 +132,8 @@ See [DEVELOPMENT.md](./DEVELOPMENT.md) ctx = api.Context.from_file("/path/to/saved_weight.bin") ``` + > Note: The context can also be accessed from the `Whisper` class via `w.context` + 2. `api.Params` This class is a wrapper around `whisper_params` @@ -135,3 +143,18 @@ See [DEVELOPMENT.md](./DEVELOPMENT.md) params = api.Params() ``` + + > Note: The params can also be accessed from the `Whisper` class via `w.params` + +## Why not? + +* [whispercpp.py](https://github.com/stlukey/whispercpp.py). There are a few key differences here: + + * They provides the Cython bindings. From the UX standpoint, this achieves the same goal as `whispercpp`. The difference is `whispercpp` use Pybind11 instead. + Feel free to use it if you prefer Cython over Pybind11. Note that `whispercpp.py` and `whispercpp` are mutually exclusive, as they also use the `whispercpp` namespace. + * `whispercpp` provides similar APIs as [`whisper-rs`](https://github.com/tazz4843/whisper-rs), which provides a nicer UX to work with. There are literally two APIs (`from_pretrained` and `transcribe`) to quickly use whisper.cpp in Python. + * `whispercpp` doesn't pollute your `$HOME` directory, rather it follows the [XDG Base Directory Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html) for saved weights. + +* Using `cdll` and `ctypes` and be done with it? + + * This is also valid, but requires a lot of hacking and it is pretty slow comparing to Cython and Pybind11.