Skip to content

Commit aec86fe

Browse files
committed
Add more info in functions info
1 parent 269eeda commit aec86fe

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

singlestoredb/apps/_python_udfs.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ async def run_udf_app(
4141

4242
base_url = generate_base_url(app_config)
4343

44-
# something
45-
4644
udf_suffix = ''
4745
if app_config.running_interactively:
4846
udf_suffix = '_test'

singlestoredb/functions/ext/asgi.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,44 @@ def _locate_app_functions(self, cur: Any) -> Tuple[Set[str], Set[str]]:
12641264
links.add(link)
12651265
return funcs, links
12661266

1267+
def _extract_sample_usage(self, docstring: str) -> Optional[str]:
1268+
"""
1269+
Extract sample usage from docstring that starts with 'SAMPLE:'.
1270+
1271+
Parameters
1272+
----------
1273+
docstring : str
1274+
The function's docstring
1275+
1276+
Returns
1277+
-------
1278+
Optional[str]
1279+
The sample usage string if found, None otherwise
1280+
"""
1281+
if not docstring:
1282+
return None
1283+
1284+
lines = docstring.strip().split('\n')
1285+
sample_lines = []
1286+
in_sample_block = False
1287+
1288+
for line in lines:
1289+
stripped_line = line.strip()
1290+
prefix = 'SAMPLE:'
1291+
1292+
# Check if line starts with SAMPLE:
1293+
if stripped_line.startswith(prefix):
1294+
in_sample_block = True
1295+
# Extract the part after SAMPLE:
1296+
sample_content = stripped_line[len(prefix)].strip() # Remove 'SAMPLE:' prefix
1297+
if sample_content:
1298+
sample_lines.append(sample_content)
1299+
elif in_sample_block:
1300+
# Continue collecting lines until we hit an empty line or end
1301+
if not stripped_line:
1302+
break
1303+
sample_lines.append(stripped_line)
1304+
12671305
def _get_function_implementation(self, func: Callable[..., Any], func_name: str) -> Dict[str, Any]:
12681306
"""
12691307
Extract function implementation details.
@@ -1296,11 +1334,17 @@ def _get_function_implementation(self, func: Callable[..., Any], func_name: str)
12961334
# Get file and line info
12971335
source_file = inspect.getfile(func)
12981336
line_number = inspect.getsourcelines(func)[1]
1337+
1338+
# Extract docstring and sample usage
1339+
docstring = inspect.getdoc(func)
1340+
sample_usage = self._extract_sample_usage(docstring) if docstring else None
12991341

13001342
return {
13011343
'implementation': source,
13021344
'source_file': source_file,
13031345
'line_number': line_number,
1346+
'docstring': docstring,
1347+
'sample_usage': sample_usage,
13041348
}
13051349

13061350
except (OSError, TypeError) as e:
@@ -1309,6 +1353,8 @@ def _get_function_implementation(self, func: Callable[..., Any], func_name: str)
13091353
'implementation': f"# Source code not available for {func_name}\n# Reason: {str(e)}",
13101354
'source_file': getattr(func, '__module__', 'unknown'),
13111355
'line_number': None,
1356+
'docstring': None,
1357+
'sample_usage': None,
13121358
}
13131359

13141360
def get_function_info(

0 commit comments

Comments
 (0)