Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions .github/workflows/python-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Generate Stubs
run: |
python -m venv venv/
./venv/bin/python -m pip install --upgrade pip
./venv/bin/python -m pip install build twine pybind11-stubgen
./venv/bin/python -m pip install .
mkdir pyslang/pyslang/
./venv/bin/python -m pybind11_stubgen pyslang -o pyslang/ --root-suffix ''
test -f pyslang/pyslang/__init__.pyi
- name: Build SDist
run: pipx run build --sdist
- name: Check metadata
Expand Down Expand Up @@ -56,26 +47,6 @@ jobs:
if: matrix.os == 'macos-latest'
with:
xcode-version: 'latest'
- name: Generate Stubs
if: matrix.os != 'windows-latest'
run: |
python -m venv venv/
./venv/bin/python -m pip install --upgrade pip
./venv/bin/python -m pip install build twine pybind11-stubgen
./venv/bin/python -m pip install .
mkdir pyslang/pyslang/
./venv/bin/python -m pybind11_stubgen pyslang -o pyslang/ --root-suffix ''
test -f pyslang/pyslang/__init__.pyi
- name: Generate Stubs (Windows)
if: matrix.os == 'windows-latest'
run: |
python -m venv venv/
./venv/Scripts/python -m pip install --upgrade pip
./venv/Scripts/python -m pip install build twine pybind11-stubgen
./venv/Scripts/python -m pip install .
mkdir pyslang/pyslang/
./venv/Scripts/python -m pybind11_stubgen pyslang -o pyslang/ --root-suffix ''
test -f pyslang/pyslang/__init__.pyi
- uses: pypa/[email protected]
env:
CIBW_ARCHS_MACOS: auto universal2
Expand Down
9 changes: 9 additions & 0 deletions bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,12 @@ install(
TARGETS pyslang
COMPONENT pylib
DESTINATION .)

# Install py.typed marker file for PEP 561 compliance
install(
FILES ${CMAKE_CURRENT_SOURCE_DIR}/../pyslang/pyslang/py.typed
COMPONENT pylib
DESTINATION .)

# Generate Python stubs as a post-install step
install(SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/generate_stubs.cmake COMPONENT pylib)
57 changes: 57 additions & 0 deletions bindings/generate_stubs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# CMake script to generate Python stubs during installation This runs as a
# post-install step to generate .pyi files

message(STATUS "Generating Python stubs for pyslang...")

# Find Python executable
find_package(
Python
COMPONENTS Interpreter
REQUIRED)

# Check if we're in a wheel build (CMAKE_INSTALL_PREFIX will be set to wheel
# staging directory)
if(DEFINED ENV{DESTDIR})
set(INSTALL_DIR "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}")
else()
set(INSTALL_DIR "${CMAKE_INSTALL_PREFIX}")
endif()

message(STATUS "Install directory: ${INSTALL_DIR}")

# Try to install pybind11-stubgen if not available
execute_process(
COMMAND ${Python_EXECUTABLE} -c "import pybind11_stubgen"
RESULT_VARIABLE STUBGEN_CHECK
OUTPUT_QUIET ERROR_QUIET)

if(NOT STUBGEN_CHECK EQUAL 0)
message(STATUS "Installing pybind11-stubgen...")
execute_process(
COMMAND ${Python_EXECUTABLE} -m pip install pybind11-stubgen
RESULT_VARIABLE PIP_RESULT
OUTPUT_QUIET ERROR_QUIET)
endif()

# Generate stubs Add install dir to Python path so it can import the module
set(ENV{PYTHONPATH} "${INSTALL_DIR}:$ENV{PYTHONPATH}")

execute_process(
COMMAND ${Python_EXECUTABLE} -m pybind11_stubgen pyslang -o "${INSTALL_DIR}"
--root-suffix ""
WORKING_DIRECTORY ${INSTALL_DIR}
RESULT_VARIABLE STUBGEN_RESULT
OUTPUT_VARIABLE STUBGEN_OUTPUT
ERROR_VARIABLE STUBGEN_ERROR)

if(STUBGEN_RESULT EQUAL 0)
message(STATUS "Successfully generated stubs")
# Verify stub file exists
if(EXISTS "${INSTALL_DIR}/pyslang/__init__.pyi")
message(STATUS "Stub file created: ${INSTALL_DIR}/pyslang/__init__.pyi")
else()
message(WARNING "Stub file not found after generation")
endif()
else()
message(WARNING "Failed to generate stubs: ${STUBGEN_ERROR}")
endif()
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ Changelog = "https://github.com/MikePopoloski/slang/blob/master/CHANGELOG.md"
test = ["pytest"]

[build-system]
requires = ["pybind11 == 3.*", "scikit-build-core"]
requires = ["pybind11 == 3.*", "scikit-build-core", "pybind11-stubgen"]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
cmake.source-dir = "."
install.components = ["pylib"]
sdist.exclude = [".github", "./build", "./install", "./tests", "./tools"]
wheel.packages = ["pyslang/pyslang"]
wheel.install-dir = "pyslang"
wheel.license-files = ["LICENSE"]

[tool.scikit-build.cmake.define]
SLANG_INCLUDE_TESTS = "OFF"
Expand Down
Empty file added pyslang/pyslang/py.typed
Empty file.
Loading