|
1 | | -# CMake script to generate Python stubs during installation |
2 | | -# This runs as a post-install step to generate .pyi files |
| 1 | +# CMake script to generate Python stubs during installation This runs as a |
| 2 | +# post-install step to generate .pyi files |
3 | 3 |
|
4 | 4 | message(STATUS "Generating Python stubs for pyslang...") |
5 | 5 |
|
6 | 6 | # Find Python executable |
7 | | -find_package(Python COMPONENTS Interpreter REQUIRED) |
| 7 | +find_package( |
| 8 | + Python |
| 9 | + COMPONENTS Interpreter |
| 10 | + REQUIRED) |
8 | 11 |
|
9 | | -# Check if we're in a wheel build (CMAKE_INSTALL_PREFIX will be set to wheel staging directory) |
| 12 | +# Check if we're in a wheel build (CMAKE_INSTALL_PREFIX will be set to wheel |
| 13 | +# staging directory) |
10 | 14 | if(DEFINED ENV{DESTDIR}) |
11 | | - set(INSTALL_DIR "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}") |
| 15 | + set(INSTALL_DIR "$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}") |
12 | 16 | else() |
13 | | - set(INSTALL_DIR "${CMAKE_INSTALL_PREFIX}") |
| 17 | + set(INSTALL_DIR "${CMAKE_INSTALL_PREFIX}") |
14 | 18 | endif() |
15 | 19 |
|
16 | 20 | message(STATUS "Install directory: ${INSTALL_DIR}") |
17 | 21 |
|
18 | 22 | # Try to install pybind11-stubgen if not available |
19 | 23 | execute_process( |
20 | | - COMMAND ${Python_EXECUTABLE} -c "import pybind11_stubgen" |
21 | | - RESULT_VARIABLE STUBGEN_CHECK |
22 | | - OUTPUT_QUIET |
23 | | - ERROR_QUIET |
24 | | -) |
| 24 | + COMMAND ${Python_EXECUTABLE} -c "import pybind11_stubgen" |
| 25 | + RESULT_VARIABLE STUBGEN_CHECK |
| 26 | + OUTPUT_QUIET ERROR_QUIET) |
25 | 27 |
|
26 | 28 | if(NOT STUBGEN_CHECK EQUAL 0) |
27 | | - message(STATUS "Installing pybind11-stubgen...") |
28 | | - execute_process( |
29 | | - COMMAND ${Python_EXECUTABLE} -m pip install pybind11-stubgen |
30 | | - RESULT_VARIABLE PIP_RESULT |
31 | | - OUTPUT_QUIET |
32 | | - ERROR_QUIET |
33 | | - ) |
| 29 | + message(STATUS "Installing pybind11-stubgen...") |
| 30 | + execute_process( |
| 31 | + COMMAND ${Python_EXECUTABLE} -m pip install pybind11-stubgen |
| 32 | + RESULT_VARIABLE PIP_RESULT |
| 33 | + OUTPUT_QUIET ERROR_QUIET) |
34 | 34 | endif() |
35 | 35 |
|
36 | | -# Generate stubs |
37 | | -# Add install dir to Python path so it can import the module |
| 36 | +# Generate stubs Add install dir to Python path so it can import the module |
38 | 37 | set(ENV{PYTHONPATH} "${INSTALL_DIR}:$ENV{PYTHONPATH}") |
39 | 38 |
|
40 | 39 | execute_process( |
41 | | - COMMAND ${Python_EXECUTABLE} -m pybind11_stubgen pyslang -o "${INSTALL_DIR}" --root-suffix "" |
42 | | - WORKING_DIRECTORY ${INSTALL_DIR} |
43 | | - RESULT_VARIABLE STUBGEN_RESULT |
44 | | - OUTPUT_VARIABLE STUBGEN_OUTPUT |
45 | | - ERROR_VARIABLE STUBGEN_ERROR |
46 | | -) |
| 40 | + COMMAND ${Python_EXECUTABLE} -m pybind11_stubgen pyslang -o "${INSTALL_DIR}" |
| 41 | + --root-suffix "" |
| 42 | + WORKING_DIRECTORY ${INSTALL_DIR} |
| 43 | + RESULT_VARIABLE STUBGEN_RESULT |
| 44 | + OUTPUT_VARIABLE STUBGEN_OUTPUT |
| 45 | + ERROR_VARIABLE STUBGEN_ERROR) |
47 | 46 |
|
48 | 47 | if(STUBGEN_RESULT EQUAL 0) |
49 | | - message(STATUS "Successfully generated stubs") |
50 | | - # Verify stub file exists |
51 | | - if(EXISTS "${INSTALL_DIR}/pyslang/__init__.pyi") |
52 | | - message(STATUS "Stub file created: ${INSTALL_DIR}/pyslang/__init__.pyi") |
53 | | - else() |
54 | | - message(WARNING "Stub file not found after generation") |
55 | | - endif() |
| 48 | + message(STATUS "Successfully generated stubs") |
| 49 | + # Verify stub file exists |
| 50 | + if(EXISTS "${INSTALL_DIR}/pyslang/__init__.pyi") |
| 51 | + message(STATUS "Stub file created: ${INSTALL_DIR}/pyslang/__init__.pyi") |
| 52 | + else() |
| 53 | + message(WARNING "Stub file not found after generation") |
| 54 | + endif() |
56 | 55 | else() |
57 | | - message(WARNING "Failed to generate stubs: ${STUBGEN_ERROR}") |
| 56 | + message(WARNING "Failed to generate stubs: ${STUBGEN_ERROR}") |
58 | 57 | endif() |
0 commit comments