Skip to content

docs(python): add doctests to builder and config APIs, enable --doctest-modules#623

Open
GayathriSrividya wants to merge 1 commit into
apache:mainfrom
GayathriSrividya:docs/issue-82-python-doctests
Open

docs(python): add doctests to builder and config APIs, enable --doctest-modules#623
GayathriSrividya wants to merge 1 commit into
apache:mainfrom
GayathriSrividya:docs/issue-82-python-doctests

Conversation

@GayathriSrividya

@GayathriSrividya GayathriSrividya commented May 28, 2026

Copy link
Copy Markdown

Summary

Closes #82.

This PR implements the doctest setup designed by @xushiyan in the issue.

Sets up Python doctest infrastructure and adds runnable Examples: blocks to the public Python API. The blocking dependency (#141 — consolidate testing data modules) was resolved in release 0.5.0.

Changes

python/pyproject.toml

Add addopts = "--doctest-modules" to [tool.pytest.ini_options]. The hudi/ directory was already in testpaths; this flag activates doctest discovery so the examples in docstrings are collected and run as part of pytest.

python/hudi/table/builder.py

Add Examples: blocks to every public HudiTableBuilder method (as specified by @xushiyan — "guiding example to show users the most typical use cases of the APIs and actual test cases like other unit tests"):

Method What the doctest covers
from_base_uri Creates a builder; asserts base_uri, empty hudi_options, empty storage_options
with_hudi_option Adds a single Hudi key; asserts hudi_options dict
with_hudi_options Adds multiple Hudi keys at once; uses sorted() for determinism
with_storage_option Adds a single storage key; asserts storage_options dict
with_storage_options Adds multiple storage keys at once
with_option Adds a generic key to options
with_options Adds multiple generic keys
build Shows the full builder chain; uses # doctest: +SKIP since a real table path is required

python/hudi/_config.py

Add Examples: blocks to the three config enums, demonstrating how to read the canonical key string from an enum member:

>>> from hudi import HudiTableConfig
>>> HudiTableConfig.BASE_PATH.value
'hoodie.base.path'

Key values were verified against the Rust AsRef<str> implementations in crates/core/src/config/{table,read,plan}.rs.

…st-modules (apache#82)

- Add `addopts = "--doctest-modules"` to [tool.pytest.ini_options] in
  pyproject.toml so pytest auto-discovers doctests in the hudi/ package.

- Add runnable Examples: blocks to every public HudiTableBuilder method
  (from_base_uri, with_hudi_option, with_hudi_options, with_storage_option,
  with_storage_options, with_option, with_options). The build() example
  uses # doctest: +SKIP to avoid requiring a real table path.

- Add Examples: blocks to HudiTableConfig, HudiReadConfig, and
  HudiPlanConfig showing how to access the key string from each enum
  (e.g. HudiTableConfig.BASE_PATH.value == 'hoodie.base.path').

Closes apache#82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setup doc testing for Python APIs

1 participant