Skip to content

Commit 81000b4

Browse files
committed
Improve documentation
1 parent 7fd60ae commit 81000b4

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

docs/quick_start/installation.rst

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -547,37 +547,40 @@ in a single pull request, so that regressions are not unwittingly introduced.
547547

548548
The workflow looks like this:
549549

550-
- Install [`uv`](https://docs.astral.sh/uv/getting-started/installation/) and
551-
`docker`
550+
- Install `uv <https://docs.astral.sh/uv/getting-started/installation/>`_ and
551+
``docker``
552552
- Create the temp build directory, cd into it, and run `cmake /path/to/source`
553-
- Run `cmake --build . --target pystubs` to generate updated stubs in
554-
`src/bindings/python/stubs/__init__.pyi`
553+
- Run ``cmake --build . --target pystubs`` to generate updated stubs in
554+
``src/bindings/python/stubs/__init__.pyi``
555555
- Commit the new stubs and push to Github
556-
- In CI, the stubs will be included in the wheels built by `cibuildwheel`, as
557-
defined in `.github/workflows/wheel_workflow.yml`
558-
- In CI, one of the `cibuildwheel` Github actions will rebuild the stubs to a
556+
- In CI, the stubs will be included in the wheels built by ``cibuildwheel``, as
557+
defined in ``.github/workflows/wheel_workflow.yml``
558+
- In CI, one of the ``cibuildwheel`` Github actions will rebuild the stubs to a
559559
temp location and verify that they match what has been committed to the repo.
560560
This step ensures that if changes to the C++ source code and bindings results
561561
in a change to the stubs, developers are notified of the need to regenerate
562-
the stubs, so that changes can be reviewed and the rules in `generate_stubs.py`
562+
the stubs, so that changes can be reviewed and the rules in ``generate_stubs.py``
563563
can be updated, if necessary.
564564

565-
Note that if you can't (or don't want to) build the stubs locally, you can
566-
download an artifact containing the wheel and `__init__.pyi` file from any job
567-
that fails the stub validation.
568-
569565
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-
```
566+
build the python bindings and run the stub generator directly (requires python
567+
3.11+):
568+
569+
.. code-block:: bash
570+
571+
python -m venv .venv
572+
. .venv/bin/activate
573+
mkdir build
574+
cd build
575+
cmake -DPython_EXECUTABLE=$(which python) -DCMAKE_INSTALL_PREFIX=../dist ..
576+
cmake --build . --target=install
577+
# extract the deps from the pyproject.toml and install them into the virtualenv
578+
PY_DEPS=$(python -c "import tomllib;print(tomllib.load(open('../pyproject.toml', 'rb'))['tool']['cibuildwheel']['overrides'][0]['test-requires'])")
579+
pip install ${PY_DEPS}
580+
PY_VER=$(python -c "import sys;print(f'{sys.version_info[0]}.{sys.version_info[1]}')")
581+
# generate stubs
582+
PYTHONPATH=../dist/lib/python$PY_VER/site-packages python ../src/bindings/python/stubs/generate_stubs.py
583+
584+
If all else fails and you can't build the stubs locally, you can push changes
585+
to CI and download an artifact containing the wheel and ``__init__.pyi`` file from
586+
any job that fails the stub validation.

src/bindings/python/stubs/generate_stubs.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,31 @@
2929

3030
class OCIOSignatureGenerator(AdvancedSignatureGenerator):
3131
sig_matcher = AdvancedSigMatcher(
32+
# Override entire function signature:
3233
signature_overrides={
3334
# signatures for these special methods include many inaccurate overloads
3435
"*.__ne__": "(self, other: object) -> bool",
3536
"*.__eq__": "(self, other: object) -> bool",
3637
},
38+
# Override argument types
3739
arg_type_overrides={
40+
# (name_pattern, arg, type): arg_type
41+
# type can be str | re.Pattern
3842
("*", "*", re.compile(r"list\[(.*)]")): r"Iterable[\1]",
3943
},
44+
# Override result types
45+
# dict of (name_pattern, type) to result_type
46+
# e.g. ("*", "Buffer"): "numpy.ndarray"
47+
result_type_overrides={},
48+
# Override property types
49+
# dict of (name_pattern, type) to result_type
50+
# e.g. ("*", "Buffer"): "numpy.ndarray"
51+
property_type_overrides={},
52+
# Types that have implicit alternatives.
53+
# dict of type_str to list of types that can be used instead
54+
# e.g. "PySide2.QtGui.QKeySequence": ["str"],
55+
# converts any matching argument to a union of the supported types
56+
implicit_arg_types={},
4057
)
4158

4259
def process_sig(

0 commit comments

Comments
 (0)