MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / get_docstring

Function get_docstring

tools/sampcd_processor_utils.py:609–670  ·  view source on GitHub ↗

this function will get the docstring for test. Args: full_test, get all api filter_api, a function that filter api, if `True` then skip add to `docstrings_to_test`. apis, checking apis with ((line, api), (line, api), ...) like (("paddle.abs", "paddle.abs"), ("paddle

(
    full_test: bool = False,
    filter_api: typing.Callable[[str], bool] | None = None,
    apis: list[tuple[str, str]] | None = None,
)

Source from the content-addressed store, hash-verified

607
608
609def get_docstring(
610 full_test: bool = False,
611 filter_api: typing.Callable[[str], bool] | None = None,
612 apis: list[tuple[str, str]] | None = None,
613) -> tuple[dict[str, str], list[str]]:
614 '''
615 this function will get the docstring for test.
616
617 Args:
618 full_test, get all api
619 filter_api, a function that filter api, if `True` then skip add to `docstrings_to_test`.
620 apis, checking apis with ((line, api), (line, api), ...) like (("paddle.abs", "paddle.abs"), ("paddle.sin", "paddle.sin"), ...).
621 Do NOT use `full_test` and `apis` at the same time.
622 '''
623 import paddle
624 import paddle.static.quantization # noqa: F401
625
626 docstrings_to_test = {}
627 whl_error = []
628
629 if apis is None or not apis:
630 # get api from spec
631 if full_test:
632 get_full_api_from_pr_spec()
633 else:
634 get_incrementapi()
635
636 with open(API_DIFF_SPEC_FN) as f:
637 apis = [(line, line.replace('\n', '')) for line in f]
638
639 for line, api in apis:
640 if filter_api is not None and filter_api(api.strip()):
641 continue
642
643 try:
644 api_obj = eval(api)
645 except AttributeError:
646 whl_error.append(api)
647 continue
648 except SyntaxError:
649 logger.warning('line:%s, api:%s', line, api)
650 # paddle.Tensor.<lambda>
651 continue
652 if hasattr(api_obj, '__doc__') and api_obj.__doc__:
653 docstrings_to_test[api] = api_obj.__doc__
654
655 if len(docstrings_to_test) == 0 and len(whl_error) == 0:
656 logger.warning("-----API_PR.spec is the same as API_DEV.spec-----")
657 log_exit(0)
658
659 if len(docstrings_to_test) > 50:
660 logger.info("::group::API_PR is diff from API_DEV")
661 logger.info(docstrings_to_test.keys())
662 logger.info("::endgroup::")
663 else:
664 logger.info(
665 "API_PR is diff from API_DEV: %s", docstrings_to_test.keys()
666 )

Callers 2

run_type_checkerFunction · 0.90
run_doctestFunction · 0.70

Calls 8

get_incrementapiFunction · 0.85
evalFunction · 0.85
log_exitFunction · 0.85
replaceMethod · 0.45
appendMethod · 0.45
infoMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected