From b4cf3febd61952e49af37e8cf2f2a634a34c2677 Mon Sep 17 00:00:00 2001 From: chahatsagarmain Date: Mon, 27 Jan 2025 23:50:33 +0530 Subject: [PATCH] fix Signed-off-by: chahatsagarmain fix test Signed-off-by: chahatsagarmain fix test Signed-off-by: chahatsagarmain fix test Signed-off-by: chahatsagarmain allow class docstring Signed-off-by: chahatsagarmain test Signed-off-by: chahatsagarmain --- .github/workflows/kfp-sdk-tests.yml | 2 +- sdk/python/kfp/cli/utils/parsing.py | 42 ++++++++++++----------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/.github/workflows/kfp-sdk-tests.yml b/.github/workflows/kfp-sdk-tests.yml index 0fb6f85dae6..f432296c33d 100644 --- a/.github/workflows/kfp-sdk-tests.yml +++ b/.github/workflows/kfp-sdk-tests.yml @@ -24,7 +24,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python }} + python-version: ${{ matrix.python-version }} - name: Run SDK Tests run: | diff --git a/sdk/python/kfp/cli/utils/parsing.py b/sdk/python/kfp/cli/utils/parsing.py index 87be84b289a..245c61eaadc 100644 --- a/sdk/python/kfp/cli/utils/parsing.py +++ b/sdk/python/kfp/cli/utils/parsing.py @@ -25,9 +25,6 @@ def get_param_descr(fn: Callable, param_name: str) -> str: fn (Callable): The function of method with a __doc__ docstring implemented. param_name (str): The parameter for which to extract the description. - Raises: - ValueError: If docstring is not found or parameter is not found in docstring. - Returns: str: The description of the parameter. """ @@ -38,32 +35,27 @@ def get_param_descr(fn: Callable, param_name: str) -> str: f'Could not find parameter {param_name} in docstring of {fn}') lines = docstring.splitlines() - # collect all lines beginning after args, also get indentation space_chars + # Find Args section for i, line in enumerate(lines): if line.lstrip().startswith('Args:'): break + else: # No Args section found + raise ValueError(f'No Args section found in docstring of {fn}') lines = lines[i + 1:] - - first_already_found = False - return_lines = [] - - # allow but don't require type in docstring first_line_args_regex = rf'^{param_name}( \(.*\))?: ' - for line in lines: - if not first_already_found and re.match(first_line_args_regex, - line.lstrip()): - new_line = re.sub(first_line_args_regex, '', line.strip()) - return_lines.append(new_line) - first_already_found = True - first_indentation_level = len(line) - len(line.lstrip()) - continue - - if first_already_found: - indentation_level = len(line) - len(line.lstrip()) - if indentation_level <= first_indentation_level: - return ' '.join(return_lines) - else: - return_lines.append(line.strip()) + for i, line in enumerate(lines): + stripped = line.lstrip() + match = re.match(first_line_args_regex, stripped) + if match: + description = [re.sub(first_line_args_regex, '', stripped)] + # Collect any additional lines that are more indented + current_indent = len(line) - len(stripped) + for next_line in lines[i + 1:]: + next_indent = len(next_line) - len(next_line.lstrip()) + if next_indent <= current_indent: + break + description.append(next_line.strip()) + return ' '.join(description) raise ValueError( - f'Could not find parameter {param_name} in docstring of {fn}') + f'Could not find parameter {param_name} in docstring of {fn}') \ No newline at end of file