Skip to content

Commit abc6f96

Browse files
committed
fix stubgen failure pybind11
1 parent a95c568 commit abc6f96

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

.ci/all_requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ ml-dtypes==0.5.1 ; python_version < "3.13" \
193193
--hash=sha256:c9945669d3dadf8acb40ec2e57d38c985d8c285ea73af57fc5b09872c516106d \
194194
--hash=sha256:d13755f8e8445b3870114e5b6240facaa7cb0c3361e54beba3e07fa912a6e12b \
195195
--hash=sha256:fd918d4e6a4e0c110e2e05be7a7814d10dc1b95872accbf6512b80a109b71ae1
196-
# via -r ./mlir/python/requirements.txt
197-
nanobind @ git+https://github.com/wjakob/nanobind
196+
# via -r mlir/python/requirements.txt
197+
nanobind==2.7.0 \
198+
--hash=sha256:73b12d0e751d140d6c1bf4b215e18818a8debfdb374f08dc3776ad208d808e74 \
199+
--hash=sha256:f9f1b160580c50dcf37b6495a0fd5ec61dc0d95dae5f8004f87dd9ad7eb46b34
198200
# via -r mlir/python/requirements.txt
199201
numpy==2.0.2 \
200202
--hash=sha256:0123ffdaa88fa4ab64835dcbde75dcdf89c453c922f18dced6e27c90d1d0ec5a \

.ci/monolithic-linux.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ lit_args="-v --xunit-xml-output ${BUILD_DIR}/test-results.xml --use-unique-outpu
3434
start-group "CMake"
3535
export PIP_BREAK_SYSTEM_PACKAGES=1
3636
pip install -q -r "${MONOREPO_ROOT}"/.ci/all_requirements.txt
37-
pip install "nanobind @ git+https://github.com/wjakob/nanobind"
3837

3938
# Set the system llvm-symbolizer as preferred.
4039
export LLVM_SYMBOLIZER_PATH=`which llvm-symbolizer`

.ci/monolithic-windows.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ targets="${2}"
2020

2121
start-group "CMake"
2222
pip install -q -r "${MONOREPO_ROOT}"/.ci/all_requirements.txt
23-
pip install "nanobind @ git+https://github.com/wjakob/nanobind"
2423
pip install typing_extensions
2524

2625
export CC=cl

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ endfunction()
151151
function(declare_mlir_python_extension name)
152152
cmake_parse_arguments(ARG
153153
""
154-
"ROOT_DIR;MODULE_NAME;ADD_TO_PARENT;PYTHON_BINDINGS_LIBRARY"
154+
"ROOT_DIR;MODULE_NAME;ADD_TO_PARENT;PYTHON_BINDINGS_LIBRARY;GENERATE_TYPE_STUBS"
155155
"SOURCES;PRIVATE_LINK_LIBS;EMBED_CAPI_LINK_LIBS"
156156
${ARGN})
157157

@@ -163,17 +163,24 @@ function(declare_mlir_python_extension name)
163163
if(NOT ARG_PYTHON_BINDINGS_LIBRARY)
164164
set(ARG_PYTHON_BINDINGS_LIBRARY "pybind11")
165165
endif()
166+
if(ARG_PYTHON_BINDINGS_LIBRARY STREQUAL "pybind11")
167+
set(ARG_GENERATE_TYPE_STUBS OFF)
168+
endif()
169+
if(NOT DEFINED ARG_GENERATE_TYPE_STUBS)
170+
set(ARG_GENERATE_TYPE_STUBS ON)
171+
endif()
166172

167173
add_library(${name} INTERFACE)
168174
set_target_properties(${name} PROPERTIES
169175
# Yes: Leading-lowercase property names are load bearing and the recommended
170176
# way to do this: https://gitlab.kitware.com/cmake/cmake/-/issues/19261
171-
EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_EXTENSION_MODULE_NAME;mlir_python_EMBED_CAPI_LINK_LIBS;mlir_python_DEPENDS;mlir_python_BINDINGS_LIBRARY"
177+
EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_EXTENSION_MODULE_NAME;mlir_python_EMBED_CAPI_LINK_LIBS;mlir_python_DEPENDS;mlir_python_BINDINGS_LIBRARY;mlir_python_GENERATE_TYPE_STUBS"
172178
mlir_python_SOURCES_TYPE extension
173179
mlir_python_EXTENSION_MODULE_NAME "${ARG_MODULE_NAME}"
174180
mlir_python_EMBED_CAPI_LINK_LIBS "${ARG_EMBED_CAPI_LINK_LIBS}"
175181
mlir_python_DEPENDS ""
176182
mlir_python_BINDINGS_LIBRARY "${ARG_PYTHON_BINDINGS_LIBRARY}"
183+
mlir_python_GENERATE_TYPE_STUBS "${ARG_GENERATE_TYPE_STUBS}"
177184
)
178185

179186
# Set the interface source and link_libs properties of the target
@@ -276,19 +283,22 @@ function(add_mlir_python_modules name)
276283
)
277284
add_dependencies(${modules_target} ${_extension_target})
278285
mlir_python_setup_extension_rpath(${_extension_target})
279-
generate_type_stubs(
280-
${_module_name}
281-
${_extension_target}
282-
"${modules_target}.extension._mlir.dso"
283-
"${CMAKE_CURRENT_SOURCE_DIR}/mlir/_mlir_libs/_mlir"
284-
)
285-
declare_mlir_python_sources(
286-
"${MLIR_PYTHON_PACKAGE_PREFIX}.${_module_name}_type_stub_gen"
287-
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
288-
ADD_TO_PARENT "${sources_target}"
289-
SOURCES_GLOB "_mlir_libs/${_module_name}/**/*.pyi"
290-
)
291-
add_dependencies("${modules_target}" "${NB_STUBGEN_CUSTOM_TARGET}")
286+
get_target_property(_generate_type_stubs ${sources_target} mlir_python_GENERATE_TYPE_STUBS)
287+
if(_generate_type_stubs)
288+
generate_type_stubs(
289+
${_module_name}
290+
${_extension_target}
291+
"${modules_target}.extension._mlir.dso"
292+
"${CMAKE_CURRENT_SOURCE_DIR}/mlir/_mlir_libs/_mlir"
293+
)
294+
declare_mlir_python_sources(
295+
"${MLIR_PYTHON_PACKAGE_PREFIX}.${_module_name}_type_stub_gen"
296+
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
297+
ADD_TO_PARENT "${sources_target}"
298+
SOURCES_GLOB "_mlir_libs/${_module_name}/**/*.pyi"
299+
)
300+
add_dependencies("${modules_target}" "${NB_STUBGEN_CUSTOM_TARGET}")
301+
endif()
292302
else()
293303
message(SEND_ERROR "Unrecognized source type '${_source_type}' for python source target ${sources_target}")
294304
return()

mlir/python/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
nanobind @ git+https://github.com/wjakob/nanobind
1+
nanobind>=2.4, <3.0
22
numpy>=1.19.5, <=2.1.2
33
pybind11>=2.10.0, <=2.13.6
44
PyYAML>=5.4.0, <=6.0.1
55
ml_dtypes>=0.1.0, <=0.6.0; python_version<"3.13" # provides several NumPy dtype extensions, including the bf16
66
ml_dtypes>=0.5.0, <=0.6.0; python_version>="3.13"
7+
typing_extensions

0 commit comments

Comments
 (0)