Skip to content

Commit

Permalink
fix(wheel): prepare for releases (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarnphm committed Feb 28, 2023
1 parent bc7f895 commit 736b144
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 22 deletions.
8 changes: 0 additions & 8 deletions .github/actions/setup-repo/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 39 additions & 14 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}

Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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`
Expand All @@ -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.

0 comments on commit 736b144

Please sign in to comment.