Skip to content

Commit

Permalink
Read function docstrings as descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-janidlo committed Nov 11, 2024
1 parent 2de8ef9 commit 36607d6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
New Functionality
^^^^^^^^^^^^^^^^^

- Function docstrings are now read and used as the description for the function when it
is uploaded. This will support future UI changes to the webapp.
3 changes: 3 additions & 0 deletions compute_sdk/globus_compute_sdk/sdk/web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
`FunctionRegistrationData` which can be constructed from an arbitrary callable.
"""

import inspect
import json
import typing as t
import warnings
Expand Down Expand Up @@ -62,6 +63,8 @@ def __init__(
)
function_name = function.__name__
function_code = _get_packed_code(function, serializer=serializer)
if description is None:
description = inspect.getdoc(function)

if function_name is None or function_code is None:
raise ValueError(
Expand Down
30 changes: 30 additions & 0 deletions compute_sdk/tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,36 @@ def test_register_function_deprecated_args(gcc, dep_arg):
assert dep_arg in str(warning)


def test_register_function_docstring(gcc):
gcc.web_client = mock.MagicMock()

def func_with_docstring():
"""This is a docstring"""
return "Funky"

gcc.register_function(func_with_docstring)

a, _ = gcc.web_client.register_function.call_args
func_data = a[0]
assert func_data.description == "This is a docstring"


def test_register_function_multiline_dosctring(gcc):
gcc.web_client = mock.MagicMock()

def func_with_multiline_docstring():
"""This is a docstring
that spans multiple lines
"""
return "Funky"

gcc.register_function(func_with_multiline_docstring)

a, _ = gcc.web_client.register_function.call_args
func_data = a[0]
assert func_data.description == "This is a docstring\nthat spans multiple lines"


def test_register_function_no_metadata(gcc):
gcc.web_client = mock.MagicMock()

Expand Down

0 comments on commit 36607d6

Please sign in to comment.