singlestoredb 1.15.0__cp38-abi3-win32.whl → 1.15.2__cp38-abi3-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of singlestoredb might be problematic. Click here for more details.
- _singlestoredb_accel.pyd +0 -0
- singlestoredb/__init__.py +1 -1
- singlestoredb/ai/chat.py +14 -0
- singlestoredb/apps/_python_udfs.py +18 -3
- singlestoredb/apps/_stdout_supress.py +1 -1
- singlestoredb/apps/_uvicorn_util.py +4 -0
- singlestoredb/config.py +24 -0
- singlestoredb/converters.py +1 -1
- singlestoredb/docstring/__init__.py +33 -0
- singlestoredb/docstring/attrdoc.py +126 -0
- singlestoredb/docstring/common.py +230 -0
- singlestoredb/docstring/epydoc.py +267 -0
- singlestoredb/docstring/google.py +412 -0
- singlestoredb/docstring/numpydoc.py +562 -0
- singlestoredb/docstring/parser.py +100 -0
- singlestoredb/docstring/py.typed +1 -0
- singlestoredb/docstring/rest.py +256 -0
- singlestoredb/docstring/tests/__init__.py +1 -0
- singlestoredb/docstring/tests/_pydoctor.py +21 -0
- singlestoredb/docstring/tests/test_epydoc.py +729 -0
- singlestoredb/docstring/tests/test_google.py +1007 -0
- singlestoredb/docstring/tests/test_numpydoc.py +1100 -0
- singlestoredb/docstring/tests/test_parse_from_object.py +109 -0
- singlestoredb/docstring/tests/test_parser.py +248 -0
- singlestoredb/docstring/tests/test_rest.py +547 -0
- singlestoredb/docstring/tests/test_util.py +70 -0
- singlestoredb/docstring/util.py +141 -0
- singlestoredb/functions/decorator.py +19 -18
- singlestoredb/functions/ext/asgi.py +304 -32
- singlestoredb/functions/ext/timer.py +2 -11
- singlestoredb/functions/ext/utils.py +55 -6
- singlestoredb/functions/signature.py +374 -241
- singlestoredb/fusion/handlers/files.py +4 -4
- singlestoredb/fusion/handlers/models.py +1 -1
- singlestoredb/fusion/handlers/stage.py +4 -4
- singlestoredb/management/cluster.py +1 -1
- singlestoredb/management/manager.py +15 -5
- singlestoredb/management/region.py +12 -2
- singlestoredb/management/workspace.py +17 -25
- singlestoredb/tests/ext_funcs/__init__.py +39 -0
- singlestoredb/tests/test_connection.py +18 -8
- singlestoredb/tests/test_management.py +24 -57
- singlestoredb/tests/test_udf.py +43 -15
- {singlestoredb-1.15.0.dist-info → singlestoredb-1.15.2.dist-info}/METADATA +1 -1
- {singlestoredb-1.15.0.dist-info → singlestoredb-1.15.2.dist-info}/RECORD +49 -30
- {singlestoredb-1.15.0.dist-info → singlestoredb-1.15.2.dist-info}/LICENSE +0 -0
- {singlestoredb-1.15.0.dist-info → singlestoredb-1.15.2.dist-info}/WHEEL +0 -0
- {singlestoredb-1.15.0.dist-info → singlestoredb-1.15.2.dist-info}/entry_points.txt +0 -0
- {singlestoredb-1.15.0.dist-info → singlestoredb-1.15.2.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"""Utility functions for working with docstrings."""
|
|
2
|
+
import typing as T
|
|
3
|
+
from collections import ChainMap
|
|
4
|
+
from inspect import Signature
|
|
5
|
+
from itertools import chain
|
|
6
|
+
|
|
7
|
+
from .common import DocstringMeta
|
|
8
|
+
from .common import DocstringParam
|
|
9
|
+
from .common import DocstringReturns # noqa: F401
|
|
10
|
+
from .common import DocstringStyle
|
|
11
|
+
from .common import RenderingStyle
|
|
12
|
+
from .parser import compose
|
|
13
|
+
from .parser import parse
|
|
14
|
+
|
|
15
|
+
_Func = T.Callable[..., T.Any]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def combine_docstrings(
|
|
19
|
+
*others: _Func,
|
|
20
|
+
exclude: T.Iterable[T.Type[DocstringMeta]] = (),
|
|
21
|
+
style: DocstringStyle = DocstringStyle.AUTO,
|
|
22
|
+
rendering_style: RenderingStyle = RenderingStyle.COMPACT,
|
|
23
|
+
) -> _Func:
|
|
24
|
+
"""A function decorator that parses the docstrings from `others`,
|
|
25
|
+
programmatically combines them with the parsed docstring of the decorated
|
|
26
|
+
function, and replaces the docstring of the decorated function with the
|
|
27
|
+
composed result. Only parameters that are part of the decorated functions
|
|
28
|
+
signature are included in the combined docstring. When multiple sources for
|
|
29
|
+
a parameter or docstring metadata exists then the decorator will first
|
|
30
|
+
default to the wrapped function's value (when available) and otherwise use
|
|
31
|
+
the rightmost definition from ``others``.
|
|
32
|
+
|
|
33
|
+
The following example illustrates its usage:
|
|
34
|
+
|
|
35
|
+
>>> def fun1(a, b, c, d):
|
|
36
|
+
... '''short_description: fun1
|
|
37
|
+
...
|
|
38
|
+
... :param a: fun1
|
|
39
|
+
... :param b: fun1
|
|
40
|
+
... :return: fun1
|
|
41
|
+
... '''
|
|
42
|
+
>>> def fun2(b, c, d, e):
|
|
43
|
+
... '''short_description: fun2
|
|
44
|
+
...
|
|
45
|
+
... long_description: fun2
|
|
46
|
+
...
|
|
47
|
+
... :param b: fun2
|
|
48
|
+
... :param c: fun2
|
|
49
|
+
... :param e: fun2
|
|
50
|
+
... '''
|
|
51
|
+
>>> @combine_docstrings(fun1, fun2)
|
|
52
|
+
>>> def decorated(a, b, c, d, e, f):
|
|
53
|
+
... '''
|
|
54
|
+
... :param e: decorated
|
|
55
|
+
... :param f: decorated
|
|
56
|
+
... '''
|
|
57
|
+
>>> print(decorated.__doc__)
|
|
58
|
+
short_description: fun2
|
|
59
|
+
<BLANKLINE>
|
|
60
|
+
long_description: fun2
|
|
61
|
+
<BLANKLINE>
|
|
62
|
+
:param a: fun1
|
|
63
|
+
:param b: fun1
|
|
64
|
+
:param c: fun2
|
|
65
|
+
:param e: fun2
|
|
66
|
+
:param f: decorated
|
|
67
|
+
:returns: fun1
|
|
68
|
+
>>> @combine_docstrings(fun1, fun2, exclude=[DocstringReturns])
|
|
69
|
+
>>> def decorated(a, b, c, d, e, f): pass
|
|
70
|
+
>>> print(decorated.__doc__)
|
|
71
|
+
short_description: fun2
|
|
72
|
+
<BLANKLINE>
|
|
73
|
+
long_description: fun2
|
|
74
|
+
<BLANKLINE>
|
|
75
|
+
:param a: fun1
|
|
76
|
+
:param b: fun1
|
|
77
|
+
:param c: fun2
|
|
78
|
+
:param e: fun2
|
|
79
|
+
|
|
80
|
+
:param others: callables from which to parse docstrings.
|
|
81
|
+
:param exclude: an iterable of ``DocstringMeta`` subclasses to exclude when
|
|
82
|
+
combining docstrings.
|
|
83
|
+
:param style: style composed docstring. The default will infer the style
|
|
84
|
+
from the decorated function.
|
|
85
|
+
:param rendering_style: The rendering style used to compose a docstring.
|
|
86
|
+
:return: the decorated function with a modified docstring.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
def wrapper(func: _Func) -> _Func:
|
|
90
|
+
sig = Signature.from_callable(func)
|
|
91
|
+
|
|
92
|
+
comb_doc = parse(func.__doc__ or '')
|
|
93
|
+
docs = [parse(other.__doc__ or '') for other in others] + [comb_doc]
|
|
94
|
+
params = dict(
|
|
95
|
+
ChainMap(
|
|
96
|
+
*(
|
|
97
|
+
{param.arg_name: param for param in doc.params}
|
|
98
|
+
for doc in docs
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
for doc in reversed(docs):
|
|
104
|
+
if not doc.short_description:
|
|
105
|
+
continue
|
|
106
|
+
comb_doc.short_description = doc.short_description
|
|
107
|
+
comb_doc.blank_after_short_description = (
|
|
108
|
+
doc.blank_after_short_description
|
|
109
|
+
)
|
|
110
|
+
break
|
|
111
|
+
|
|
112
|
+
for doc in reversed(docs):
|
|
113
|
+
if not doc.long_description:
|
|
114
|
+
continue
|
|
115
|
+
comb_doc.long_description = doc.long_description
|
|
116
|
+
comb_doc.blank_after_long_description = (
|
|
117
|
+
doc.blank_after_long_description
|
|
118
|
+
)
|
|
119
|
+
break
|
|
120
|
+
|
|
121
|
+
combined: T.Dict[T.Type[DocstringMeta], T.List[DocstringMeta]] = {}
|
|
122
|
+
for doc in docs:
|
|
123
|
+
metas: T.Dict[T.Type[DocstringMeta], T.List[DocstringMeta]] = {}
|
|
124
|
+
for meta in doc.meta:
|
|
125
|
+
meta_type = type(meta)
|
|
126
|
+
if meta_type in exclude:
|
|
127
|
+
continue
|
|
128
|
+
metas.setdefault(meta_type, []).append(meta)
|
|
129
|
+
for meta_type, meta_list in metas.items():
|
|
130
|
+
combined[meta_type] = meta_list
|
|
131
|
+
|
|
132
|
+
combined[DocstringParam] = [
|
|
133
|
+
params[name] for name in sig.parameters if name in params
|
|
134
|
+
]
|
|
135
|
+
comb_doc.meta = list(chain(*combined.values()))
|
|
136
|
+
func.__doc__ = compose(
|
|
137
|
+
comb_doc, style=style, rendering_style=rendering_style,
|
|
138
|
+
)
|
|
139
|
+
return func
|
|
140
|
+
|
|
141
|
+
return wrapper
|
|
@@ -45,23 +45,20 @@ def is_valid_type(obj: Any) -> bool:
|
|
|
45
45
|
return False
|
|
46
46
|
|
|
47
47
|
|
|
48
|
-
def
|
|
48
|
+
def is_sqlstr_callable(obj: Any) -> bool:
|
|
49
49
|
"""Check if the object is a valid callable for a parameter type."""
|
|
50
50
|
if not callable(obj):
|
|
51
51
|
return False
|
|
52
52
|
|
|
53
53
|
returns = utils.get_annotations(obj).get('return', None)
|
|
54
54
|
|
|
55
|
-
if inspect.isclass(returns) and issubclass(returns,
|
|
55
|
+
if inspect.isclass(returns) and issubclass(returns, SQLString):
|
|
56
56
|
return True
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
f'callable {obj} must return a str, '
|
|
60
|
-
f'but got {returns}',
|
|
61
|
-
)
|
|
58
|
+
return False
|
|
62
59
|
|
|
63
60
|
|
|
64
|
-
def expand_types(args: Any) -> Optional[
|
|
61
|
+
def expand_types(args: Any) -> Optional[List[Any]]:
|
|
65
62
|
"""Expand the types for the function arguments / return values."""
|
|
66
63
|
if args is None:
|
|
67
64
|
return None
|
|
@@ -70,28 +67,32 @@ def expand_types(args: Any) -> Optional[Union[List[str], Type[Any]]]:
|
|
|
70
67
|
if isinstance(args, str):
|
|
71
68
|
return [args]
|
|
72
69
|
|
|
73
|
-
# General way of accepting pydantic.BaseModel, NamedTuple, TypedDict
|
|
74
|
-
elif is_valid_type(args):
|
|
75
|
-
return args
|
|
76
|
-
|
|
77
70
|
# List of SQL strings or callables
|
|
78
71
|
elif isinstance(args, list):
|
|
79
|
-
new_args = []
|
|
72
|
+
new_args: List[Any] = []
|
|
80
73
|
for arg in args:
|
|
81
74
|
if isinstance(arg, str):
|
|
82
75
|
new_args.append(arg)
|
|
83
|
-
elif
|
|
76
|
+
elif is_sqlstr_callable(arg):
|
|
84
77
|
new_args.append(arg())
|
|
78
|
+
elif type(arg) is type:
|
|
79
|
+
new_args.append(arg)
|
|
80
|
+
elif is_valid_type(arg):
|
|
81
|
+
new_args.append(arg)
|
|
85
82
|
else:
|
|
86
83
|
raise TypeError(f'unrecognized type for parameter: {arg}')
|
|
87
84
|
return new_args
|
|
88
85
|
|
|
89
86
|
# Callable that returns a SQL string
|
|
90
|
-
elif
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
elif is_sqlstr_callable(args):
|
|
88
|
+
return [args()]
|
|
89
|
+
|
|
90
|
+
# General way of accepting pydantic.BaseModel, NamedTuple, TypedDict
|
|
91
|
+
elif is_valid_type(args):
|
|
92
|
+
return [args]
|
|
93
|
+
|
|
94
|
+
elif type(args) is type:
|
|
95
|
+
return [args]
|
|
95
96
|
|
|
96
97
|
raise TypeError(f'unrecognized type for parameter: {args}')
|
|
97
98
|
|