Skip to content

Commit 4d1dd0c

Browse files
committed
Add job to build stub
1 parent bcc172e commit 4d1dd0c

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed

.github/workflows/_build_linux_cuda.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,70 @@ jobs:
9090
"${python_exe}" -m pip install -r ./packaging/requirements.txt
9191
"${python_exe}" -m twine check --strict ~/package/*.whl
9292
93+
check-stub:
94+
if: ${{ inputs.run-test == 'true' }}
95+
needs: ["build"]
96+
runs-on: ${{ inputs.machine }}
97+
strategy:
98+
fail-fast: false
99+
matrix:
100+
ffmpeg-version: ["8.0"]
101+
steps:
102+
- uses: actions/checkout@v4
103+
with:
104+
persist-credentials: false
105+
106+
- uses: actions/download-artifact@v4
107+
with:
108+
name: "${{ env.ARTIFACT }}"
109+
path: ~/package
110+
111+
- uses: conda-incubator/setup-miniconda@v3
112+
with:
113+
python-version: "${{ inputs.python-version }}"
114+
conda-remove-defaults: "true"
115+
116+
- name: Generate stub files
117+
run: |
118+
set -x
119+
120+
pip install $(find "${HOME}/package" -name '*.whl' -depth -maxdepth 1) nanobind
121+
122+
123+
cu_ver="${{ inputs.cuda-version }}"
124+
cu_ver="${cu_ver//[.]/}" # Remove dots
125+
pip install numpy torch --index-url "https://download.pytorch.org/whl/cu${cu_ver}"
126+
127+
# Install FFmpeg
128+
# Note: Somehow FFmepg 5.1 does not install libiconv so specifying it here
129+
conda install -q -c conda-forge "ffmpeg==${{ matrix.ffmpeg-version }}" libiconv
130+
131+
# Sort out library paths
132+
# 1. For some reason, the FFmpeg dynamic libraries are not found.
133+
export "LD_LIBRARY_PATH=${CONDA_PREFIX}/lib"
134+
# 2. CUDA runtime PyPI package is installed as part of PyTorch installation.
135+
# However, it is installed in site-packages dir, which is not in PATH by default.
136+
# (PyTorch has a special way to load it, but we don't do that)
137+
cudart_dir="$(
138+
python -c 'import os.path,nvidia.cuda_runtime;print(os.path.join(nvidia.cuda_runtime.__path__[0], "lib"))'
139+
)"
140+
export "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${cudart_dir}"
141+
142+
143+
python scripts/generate_stub.py -o ~/stubs
144+
cp ~/stubs/* src/spdl/io/lib/
145+
git diff --exit-code
146+
147+
- uses: actions/upload-artifact@v4
148+
name: Upload up-to-date stub files
149+
if: failure()
150+
with:
151+
name: "stub"
152+
path: ~/stubs
153+
if-no-files-found: error
154+
retention-days: 7
155+
overwrite: true
156+
93157
check-package-dependency:
94158
if: ${{ inputs.run-test == 'true' }}
95159
needs: ["build"]

.github/workflows/packaging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ jobs:
6565
build_container: "pytorch/manylinux2_28-builder:cuda${{ matrix.cuda-version }}"
6666
python-version: "${{ matrix.python-version }}"
6767
cuda-version: "${{ matrix.cuda-version }}"
68-
run-test: "${{ matrix.python-version == '3.11'}}"
68+
run-test: "${{ matrix.python-version == '3.12'}}"

scripts/generate_stub.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (c) Meta Platforms, Inc. and affiliates.
4+
# All rights reserved.
5+
#
6+
# This source code is licensed under the BSD-style license found in the
7+
# LICENSE file in the root directory of this source tree.
8+
9+
"""Generate interface files for extension modules."""
10+
11+
import logging
12+
from argparse import ArgumentParser
13+
from pathlib import Path
14+
15+
from nanobind.stubgen import StubGen
16+
from spdl.io.lib import _import_libspdl, _import_libspdl_cuda
17+
18+
19+
def _parse_args():
20+
parser = ArgumentParser(description=__doc__)
21+
parser.add_argument("--output-dir", "-o", required=True, type=Path)
22+
return parser.parse_args()
23+
24+
25+
def _generate(mod, output):
26+
sg = StubGen(mod)
27+
sg.put(mod)
28+
with open(output, "w") as f:
29+
f.write(sg.get())
30+
31+
32+
def _main():
33+
args = _parse_args()
34+
logging.basicConfig(level=logging.DEBUG)
35+
args.output_dir.mkdir(exist_ok=True, parents=True)
36+
_generate(_import_libspdl(), args.output_dir / "_libspdl.pyi")
37+
_generate(_import_libspdl_cuda(), args.output_dir / "_libspdl_cuda.pyi")
38+
39+
40+
if __name__ == "__main__":
41+
_main()

0 commit comments

Comments
 (0)