Skip to content

Commit 7fd60ae

Browse files
committed
Document how to generate stubs without docker
1 parent db8407f commit 7fd60ae

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

docs/quick_start/installation.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,19 @@ The workflow looks like this:
565565
Note that if you can't (or don't want to) build the stubs locally, you can
566566
download an artifact containing the wheel and `__init__.pyi` file from any job
567567
that fails the stub validation.
568+
569+
If you want to bypass the use of docker, you can use the following steps to
570+
build the python bindings and run the stub generator directly:
571+
572+
```
573+
python -m venv .venv
574+
. .venv/bin/activate
575+
mkdir build
576+
cd build
577+
cmake -DPython_EXECUTABLE=$(which python) -DCMAKE_INSTALL_PREFIX=../dist ..
578+
cmake --build . --target=install
579+
# extract the deps from the pyproject.toml and install them
580+
pip install $(yq -r '.tool.cibuildwheel.overrides.[0].test-requires' -oy ../pyproject.toml)
581+
PY_VER=$(python -c "import sys;print(f'{sys.version_info[0]}.{sys.version_info[1]}')")
582+
PYTHONPATH=../dist/lib/python$PY_VER/site-packages python ../src/bindings/python/stubs/generate_stubs.py --out-path ../src/bindings/python/stubs/
583+
```

src/bindings/python/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ install(TARGETS PyOpenColorIO
258258
LIBRARY DESTINATION ${_PyOpenColorIO_SITE_PACKAGE_DIR}
259259
)
260260

261+
install(FILES package/__init__.py DESTINATION ${_PyOpenColorIO_SITE_PACKAGE_DIR})
261262
install(FILES stubs/PyOpenColorIO/__init__.pyi DESTINATION ${_PyOpenColorIO_SITE_PACKAGE_DIR})
262263
install(FILES stubs/PyOpenColorIO/py.typed DESTINATION ${_PyOpenColorIO_SITE_PACKAGE_DIR})
263264

src/bindings/python/stubs/generate_stubs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Script to generate pyi stubs by patching and calling mypy's stubgen tool.
33
44
There are two entry-points which are designed to call this script:
5-
- `make pystubs` is called during local development to generate the
5+
- `cmake --build . --target pystubs` is called during local development to generate the
66
stubs and copy them into the git repo to be committed and reviewed.
77
- in CI, the cibuildwheel action is used to validate that the stubs match what
88
has been committed to the repo.
@@ -117,7 +117,6 @@ def main() -> None:
117117
parser = argparse.ArgumentParser()
118118
parser.add_argument(
119119
"--out-path",
120-
default="out",
121120
help="Directory to write the stubs."
122121
)
123122
parser.add_argument(
@@ -127,7 +126,10 @@ def main() -> None:
127126
"contents differ."
128127
)
129128
args = parser.parse_args()
130-
out_path = pathlib.Path(args.out_path)
129+
if not args.out_path:
130+
out_path = pathlib.Path(sys.modules[__name__].__file__).parent
131+
else:
132+
out_path = pathlib.Path(args.out_path)
131133
print(f"Stub output directory: {out_path}")
132134

133135
# perform import so we can see the traceback if it fails.

0 commit comments

Comments
 (0)