Skip to content

Commit a59edc4

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

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

.github/workflows/_build_linux_cuda.yml

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