Skip to content

Commit 12cdb09

Browse files
AlenkaFtadeja
andauthored
GH-28859: [Doc][Python] Use only code-block directive and set up doctest for the python user guide (#48619)
### Rationale for this change In many places in the Python User Guide the code exampels are written with IPython directive (elsewhere code-block is used). IPython directives are converted to IPython format (`In` and `Out` during the doc build). This can lead to slower builds. ### What changes are included in this PR? IPython directives are converted to runnable code-block (with `>>>` and `...`) and pytest doctest support for `.rst` files is added to the `conda-python-docs` CI job. This means the code in the Python User Guide is tested separately to the building of the documentation. ### Are these changes tested? Yes, with the CI. ### Are there any user-facing changes? Changes to the Python User Guide examples will have to be tested with `pytest --doctest-glob='*.rst' docs/source/python/file.rst` * GitHub Issue: #28859 Lead-authored-by: AlenkaF <frim.alenka@gmail.com> Co-authored-by: Alenka Frim <AlenkaF@users.noreply.github.com> Co-authored-by: tadeja <tadeja@users.noreply.github.com> Signed-off-by: AlenkaF <frim.alenka@gmail.com>
1 parent d510b10 commit 12cdb09

24 files changed

Lines changed: 2301 additions & 1495 deletions

ci/scripts/python_test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@ export PYARROW_TEST_S3
7070

7171
# Testing PyArrow
7272
pytest -r s ${PYTEST_ARGS} --pyargs pyarrow
73+
74+
# Testing RST documentation examples (if PYTEST_RST_ARGS is set)
75+
if [ -n "${PYTEST_RST_ARGS}" ]; then
76+
pytest ${PYTEST_RST_ARGS} ${arrow_dir}/docs/source/python
77+
fi

compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,7 @@ services:
15301530
BUILD_DOCS_CPP: "ON"
15311531
BUILD_DOCS_PYTHON: "ON"
15321532
PYTEST_ARGS: "--doctest-modules --doctest-cython"
1533+
PYTEST_RST_ARGS: "--doctest-glob=*.rst"
15331534
volumes: *conda-volumes
15341535
command:
15351536
["/arrow/ci/scripts/cpp_build.sh /arrow /build &&

docs/source/developers/python/development.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,24 @@ for ``.py`` files or
127127
for ``.pyx`` and ``.pxi`` files. In this case you will also need to
128128
install the `pytest-cython <https://github.com/lgpage/pytest-cython>`_ plugin.
129129

130+
Testing Documentation Examples
131+
-------------------------------
132+
133+
Documentation examples in ``.rst`` files under ``docs/source/python/`` use
134+
doctest syntax and can be tested locally using:
135+
136+
.. code-block::
137+
138+
$ pushd arrow/python
139+
$ pytest --doctest-glob="*.rst" docs/source/python/file.rst # checking single file
140+
$ pytest --doctest-glob="*.rst" docs/source/python # checking entire directory
141+
$ popd
142+
143+
The examples use standard doctest syntax with ``>>>`` for Python prompts and
144+
``...`` for continuation lines. The ``conftest.py`` fixture automatically
145+
handles temporary directory setup for examples that create files.
146+
147+
130148
Debugging
131149
=========
132150

0 commit comments

Comments
 (0)