Skip to content

Commit e7cf64b

Browse files
committed
Use uv as a task runner
1 parent 579a5af commit e7cf64b

3 files changed

Lines changed: 53 additions & 26 deletions

File tree

.github/workflows/build-steps.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ jobs:
106106
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
107107
with:
108108
fetch-depth: '0'
109+
- name: Install uv
110+
uses: astral-sh/setup-uv@v5
111+
with:
112+
version: "0.6.13"
109113
- name: Prepare ccache timestamp
110114
id: ccache_cache_keys
111115
shell: bash

src/cmake/pythonutils.cmake

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,28 +161,48 @@ macro (setup_python_module)
161161
install(FILES __init__.py DESTINATION ${PYTHON_SITE_DIR} COMPONENT user)
162162

163163
# Create the __init__.pyi stub file
164-
165-
# Run stub generation process
166-
set(_stub_file "${CMAKE_BINARY_DIR}/lib/python/site-packages/OpenImageIO.pyi")
167-
# FIXME: is this the right location to use? the source gets copied to build/src
168-
set(_stub_gen "${CMAKE_SOURCE_DIR}/src/python/generate_stubs.py")
169-
add_custom_command(
170-
COMMAND pipx run ${_stub_gen} ${PYTHON_BUILD_SITE}
171-
OUTPUT ${_stub_file}
172-
DEPENDS ${_stub_gen}
173-
COMMENT "Creating python stubs"
174-
)
175-
install(FILES ${_stub_file} DESTINATION ${PYTHON_SITE_DIR} RENAME __init__.pyi COMPONENT user)
176-
# install the marker file
177-
file(WRITE "${CMAKE_BINARY_DIR}/lib/python/site-packages/py.typed" "")
178-
install(FILES "${CMAKE_BINARY_DIR}/lib/python/site-packages/py.typed" DESTINATION ${PYTHON_SITE_DIR} COMPONENT user)
179-
180-
# Ensure this runs after PyOpenImageIO
181-
add_custom_target(
182-
PyOpenImageIO_stubs ALL
183-
DEPENDS ${_stub_file} "${CMAKE_BINARY_DIR}/lib/python/site-packages/py.typed"
184-
)
185-
add_dependencies(PyOpenImageIO_stubs PyOpenImageIO)
164+
if (PYTHON_VERSION_FOUND VERSION_GREATER_EQUAL "3.9")
165+
# A modern version of python is required for the necessary version of mypy
166+
167+
# Run stub generation process
168+
set (_stub_file "${CMAKE_BINARY_DIR}/lib/python/site-packages/OpenImageIO.pyi")
169+
# FIXME: is this the right location to use? the source gets copied to build/src
170+
set (_stub_gen "${CMAKE_SOURCE_DIR}/src/python/generate_stubs.py")
171+
172+
find_program (UV_EXE NAMES uv uv.exe)
173+
174+
if (NOT UV_EXE)
175+
# add_custom_command (
176+
# COMMAND ${Python3_EXECUTABLE} -m venv "${PYTHON_VENV_DIR}"
177+
# COMMAND ${PYTHON_VENV_EXE} -m pip install uv
178+
# OUTPUT "${PYTHON_VENV_DIR}/bin/activate"
179+
# COMMENT "Creating virtualenv at ${PYTHON_VENV_DIR}"
180+
# )
181+
execute_process (
182+
COMMAND ${Python3_EXECUTABLE} -m venv "${PYTHON_VENV_DIR}"
183+
COMMAND ${PYTHON_VENV_EXE} -m pip install uv
184+
COMMAND_ERROR_IS_FATAL ANY
185+
)
186+
find_program (UV_EXE NAMES uv uv.exe)
187+
endif()
188+
189+
add_custom_command (
190+
COMMAND ${UV_EXE} run --python=${Python3_EXECUTABLE} ${_stub_gen} ${PYTHON_BUILD_SITE}
191+
OUTPUT ${_stub_file}
192+
DEPENDS ${_stub_gen}
193+
COMMENT "Creating python stubs")
194+
install (FILES ${_stub_file} DESTINATION ${PYTHON_SITE_DIR} RENAME __init__.pyi COMPONENT user)
195+
# install the marker file
196+
file (WRITE "${CMAKE_BINARY_DIR}/lib/python/site-packages/py.typed" "")
197+
install (FILES "${CMAKE_BINARY_DIR}/lib/python/site-packages/py.typed"
198+
DESTINATION ${PYTHON_SITE_DIR} COMPONENT user)
199+
200+
# Ensure this runs after PyOpenImageIO
201+
add_custom_target (
202+
PyOpenImageIO_stubs ALL
203+
DEPENDS ${_stub_file} "${CMAKE_BINARY_DIR}/lib/python/site-packages/py.typed")
204+
add_dependencies (PyOpenImageIO_stubs PyOpenImageIO)
205+
endif()
186206

187207
endmacro ()
188208

src/python/generate_stubs.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,22 @@ class OIIOSignatureGenerator(AdvancedSignatureGenerator):
6060
("*.ImageInput.open", "object"): "ImageInput | None",
6161

6262
# ("*.TextureSystem.imagespec", "object"): "ImageSpec | None",
63-
# ("*.ImageInput.read_native_deep_*", "object"): "DeepData | None",
6463

65-
# pybind11 has special support, so it may be possible to get it to emit these types
64+
# if you return an uninitialized unique_ptr to pybind11 it will convert to `None` (see #4685)
65+
("*.ImageInput.read_native_deep_*", "DeepData"): "DeepData | None",
66+
67+
# pybind11 has numpy support, so it may be possible to get it to emit these types
6668
# by using py::numpy in our wrapper code.
6769
("*.ImageInput.read_*", "object"): "numpy.ndarray | None",
6870
("*", "Buffer"): "numpy.ndarray",
6971
("*.get_pixels", "object"): "numpy.ndarray | None",
7072

71-
# For results, object is too restrictive (produces spurious errors during type analysis)
73+
# For results, `object` is too restrictive (produces spurious errors during type analysis)
7274
("*.getattribute", "object"): "Any",
7375
("*.ImageSpec.get", "object"): "Any",
7476

75-
# pybind11 does not have a way to emit tuple[T, ...], e.g. from std:vector<T>.
77+
# pybind11 treats std:vector<T> as list[T], but we want tuple[T, ...]
78+
# our custom code to convert vector to tuple obscures the contained type.
7679
("*.ImageBufAlgo.histogram", "tuple"): "tuple[int, ...]",
7780
("*.ImageBufAlgo.isConstantColor", "*"): "tuple[float, ...] | None",
7881
("*.ImageBufAlgo.color_range_check", "*"): "tuple[int, ...] | None",

0 commit comments

Comments
 (0)