toolslm 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.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.
- toolslm/__init__.py +1 -1
- toolslm/funccall.py +14 -10
- {toolslm-0.1.2.dist-info → toolslm-0.1.3.dist-info}/METADATA +1 -1
- toolslm-0.1.3.dist-info/RECORD +13 -0
- toolslm-0.1.2.dist-info/RECORD +0 -13
- {toolslm-0.1.2.dist-info → toolslm-0.1.3.dist-info}/WHEEL +0 -0
- {toolslm-0.1.2.dist-info → toolslm-0.1.3.dist-info}/entry_points.txt +0 -0
- {toolslm-0.1.2.dist-info → toolslm-0.1.3.dist-info}/licenses/LICENSE +0 -0
- {toolslm-0.1.2.dist-info → toolslm-0.1.3.dist-info}/top_level.txt +0 -0
toolslm/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.3"
|
toolslm/funccall.py
CHANGED
|
@@ -141,7 +141,7 @@ def _copy_loc(new, orig):
|
|
|
141
141
|
return new
|
|
142
142
|
|
|
143
143
|
# %% ../01_funccall.ipynb 69
|
|
144
|
-
def _run(code:str ):
|
|
144
|
+
def _run(code:str, glb:dict=None, loc:dict=None):
|
|
145
145
|
"Run `code`, returning final expression (similar to IPython)"
|
|
146
146
|
tree = ast.parse(code)
|
|
147
147
|
last_node = tree.body[-1] if tree.body else None
|
|
@@ -153,30 +153,34 @@ def _run(code:str ):
|
|
|
153
153
|
tree.body[-1] = _copy_loc(assign_node, last_node)
|
|
154
154
|
|
|
155
155
|
compiled_code = compile(tree, filename='<ast>', mode='exec')
|
|
156
|
-
|
|
156
|
+
glb = glb or {}
|
|
157
157
|
stdout_buffer = io.StringIO()
|
|
158
158
|
saved_stdout = sys.stdout
|
|
159
159
|
sys.stdout = stdout_buffer
|
|
160
|
-
try: exec(compiled_code,
|
|
160
|
+
try: exec(compiled_code, glb, loc)
|
|
161
161
|
finally: sys.stdout = saved_stdout
|
|
162
|
-
_result =
|
|
162
|
+
_result = glb.get('_result', None)
|
|
163
163
|
if _result is not None: return _result
|
|
164
164
|
return stdout_buffer.getvalue().strip()
|
|
165
165
|
|
|
166
166
|
# %% ../01_funccall.ipynb 74
|
|
167
|
-
def python(code, # Code to execute
|
|
168
|
-
|
|
167
|
+
def python(code:str, # Code to execute
|
|
168
|
+
glb:Optional[dict]=None, # Globals namespace
|
|
169
|
+
loc:Optional[dict]=None, # Locals namespace
|
|
170
|
+
timeout:int=3600 # Maximum run time in seconds before a `TimeoutError` is raised
|
|
169
171
|
): # Result of last node, if it's an expression, or `None` otherwise
|
|
170
172
|
"""Executes python `code` with `timeout` and returning final expression (similar to IPython).
|
|
171
173
|
Raised exceptions are returned as a string, with a stack trace."""
|
|
172
174
|
def handler(*args): raise TimeoutError()
|
|
175
|
+
if glb is None: glb = inspect.currentframe().f_back.f_globals
|
|
176
|
+
if loc is None: loc=glb
|
|
173
177
|
signal.signal(signal.SIGALRM, handler)
|
|
174
178
|
signal.alarm(timeout)
|
|
175
|
-
try: return _run(code)
|
|
179
|
+
try: return _run(code, glb, loc)
|
|
176
180
|
except Exception as e: return traceback.format_exc()
|
|
177
181
|
finally: signal.alarm(0)
|
|
178
182
|
|
|
179
|
-
# %% ../01_funccall.ipynb
|
|
183
|
+
# %% ../01_funccall.ipynb 85
|
|
180
184
|
def mk_ns(*funcs_or_objs):
|
|
181
185
|
merged = {}
|
|
182
186
|
for o in funcs_or_objs:
|
|
@@ -185,14 +189,14 @@ def mk_ns(*funcs_or_objs):
|
|
|
185
189
|
if callable(o) and hasattr(o, '__name__'): merged |= {o.__name__: o}
|
|
186
190
|
return merged
|
|
187
191
|
|
|
188
|
-
# %% ../01_funccall.ipynb
|
|
192
|
+
# %% ../01_funccall.ipynb 94
|
|
189
193
|
def call_func(fc_name, fc_inputs, ns):
|
|
190
194
|
"Call the function `fc_name` with the given `fc_inputs` using namespace `ns`."
|
|
191
195
|
if not isinstance(ns, abc.Mapping): ns = mk_ns(*ns)
|
|
192
196
|
func = ns[fc_name]
|
|
193
197
|
return func(**fc_inputs)
|
|
194
198
|
|
|
195
|
-
# %% ../01_funccall.ipynb
|
|
199
|
+
# %% ../01_funccall.ipynb 101
|
|
196
200
|
async def call_func_async(fc_name, fc_inputs, ns):
|
|
197
201
|
"Awaits the function `fc_name` with the given `fc_inputs` using namespace `ns`."
|
|
198
202
|
if not isinstance(ns, abc.Mapping): ns = mk_ns(*ns)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
toolslm/__init__.py,sha256=XEqb2aiIn8fzGE68Mph4ck1FtQqsR_am0wRWvrYPffQ,22
|
|
2
|
+
toolslm/_modidx.py,sha256=-D-B5o30VGs11gBKf96lpADVXnZhdiVEshJpLzmUnDs,4378
|
|
3
|
+
toolslm/download.py,sha256=d84O8PCX7uAbLg0HTbNNfCdANPcnhXFu4qzOtcfJfHU,4465
|
|
4
|
+
toolslm/funccall.py,sha256=bzVlcTpgQuuBIG-I1HRidnXV5mp0FfGV10_Mk1DSQuc,8460
|
|
5
|
+
toolslm/md_hier.py,sha256=4uC12443tPBduYJgIZZIcEat2VG0x7JYC8-SwDdS2JY,6360
|
|
6
|
+
toolslm/shell.py,sha256=GVqfL74NHw66zzZ7jvGVLjE55ZNJGBPvEb8kLz4aoYc,1576
|
|
7
|
+
toolslm/xml.py,sha256=QNwUavoMkFK84D7dMwnBjqlYJwN-pJ7u3BxOeDuNAmk,4088
|
|
8
|
+
toolslm-0.1.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
+
toolslm-0.1.3.dist-info/METADATA,sha256=8MXaP61NyBqYuRyFe3IC49I0TYcZdZHniN17MJWHxB0,2483
|
|
10
|
+
toolslm-0.1.3.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
11
|
+
toolslm-0.1.3.dist-info/entry_points.txt,sha256=xFz0Eymlo5X7BGpaO6DI9gMxvN5A7faebzrlr8ctp5I,95
|
|
12
|
+
toolslm-0.1.3.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
13
|
+
toolslm-0.1.3.dist-info/RECORD,,
|
toolslm-0.1.2.dist-info/RECORD
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
toolslm/__init__.py,sha256=YvuYzWnKtqBb-IqG8HAu-nhIYAsgj9Vmc_b9o7vO-js,22
|
|
2
|
-
toolslm/_modidx.py,sha256=-D-B5o30VGs11gBKf96lpADVXnZhdiVEshJpLzmUnDs,4378
|
|
3
|
-
toolslm/download.py,sha256=d84O8PCX7uAbLg0HTbNNfCdANPcnhXFu4qzOtcfJfHU,4465
|
|
4
|
-
toolslm/funccall.py,sha256=yAZmu2gIRtND-5pOuLCp7P4dor0FV_xntcacnZ81j0M,8210
|
|
5
|
-
toolslm/md_hier.py,sha256=4uC12443tPBduYJgIZZIcEat2VG0x7JYC8-SwDdS2JY,6360
|
|
6
|
-
toolslm/shell.py,sha256=GVqfL74NHw66zzZ7jvGVLjE55ZNJGBPvEb8kLz4aoYc,1576
|
|
7
|
-
toolslm/xml.py,sha256=QNwUavoMkFK84D7dMwnBjqlYJwN-pJ7u3BxOeDuNAmk,4088
|
|
8
|
-
toolslm-0.1.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
9
|
-
toolslm-0.1.2.dist-info/METADATA,sha256=gGurWuj5SWNPQvCPKbd8oc5Iz9x4NPxv8bx_C8w3Kps,2483
|
|
10
|
-
toolslm-0.1.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
11
|
-
toolslm-0.1.2.dist-info/entry_points.txt,sha256=xFz0Eymlo5X7BGpaO6DI9gMxvN5A7faebzrlr8ctp5I,95
|
|
12
|
-
toolslm-0.1.2.dist-info/top_level.txt,sha256=4hRTrFWayz_Kz5221XjvlpCwVFrW3WPi1P0fllkTq9s,8
|
|
13
|
-
toolslm-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|