Skip to content

Commit b9baa5b

Browse files
authored
pypi への公開と pytest でのテストを追加する (#107)
* pyproject を追加 * uv.lock も追加 * お試しの PyPI build を追加 * PyPIビルドのワークフローを更新し、feature/pypiブランチへのプッシュをトリガーに追加する * 試しビルド * uvのインストールステップをビルドプロセスに追加する * typo * ビルドプロセスのランナーをubuntu-22.04に修正し、アーキテクチャを考慮したホイール名のフォーマットを更新する * macos の wheel 生成も追加 * PyPI パッケージ公開用の workflow を実装する - タグプッシュ時のみ PyPI への公開を実行 - canary バージョンを Python PEP 440 準拠の dev バージョンに自動変換 - 例: 2025.2.0-canary.0 → 2025.2.0.dev0 - Cargo.toml のバージョンを動的に書き換えて maturin が読み取る方式を採用 - TestPyPI と本番 PyPI への公開ステップを追加(本番は現在コメントアウト) - feature/pypi ブランチではビルドのみでテスト可能 * 変更履歴を更新する * Hisui を利用できる用にする * Python 3.12 以降にする * Python ライブラリとして利用できたり uv 経由でインストールできる * Python に関する確認事項を追加する * ビルド手順を README に追加する * pyproject.toml と uv.lock に依存関係を追加する * Hisui クラスの初期化時にバイナリパスの指定を不要にする。型ヒントを統一し、テストケースを追加する。 * バージョンを canary.0 に上げる * [skip-ci] 依存関係のインストール手順を追加し、Cargoビルドのステップを整理する * バージョンについて書き換える * バージョンを上げる * pyproject.toml のバージョン設定を動的に変更する * maturin の開発およびビルド用スクリプトを追加する * 変更履歴を更新する * Rust のインストール手順を修正し、バージョン変換メッセージを改善する * environment を指定する * manylinux_2_31 互換性を設定する Ubuntu 22.04 の環境に合わせて、manylinux_2_31 を明示的に指定。 これにより PyPI にアップロード可能な正しい wheel 名が生成される。 - pyproject.toml に compatibility = "manylinux_2_31" を追加 - py3-none-linux_x86_64 ではなく manylinux_2_31 wheel が生成される * manylinux_2_35 に修正する Ubuntu 22.04 は glibc 2.35 を使用しているため、manylinux_2_31 ではビルドできない。 適切な manylinux_2_35 に変更。 - manylinux_2_31 -> manylinux_2_35 - Ubuntu 22.04 の glibc バージョンと一致 * --compatibility pypi オプションを使用してPyPI互換性を確保する maturin build に --compatibility pypi オプションを追加。 これにより自動的に PyPI 互換の wheel 名が生成される: - Linux: 適切な manylinux タグを自動選択 - macOS: 適切な macosx タグを自動選択 pyproject.toml から compatibility 設定を削除し、 コマンドラインオプションで指定するように変更。 * --compatibility pypi を指定してみる * ビルドを軽くする * cargo build そもそも不要だった * uv の Python バージョンを 3.13 に設定し、maturin のヘルプを表示するコマンドを追加する * typo * maturin のヘルプ表示コマンドを削除し、ビルドコマンドを簡素化する pyproject.toml から不要な分類を削除する * arm アーキテクチャのビルドを有効にし、Python バージョンを 3.12 に変更する * maturin のビルドおよび開発コマンドを簡素化する * maturin のビルドコマンドに互換性オプションを追加する * macOS のビルドターゲットを設定し、arm64 アーキテクチャのバージョンを更新する * macOS のビルドターゲットを arm64 アーキテクチャのバージョン 14.0 に更新する * テスト用のバージョンにする * バージョンを戻す * バージョンを戻す * macos-deployment-target を指定する * macos の指定を削除 * コスメ * README.md に警告メッセージを追加する * cuda ビルドを含める * ビルド方法を uv を使わないやりかたに切り替える * 最小限にする * CI の設定を更新し、特定のパスを無視するようにする * uv の設定を追加し、自動ビルドを避けるために package を false に設定する uv.lock のソースを editable から virtual に変更する * pytest のワークフローを追加し、テスト手順を整備する * maturin develop する前に uv sync しておく * `maturin develop` をするまえに `uv sync` することを追記する * Python 3.12-3.14 でテストするようにする * pyproject を整理 * maturin を uv 経由で利用するようにする * uv 経由での maturin に切り替える * maturin を dev-dependencies に追加する * 変更履歴を更新する * README.md にビルド手順を追加する AGENTS.md の Python セクションを更新する * Cargo.toml のバージョンを Python 互換形式に変換するアクションを追加する * uv run maturin にする * maturin develop を uv run maturin develop に変更する * バージョンに canary.0 を付けてみる * Revert "バージョンに canary.0 を付けてみる" This reverts commit 917c26a.
1 parent 084dfe5 commit b9baa5b

File tree

16 files changed

+944
-23
lines changed

16 files changed

+944
-23
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Convert Cargo version for Python
2+
description: Cargo.toml のバージョンを Python 互換形式に変換する(-canary. を -dev. に変換)
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Convert version
8+
shell: bash
9+
run: |
10+
# Cargo.toml のバージョンを取得
11+
ORIGINAL_VERSION=$(grep '^version = ' Cargo.toml | cut -d'"' -f2)
12+
echo "Original version: $ORIGINAL_VERSION"
13+
14+
# -canary. を -dev. に変換(必要な場合のみ)
15+
if [[ "$ORIGINAL_VERSION" == *"-canary."* ]]; then
16+
PYTHON_VERSION="${ORIGINAL_VERSION//-canary./-dev.}"
17+
echo "Converting to Python-compatible version: $PYTHON_VERSION"
18+
19+
# OS によって sed のオプションを変更
20+
if [[ "$OSTYPE" == "darwin"* ]]; then
21+
# macOS では sed -i に '' が必要
22+
sed -i '' "s/^version = \"$ORIGINAL_VERSION\"/version = \"$PYTHON_VERSION\"/" Cargo.toml
23+
if [ -f Cargo.lock ]; then
24+
sed -i '' "s/^version = \"$ORIGINAL_VERSION\"/version = \"$PYTHON_VERSION\"/" Cargo.lock
25+
fi
26+
else
27+
# Linux
28+
sed -i "s/^version = \"$ORIGINAL_VERSION\"/version = \"$PYTHON_VERSION\"/" Cargo.toml
29+
if [ -f Cargo.lock ]; then
30+
sed -i "s/^version = \"$ORIGINAL_VERSION\"/version = \"$PYTHON_VERSION\"/" Cargo.lock
31+
fi
32+
fi
33+
fi

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88
- "feature/**"
99
paths-ignore:
1010
- "**.md"
11+
- "python/**"
12+
- ".github/workflows/pypi-publish.yml"
1113
schedule:
1214
# UTC の 01:00 は JST だと 10:00 。
1315
# 1-5 で 月曜日から金曜日

.github/workflows/pypi-publish.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: PyPI Build and Publish
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- feature/pypi
8+
tags:
9+
- "*"
10+
11+
env:
12+
CUDA_VERSION: 13.0.2
13+
14+
jobs:
15+
linux-wheel:
16+
name: Build manylinux wheels
17+
strategy:
18+
matrix:
19+
include:
20+
- runner: ubuntu-22.04
21+
arch: x86_64
22+
- runner: ubuntu-22.04-arm
23+
arch: aarch64
24+
runs-on: ${{ matrix.runner }}
25+
timeout-minutes: 30
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v5
29+
30+
- name: Install packages to build external dependencies
31+
run: |
32+
sudo apt-get update
33+
sudo apt-get install -y meson ninja-build nasm yasm build-essential autoconf automake libtool pkg-config yasm cmake
34+
35+
- name: Convert Cargo version for Python
36+
uses: ./.github/actions/convert-cargo-version-for-python
37+
38+
- name: Install Rust
39+
run: |
40+
rustup update stable
41+
rustup default stable
42+
43+
- name: Install uv
44+
uses: astral-sh/setup-uv@v6
45+
with:
46+
python-version: 3.12
47+
48+
# CUDA のインストール (x86_64 のみ)
49+
- uses: shiguredo/github-actions/.github/actions/setup-cuda-toolkit@main
50+
if: contains(matrix.arch, 'x86_64')
51+
id: cuda
52+
with:
53+
cuda_version: ${{ env.CUDA_VERSION }}
54+
platform: ${{ matrix.runner }}
55+
56+
- name: Build wheel with Maturin
57+
if: matrix.arch == 'x86_64'
58+
run: uv run maturin build --release --features nvcodec --compatibility pypi
59+
60+
- name: Build wheel with Maturin
61+
if: matrix.arch == 'aarch64'
62+
run: uv run maturin build --release --compatibility pypi
63+
64+
- name: Upload wheels
65+
uses: actions/upload-artifact@v5
66+
with:
67+
name: wheels-${{ matrix.runner }}-${{ matrix.arch }}
68+
path: target/wheels/*.whl
69+
70+
macos-wheel:
71+
name: Build macOS wheels
72+
strategy:
73+
matrix:
74+
include:
75+
- runner: macos-14
76+
arch: arm64
77+
runs-on: ${{ matrix.runner }}
78+
timeout-minutes: 30
79+
steps:
80+
- name: Checkout
81+
uses: actions/checkout@v5
82+
83+
- name: Install packages to build external dependencies
84+
run: |
85+
brew update
86+
brew install meson nasm yasm automake autoconf libtool
87+
88+
- name: Convert Cargo version for Python
89+
uses: ./.github/actions/convert-cargo-version-for-python
90+
91+
- name: Install Rust
92+
run: |
93+
rustup update stable
94+
rustup default stable
95+
96+
- name: Install uv
97+
uses: astral-sh/setup-uv@v6
98+
99+
- name: Build wheel with Maturin
100+
run: uv run maturin build --release --compatibility pypi
101+
102+
- name: Upload wheels
103+
uses: actions/upload-artifact@v5
104+
with:
105+
name: wheels-${{ matrix.runner }}-${{ matrix.arch }}
106+
path: target/wheels/*.whl
107+
108+
publish:
109+
name: Publish to PyPI
110+
if: startsWith(github.ref, 'refs/tags/')
111+
needs: [linux-wheel, macos-wheel]
112+
runs-on: ubuntu-latest
113+
environment: pypi
114+
# environment: testpypi
115+
permissions:
116+
id-token: write
117+
steps:
118+
- name: Download all artifacts
119+
uses: actions/download-artifact@v5
120+
with:
121+
pattern: wheels-*
122+
path: dist
123+
merge-multiple: true
124+
125+
# テスト用
126+
# - name: Publish package to TestPyPI
127+
# uses: pypa/gh-action-pypi-publish@release/v1
128+
# with:
129+
# repository-url: https://test.pypi.org/legacy/
130+
131+
# 本番用
132+
- name: Publish package to PyPI
133+
uses: pypa/gh-action-pypi-publish@release/v1

.github/workflows/pytest.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Pytest
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- feature/pypi
8+
tags:
9+
- "*"
10+
11+
env:
12+
CUDA_VERSION: 13.0.2
13+
14+
jobs:
15+
pytest:
16+
strategy:
17+
matrix:
18+
runs_on:
19+
- ubuntu-22.04
20+
- ubuntu-22.04-arm
21+
- macos-14
22+
python_version:
23+
- "3.12"
24+
- "3.13"
25+
- "3.14"
26+
runs-on: ${{ matrix.runs_on }}
27+
timeout-minutes: 20
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v5
31+
32+
- name: Install packages to build external dependencies
33+
if: startsWith(matrix.runs_on, 'macos')
34+
run: |
35+
brew update
36+
brew install meson nasm yasm automake autoconf libtool
37+
38+
- name: Install packages to build external dependencies
39+
if: startsWith(matrix.runs_on, 'ubuntu')
40+
run: |
41+
sudo apt-get update
42+
sudo apt-get install -y meson ninja-build nasm yasm build-essential autoconf automake libtool pkg-config yasm cmake
43+
44+
- name: Convert Cargo version for Python
45+
uses: ./.github/actions/convert-cargo-version-for-python
46+
47+
- name: Install Rust
48+
run: |
49+
rustup update stable
50+
rustup default stable
51+
52+
- name: Install uv
53+
uses: astral-sh/setup-uv@v6
54+
with:
55+
python-version: ${{ matrix.python_version }}
56+
57+
- name: Sync uv dependencies
58+
run: uv sync
59+
60+
- name: Build with Maturin
61+
run: uv run maturin develop --no-default-features
62+
63+
- name: Run pytest
64+
run: uv run pytest

AGENTS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@
2424
- コミットメッセージは日本語で書くこと
2525
- コミットメッセージは命令形で書くこと
2626
- コミットメッセージは〜するという形で書くこと
27+
28+
## Python について
29+
30+
- コメントは日本語で書くこと
31+
- `uv run maturin develop` でビルドできることを確認すること
32+
- `uv run pytest` でテストが通ることを確認すること

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
## develop
1313

14+
- [ADD] PyPI に `hiusi` を登録する GitHub Actions `pypi-publish.yml` を追加する
15+
- バージョンが `-canary.X``.devX` 形式に変換される
16+
- @voluntas
17+
18+
### misc
19+
20+
- [ADD] Hisui Python バインディングテスト用の GitHub Actions `pytest.yml` を追加する
21+
- @voluntas
22+
- [ADD] python/tests に Hisui Python バインディングのテストコードを追加する
23+
- @voluntas
24+
1425
## 2025.3.0
1526

1627
**リリース日**: 2025-11-06

README.md

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@ Media Pipeline Tool Hisui は以下の特徴を持つ予定です。
6161
- RTP 入出力機能
6262
- HLS 出力機能
6363

64+
## インストール
65+
66+
Hisui は [uv](https://docs.astral.sh/uv/) を利用して PyPI 経由でインストールすることができます。
67+
68+
```bash
69+
uv tool install hisui
70+
```
71+
72+
## Python ライブラリとして利用する
73+
74+
Hisui は Python でコマンドラインのラッパーライブラリを提供しています。
75+
76+
```bash
77+
uv add hisui
78+
```
79+
80+
```python
81+
from hisui import Hisui
82+
83+
with Hisui() as hisui:
84+
# List available codecs
85+
codecs = hisui.list_codecs()
86+
print(codecs)
87+
```
88+
6489
## ファイル形式
6590

6691
- Sora が生成した MP4 または WebM ファイルに対応しています
@@ -83,29 +108,7 @@ Media Pipeline Tool Hisui は以下の特徴を持つ予定です。
83108
> Ubuntu を利用する場合、 FDK-AAC を利用した AAC のエンコードに対応しています。
84109
> ただし、 `libfdk-aac-dev` パッケージをシステムにインストールした上で、 `--features fdk-aac` を指定して Hisui を自前でビルドする必要があります。
85110
86-
### Hisui レガシー機能
87-
88-
新しい Hisui のレガシー機能は [レガシー版の Hisui](<https://github.com/shiguredo/hisui-legacy>) とほぼ互換性があります。
89-
レガシー版の Hisui は新しい Hisui が正式リリースしたタイミングで非推奨となります。
90-
Hisui レガシー機能は Hisui 2025.1.x でのみ利用できます。
91-
92-
2025.2.x からは Hisui レガシー機能は削除していますので、ご注意ください。
93-
94-
### 新しい Hisui とレガシー版 Hisui の違い
95-
96-
- Rust で実装されています
97-
- macOS の Audio Toolbox を利用した AAC の音声エンコードに対応しています
98-
- macOS の Video Toolbox を利用した H.264/H.265 のハードウェアアクセラレーターの映像デコード/エンコードに対応しています
99-
- MP4 と WebM の入力形式に対応しています
100-
- 分割録画機能が出力するファイル形式に対応しています
101-
- 出力形式が MP4 形式のみです
102-
- WebM での出力形式は非対応です
103-
- AV1 のデコーダに [dav1d](https://code.videolan.org/videolan/dav1d/) を利用しています
104-
- Intel VPL に非対応です
105-
- NVIDIA Video Codec に対応しています
106-
- [Optuna](https://optuna.org/) を利用したエンコーダーパラメータの自動調整機能を利用できます
107-
108-
詳細は [migrate_hisui_legacy\.md](docs/migrate_hisui_legacy.md) をご覧ください。
111+
##
109112

110113
## 動作環境
111114

@@ -223,3 +226,28 @@ H.265 が利用可能なバイナリを配布する事は、ライセンスが
223226

224227
- [Access Advance](https://accessadvance.com/ja/)
225228
- [Via Licensing Alliance](https://www.via-la.com/)
229+
230+
## Hisui レガシー機能
231+
232+
> [!IMPORTANT]
233+
> Hisui レガシー機能は 2025.1.x でのみ利用できます。
234+
235+
新しい Hisui のレガシー機能は [レガシー版の Hisui](<https://github.com/shiguredo/hisui-legacy>) とほぼ互換性があります。
236+
レガシー版の Hisui は新しい Hisui が正式リリースしたタイミングで非推奨となります。
237+
Hisui レガシー機能は Hisui 2025.1.x でのみ利用できます。
238+
239+
### 新しい Hisui とレガシー版 Hisui の違い
240+
241+
- Rust で実装されています
242+
- macOS の Audio Toolbox を利用した AAC の音声エンコードに対応しています
243+
- macOS の Video Toolbox を利用した H.264/H.265 のハードウェアアクセラレーターの映像デコード/エンコードに対応しています
244+
- MP4 と WebM の入力形式に対応しています
245+
- 分割録画機能が出力するファイル形式に対応しています
246+
- 出力形式が MP4 形式のみです
247+
- WebM での出力形式は非対応です
248+
- AV1 のデコーダに [dav1d](https://code.videolan.org/videolan/dav1d/) を利用しています
249+
- Intel VPL に非対応です
250+
- NVIDIA Video Codec に対応しています
251+
- [Optuna](https://optuna.org/) を利用したエンコーダーパラメータの自動調整機能を利用できます
252+
253+
詳細は [migrate_hisui_legacy\.md](docs/migrate_hisui_legacy.md) をご覧ください。

0 commit comments

Comments
 (0)