in google_cloud_automlops/utils/utils.py [0:0]
def get_function_source_definition(func: Callable) -> str:
"""Returns a formatted string of the source code.
Args:
func (Callable): The python function to create a component from. The function should have
type annotations for all its arguments, indicating how it is intended to be used (e.g.
as an input/output Artifact object, a plain parameter, or a path to a file).
Returns:
str: The source code from the inputted function.
Raises:
Exception: The preprocess operations failed.
"""
source_code = inspect.getsource(func)
source_code = textwrap.dedent(source_code)
source_code_lines = source_code.split('\n')
source_code_lines = itertools.dropwhile(lambda x: not x.startswith('def'),
source_code_lines)
if not source_code_lines:
raise ValueError(
f'Failed to dedent and clean up the source of function "{func.__name__}". '
f'It is probably not properly indented.')
return '\n'.join(source_code_lines)