@@ -144,7 +144,7 @@ macro (setup_python_module)
144144 set (PYTHON_SITE_DIR .)
145145 endif ()
146146
147- set (PYTHON_BUILD_SITE "${CMAKE_BINARY_DIR} /lib/python/site-packages" )
147+ set (PYTHON_BUILD_SITE "${CMAKE_BINARY_DIR} /lib/python/site-packages/OpenImageIO " )
148148
149149 # In the build area, put it in lib/python so it doesn't clash with the
150150 # non-python libraries of the same name (which aren't prefixed by "lib"
@@ -164,8 +164,12 @@ macro (setup_python_module)
164164 if (PYTHON_VERSION_FOUND VERSION_GREATER_EQUAL "3.10" )
165165 # A modern version of python is required for the necessary version of mypy
166166
167+ # copy the __init__.py file so that the package is importable on all platforms
168+ file (COPY __init__.py DESTINATION ${PYTHON_BUILD_SITE} )
169+ # write the marker file
170+ file (WRITE "${PYTHON_BUILD_SITE} /py.typed" "" )
171+
167172 # Run stub generation process
168- set (_stub_file "${CMAKE_BINARY_DIR} /lib/python/site-packages/OpenImageIO.pyi" )
169173 # FIXME: is this the right location to use? the source gets copied to build/src
170174 set (_stub_gen "${CMAKE_SOURCE_DIR} /src/python/generate_stubs.py" )
171175
@@ -191,20 +195,18 @@ macro (setup_python_module)
191195 # endif()
192196
193197 add_custom_command (
194- COMMAND uv run ${ _stub_gen} ${PYTHON_BUILD_SITE}
195- OUTPUT ${_stub_file}
196- DEPENDS ${_stub_gen}
198+ COMMAND uv run --python=${Python3_EXECUTABLE} ${ _stub_gen} " ${CMAKE_BINARY_DIR} /lib/python/site-packages"
199+ OUTPUT " ${PYTHON_BUILD_SITE} /__init__.pyi"
200+ DEPENDS ${_stub_gen} " ${PYTHON_BUILD_SITE} /__init__.py"
197201 COMMENT "Creating python stubs" )
198- install (FILES ${_stub_file} DESTINATION ${PYTHON_SITE_DIR} RENAME __init__.pyi COMPONENT user)
199- # install the marker file
200- file (WRITE "${CMAKE_BINARY_DIR} /lib/python/site-packages/py.typed" "" )
201- install (FILES "${CMAKE_BINARY_DIR} /lib/python/site-packages/py.typed"
202- DESTINATION ${PYTHON_SITE_DIR} COMPONENT user)
202+
203+ install (FILES "${PYTHON_BUILD_SITE} /__init__.pyi" DESTINATION ${PYTHON_SITE_DIR} COMPONENT user)
204+ install (FILES "${PYTHON_BUILD_SITE} /py.typed" DESTINATION ${PYTHON_SITE_DIR} COMPONENT user)
203205
204206 # Ensure this runs after PyOpenImageIO
205207 add_custom_target (
206208 PyOpenImageIO_stubs ALL
207- DEPENDS ${_stub_file} "${CMAKE_BINARY_DIR} /lib/python/site-packages /py.typed" )
209+ DEPENDS " ${PYTHON_BUILD_SITE} /__init__.pyi" "${PYTHON_BUILD_SITE} /py.typed" )
208210 add_dependencies (PyOpenImageIO_stubs PyOpenImageIO )
209211 endif ()
210212
0 commit comments