From e0b9cfab501956f7c1deeaaccba2f444a8e220a5 Mon Sep 17 00:00:00 2001 From: melpon Date: Mon, 10 Jun 2024 13:20:00 +0900 Subject: [PATCH 1/5] =?UTF-8?q?sora=5Fsdk=20=E3=81=AB=E5=9E=8B=E3=82=92?= =?UTF-8?q?=E4=BB=98=E3=81=91=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ CHANGES.md | 2 ++ CMakeLists.txt | 10 ++++++++++ pyproject.toml | 1 + requirements-dev.lock | 1 + run.py | 4 ++++ src/sora_sdk_ext.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++- 7 files changed, 64 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 568cd3ac..a1e34b44 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ build src/sora_sdk/*.so src/sora_sdk/*.dll src/sora_sdk/*.pyd +src/sora_sdk/*.pyi +src/sora_sdk/py.typed # パッケージ /dist diff --git a/CHANGES.md b/CHANGES.md index b9f09445..099bdc6f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,8 @@ - @melpon - [UPDATE] Sora C++ SDK のバージョンを `2024.6.1` に上げる - @voluntas +- [ADD] sora_sdk に型を付ける + - @melpon - [FIX] SoraAudioSink.read が timeout を無視して失敗を返すケースがあったので修正する - @enm10k - [FIX] SoraAudioSink.read が timeout を無視するケースがある問題を修正した結果、 read の実行タイミングによってはクラッシュするようになったので修正する diff --git a/CMakeLists.txt b/CMakeLists.txt index 609f31d0..fa488880 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,15 @@ nanobind_add_module( src/sora_video_source.cpp ) +nanobind_add_stub( + sora_sdk_ext_stub + MODULE sora_sdk_ext + OUTPUT sora_sdk_ext.pyi + PYTHON_PATH $ + DEPENDS sora_sdk_ext + MARKER_FILE py.typed +) + set_target_properties(sora_sdk_ext PROPERTIES CXX_STANDARD 20 C_STANDARD 20) set_target_properties(sora_sdk_ext PROPERTIES POSITION_INDEPENDENT_CODE ON) @@ -132,3 +141,4 @@ endif() target_link_libraries(sora_sdk_ext PRIVATE Sora::sora) install(TARGETS sora_sdk_ext LIBRARY DESTINATION .) +install(FILES py.typed sora_sdk_ext.pyi DESTINATION ".") diff --git a/pyproject.toml b/pyproject.toml index f387dda9..d36a32a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,7 @@ dev-dependencies = [ "auditwheel~=6.0.0", "pytest>=8.2", "ruff>=0.4", + "typing-extensions>=4.12.2", ] [tool.ruff] diff --git a/requirements-dev.lock b/requirements-dev.lock index a7f399a9..33c373c3 100644 --- a/requirements-dev.lock +++ b/requirements-dev.lock @@ -34,6 +34,7 @@ setuptools==70.0.0 tomli==2.0.1 # via build # via pytest +typing-extensions==4.12.2 wheel==0.43.0 zipp==3.19.0 # via importlib-metadata diff --git a/run.py b/run.py index 11814d10..3cf84638 100644 --- a/run.py +++ b/run.py @@ -779,6 +779,10 @@ def main(): shutil.copyfile( os.path.join(sora_build_target_dir, file), os.path.join(sora_src_dir, file) ) + if file in ("sora_sdk_ext.pyi", "py.typed"): + shutil.copyfile( + os.path.join(sora_build_target_dir, file), os.path.join(sora_src_dir, file) + ) if __name__ == "__main__": diff --git a/src/sora_sdk_ext.cpp b/src/sora_sdk_ext.cpp index d2ac1e71..afd4dcff 100644 --- a/src/sora_sdk_ext.cpp +++ b/src/sora_sdk_ext.cpp @@ -319,7 +319,50 @@ NB_MODULE(sora_sdk_ext, m) { "insecure"_a = nb::none(), "client_cert"_a = nb::none(), "client_key"_a = nb::none(), "proxy_url"_a = nb::none(), "proxy_username"_a = nb::none(), "proxy_password"_a = nb::none(), - "proxy_agent"_a = nb::none()) + "proxy_agent"_a = nb::none(), + nb::sig("def create_connection(" + "self, " + "signaling_urls: list[str], " + "role: str, " + "channel_id: str, " + "client_id: Optional[str] = None, " + "bundle_id: Optional[str] = None, " + "metadata: Optional[dict] = None, " + "signaling_notify_metadata: Optional[dict] = None, " + "audio_source: Optional[SoraTrackInterface] = None, " + "video_source: Optional[SoraTrackInterface] = None, " + "audio: Optional[bool] = None, " + "video: Optional[bool] = None, " + "audio_codec_type: Optional[str] = None, " + "video_codec_type: Optional[str] = None, " + "video_bit_rate: Optional[int] = None, " + "audio_bit_rate: Optional[int] = None, " + "video_vp9_params: Optional[dict] = None, " + "video_av1_params: Optional[dict] = None, " + "video_h264_params: Optional[dict] = None, " + "simulcast: Optional[bool] = None, " + "spotlight: Optional[bool] = None, " + "spotlight_number: Optional[int] = None, " + "simulcast_rid: Optional[str] = None, " + "spotlight_focus_rid: Optional[str] = None, " + "spotlight_unfocus_rid: Optional[str] = None, " + "forwarding_filter: Optional[dict] = None, " + "data_channels: Optional[list[dict]] = None, " + "data_channel_signaling: Optional[bool] = None, " + "ignore_disconnect_websocket: Optional[bool] = None, " + "data_channel_signaling_timeout: Optional[int] = None, " + "disconnect_wait_timeout: Optional[int] = None, " + "websocket_close_timeout: Optional[int] = None, " + "websocket_connection_timeout: Optional[int] = None, " + "audio_streaming_language_code: Optional[str] = None, " + "insecure: Optional[bool] = None, " + "client_cert: Optional[str] = None, " + "client_key: Optional[str] = None, " + "proxy_url: Optional[str] = None, " + "proxy_username: Optional[str] = None, " + "proxy_password: Optional[str] = None, " + "proxy_agent: Optional[str] = None" + ") -> SoraConnection")) .def("create_audio_source", &Sora::CreateAudioSource, "channels"_a, "sample_rate"_a) .def("create_video_source", &Sora::CreateVideoSource); From 6053be0d315f5e3ecbb594984bb96c27b3933e93 Mon Sep 17 00:00:00 2001 From: melpon Date: Mon, 10 Jun 2024 13:46:44 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=E7=89=B9=E5=AE=9A=E3=81=AE=E7=92=B0?= =?UTF-8?q?=E5=A2=83=E3=81=A0=E3=81=91=20pyi=20=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E3=82=92=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 +++- run.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa488880..cc9d9ccf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,4 +141,6 @@ endif() target_link_libraries(sora_sdk_ext PRIVATE Sora::sora) install(TARGETS sora_sdk_ext LIBRARY DESTINATION .) -install(FILES py.typed sora_sdk_ext.pyi DESTINATION ".") +if (SORA_GEN_PYI) + install(FILES py.typed sora_sdk_ext.pyi DESTINATION ".") +endif() diff --git a/run.py b/run.py index 3cf84638..faa58c10 100644 --- a/run.py +++ b/run.py @@ -754,6 +754,10 @@ def main(): "-DNB_SUFFIX=.cpython-38-aarch64-linux-gnu.so", ] + # Windows 以外の、クロスコンパイルでない環境では pyi ファイルを生成する + if target_platform.os != "windows" and build_platform.package_name == target_platform.package_name: + cmake_args.append("-DSORA_GEN_PYI=ON") + sora_src_dir = os.path.join("src", "sora_sdk") sora_build_dir = os.path.join(build_dir, "sora_sdk") if target_platform.os == "windows": From 20e39e0376f20593c2fc5bbf1fa03a64a9e93b22 Mon Sep 17 00:00:00 2001 From: melpon Date: Mon, 10 Jun 2024 13:51:21 +0900 Subject: [PATCH 3/5] =?UTF-8?q?stub=20=E3=81=AE=E3=81=A8=E3=81=93=E3=82=8D?= =?UTF-8?q?=E3=82=82=E5=9B=B2=E3=81=BE=E3=81=AA=E3=81=84=E3=81=A8=E3=81=84?= =?UTF-8?q?=E3=81=91=E3=81=AA=E3=81=95=E3=81=9D=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cc9d9ccf..6c8cfd4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,14 +84,16 @@ nanobind_add_module( src/sora_video_source.cpp ) -nanobind_add_stub( - sora_sdk_ext_stub - MODULE sora_sdk_ext - OUTPUT sora_sdk_ext.pyi - PYTHON_PATH $ - DEPENDS sora_sdk_ext - MARKER_FILE py.typed -) +if (SORA_GEN_PYI) + nanobind_add_stub( + sora_sdk_ext_stub + MODULE sora_sdk_ext + OUTPUT sora_sdk_ext.pyi + PYTHON_PATH $ + DEPENDS sora_sdk_ext + MARKER_FILE py.typed + ) +endif() set_target_properties(sora_sdk_ext PROPERTIES CXX_STANDARD 20 C_STANDARD 20) set_target_properties(sora_sdk_ext PROPERTIES POSITION_INDEPENDENT_CODE ON) From 6425903c9781b9b4ed24d28d373dbed40761d94e Mon Sep 17 00:00:00 2001 From: melpon Date: Mon, 10 Jun 2024 14:06:15 +0900 Subject: [PATCH 4/5] =?UTF-8?q?pyi=20=E3=82=92=E3=82=B3=E3=83=94=E3=83=BC?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5d414091..78bf63b0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,34 @@ on: - cron: "0 5 * * 1-5" jobs: + # まず pyi を生成する + # クロスコンパイル環境だと pyi が生成できないので、 + # 1箇所で pyi を生成してアーティファクトにアップロードして、 + # それを各ビルドで利用する形にする。 + build_pyi: + runs-on: ubuntu-22.04 + timeout-minutes: 60 + steps: + - uses: actions/checkout@v4 + - run: | + sudo apt-get -y install libva-dev libdrm-dev + - uses: eifinger/setup-rye@v3 + with: + version: 'latest' + - run: echo "$HOME/.rye/shims" >> $GITHUB_PATH + - run: rye pin cpython@3.12 + - run: rye sync + - name: Generate pyi + run: | + rye run python run.py + mkdir sora_sdk/ + cp src/sora_sdk/py.typed sora_sdk/ + cp src/sora_sdk/sora_sdk_ext.pyi sora_sdk/ + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: sora_sdk + path: sora_sdk/ build_linux_macos: strategy: fail-fast: false @@ -46,10 +74,18 @@ jobs: python_version: "3.11" - platform: { name: ubuntu-20.04_armv8_jetson } python_version: "3.12" + needs: [build_pyi] runs-on: ${{ matrix.platform.runs_on }} timeout-minutes: 60 steps: - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: sora_sdk + path: sora_sdk/ + - run: | + cp sora_sdk/py.typed src/sora_sdk/py.typed + cp sora_sdk/sora_sdk_ext.pyi src/sora_sdk/sora_sdk_ext.pyi - run: | sudo apt-get update sudo apt-get -y install libva-dev libdrm-dev @@ -112,6 +148,7 @@ jobs: path: "dist/" build_windows: + needs: [build_pyi] runs-on: windows-2022 timeout-minutes: 60 strategy: @@ -129,6 +166,13 @@ jobs: with: python-version: "${{ matrix.python_version }}" cache: "pip" + - uses: actions/download-artifact@v4 + with: + name: sora_sdk + path: sora_sdk/ + - run: | + cp sora_sdk/py.typed src/sora_sdk/py.typed + cp sora_sdk/sora_sdk_ext.pyi src/sora_sdk/sora_sdk_ext.pyi - run: pip install -r requirements-dev.lock - run: python run.py - run: python -m build From 1580ce2e529f6eaa45074f1f8fb63b92661d9f65 Mon Sep 17 00:00:00 2001 From: melpon Date: Mon, 10 Jun 2024 14:07:26 +0900 Subject: [PATCH 5/5] =?UTF-8?q?paths-ignore=20=E3=81=8B=E3=82=89=20*.yml?= =?UTF-8?q?=20=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78bf63b0..4bc1c934 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,7 +6,6 @@ on: paths-ignore: - "doc/**" - "**.md" - - "**.yml" # 毎日日本時間(JST)の14:00(UTCの5:00)に実行します。 # ただし、週末は除きます。 schedule: