Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: chahatsagarmain <[email protected]>
  • Loading branch information
chahatsagarmain committed Jan 28, 2025
1 parent 9228f72 commit 2e5bcad
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions sdk/python/kfp/cli/utils/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

def get_param_descr(fn: Callable, param_name: str) -> str:
"""Extracts the description of a parameter from the docstring of a function
or method. Docstring must conform to Google Style.
or method. Docstring must conform to Google Style (https://sphinxcontrib-
napoleon.readthedocs.io/en/latest/example_google.html).
Args:
fn (Callable): The function of method with a __doc__ docstring implemented.
Expand All @@ -27,10 +28,7 @@ def get_param_descr(fn: Callable, param_name: str) -> str:
Returns:
str: The description of the parameter.
"""
if not isinstance(fn, type) and not callable(fn):
docstring = fn.__class__.__doc__
else:
docstring = fn.__doc__
docstring = fn.__doc__

if docstring is None:
raise ValueError(
Expand All @@ -49,19 +47,22 @@ def get_param_descr(fn: Callable, param_name: str) -> str:
# More lenient regex pattern
first_line_args_regex = rf'^\s*{param_name}\s*(?:\([^)]*\))?\s*:\s*'

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)
first_already_found = False
return_lines = []
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())
raise ValueError(
f'Could not find parameter {param_name} in docstring of {fn}')

0 comments on commit 2e5bcad

Please sign in to comment.