ipykernel-helper 0.0.1__py3-none-any.whl → 0.0.2__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.
Potentially problematic release.
This version of ipykernel-helper might be problematic. Click here for more details.
- ipykernel_helper/__init__.py +1 -1
- ipykernel_helper/_modidx.py +10 -1
- ipykernel_helper/core.py +87 -6
- {ipykernel_helper-0.0.1.dist-info → ipykernel_helper-0.0.2.dist-info}/METADATA +2 -1
- ipykernel_helper-0.0.2.dist-info/RECORD +9 -0
- {ipykernel_helper-0.0.1.dist-info → ipykernel_helper-0.0.2.dist-info}/WHEEL +1 -1
- ipykernel_helper-0.0.1.dist-info/RECORD +0 -9
- {ipykernel_helper-0.0.1.dist-info → ipykernel_helper-0.0.2.dist-info}/entry_points.txt +0 -0
- {ipykernel_helper-0.0.1.dist-info → ipykernel_helper-0.0.2.dist-info}/licenses/LICENSE +0 -0
- {ipykernel_helper-0.0.1.dist-info → ipykernel_helper-0.0.2.dist-info}/top_level.txt +0 -0
ipykernel_helper/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
__version__ = "0.0.
|
|
1
|
+
__version__ = "0.0.2"
|
|
2
2
|
from .core import *
|
ipykernel_helper/_modidx.py
CHANGED
|
@@ -5,5 +5,14 @@ d = { 'settings': { 'branch': 'main',
|
|
|
5
5
|
'doc_host': 'https://AnswerDotAI.github.io',
|
|
6
6
|
'git_url': 'https://github.com/AnswerDotAI/ipykernel-helper',
|
|
7
7
|
'lib_path': 'ipykernel_helper'},
|
|
8
|
-
'syms': { 'ipykernel_helper.core': { 'ipykernel_helper.core.
|
|
8
|
+
'syms': { 'ipykernel_helper.core': { 'ipykernel_helper.core.AsyncKernelClient.interactive': ( 'core.html#asynckernelclient.interactive',
|
|
9
|
+
'ipykernel_helper/core.py'),
|
|
10
|
+
'ipykernel_helper.core._get_schema': ('core.html#_get_schema', 'ipykernel_helper/core.py'),
|
|
11
|
+
'ipykernel_helper.core._rank': ('core.html#_rank', 'ipykernel_helper/core.py'),
|
|
12
|
+
'ipykernel_helper.core._signatures': ('core.html#_signatures', 'ipykernel_helper/core.py'),
|
|
13
|
+
'ipykernel_helper.core.get_schemas': ('core.html#get_schemas', 'ipykernel_helper/core.py'),
|
|
14
|
+
'ipykernel_helper.core.get_vars': ('core.html#get_vars', 'ipykernel_helper/core.py'),
|
|
15
|
+
'ipykernel_helper.core.ranked_complete': ('core.html#ranked_complete', 'ipykernel_helper/core.py'),
|
|
16
|
+
'ipykernel_helper.core.safe_repr': ('core.html#safe_repr', 'ipykernel_helper/core.py'),
|
|
17
|
+
'ipykernel_helper.core.sig_help': ('core.html#sig_help', 'ipykernel_helper/core.py'),
|
|
9
18
|
'ipykernel_helper.core.user_items': ('core.html#user_items', 'ipykernel_helper/core.py')}}}
|
ipykernel_helper/core.py
CHANGED
|
@@ -3,12 +3,23 @@
|
|
|
3
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
|
|
4
4
|
|
|
5
5
|
# %% auto 0
|
|
6
|
-
__all__ = ['safe_repr', 'user_items']
|
|
6
|
+
__all__ = ['safe_repr', 'user_items', 'ranked_complete', 'sig_help', 'get_vars', 'get_schemas']
|
|
7
7
|
|
|
8
8
|
# %% ../nbs/00_core.ipynb
|
|
9
|
-
import
|
|
9
|
+
from fastcore.meta import delegates
|
|
10
|
+
from fastcore.utils import patch,dict2obj
|
|
11
|
+
import typing,warnings
|
|
10
12
|
from types import ModuleType, FunctionType, MethodType, BuiltinFunctionType
|
|
11
|
-
from inspect import signature
|
|
13
|
+
from inspect import signature, currentframe
|
|
14
|
+
from functools import cmp_to_key,partial
|
|
15
|
+
from toolslm.funccall import *
|
|
16
|
+
|
|
17
|
+
from jupyter_client import AsyncKernelClient
|
|
18
|
+
from IPython.core.completer import ProvisionalCompleterWarning
|
|
19
|
+
from jedi import Interpreter, Script as jscript
|
|
20
|
+
|
|
21
|
+
# %% ../nbs/00_core.ipynb
|
|
22
|
+
warnings.filterwarnings('ignore', category=ProvisionalCompleterWarning)
|
|
12
23
|
|
|
13
24
|
# %% ../nbs/00_core.ipynb
|
|
14
25
|
def safe_repr(obj, max_len=200):
|
|
@@ -19,8 +30,9 @@ def safe_repr(obj, max_len=200):
|
|
|
19
30
|
except Exception as e: return f"<repr error: {str(e)}>"
|
|
20
31
|
|
|
21
32
|
# %% ../nbs/00_core.ipynb
|
|
22
|
-
def user_items(ns, max_len=200, xtra_skip=()):
|
|
33
|
+
def user_items(ns=None, max_len=200, xtra_skip=()):
|
|
23
34
|
"Get user-defined vars & funcs from namespace."
|
|
35
|
+
if ns is None: ns = currentframe().f_back.f_globals
|
|
24
36
|
ignore = {'In', 'Out', 'exit', 'quit', 'open', 'nbmeta', 'receive_nbmeta'}
|
|
25
37
|
ignore.add(xtra_skip)
|
|
26
38
|
rm_types = (
|
|
@@ -29,8 +41,77 @@ def user_items(ns, max_len=200, xtra_skip=()):
|
|
|
29
41
|
getattr(typing, '_GenericAlias', ()),
|
|
30
42
|
getattr(typing, '_SpecialForm', ())
|
|
31
43
|
)
|
|
32
|
-
user_items = {k:
|
|
33
|
-
|
|
44
|
+
user_items = {k:v for k, v in ns.items()
|
|
45
|
+
if not k in ignore}
|
|
46
|
+
user_vars = {k:safe_repr(v, max_len=max_len)
|
|
47
|
+
for k, v in user_items.items() if not k.startswith('_') and not isinstance(v, rm_types)}
|
|
34
48
|
user_fns = {k:str(signature(v)) for k, v in user_items.items()
|
|
35
49
|
if isinstance(v, FunctionType) and v.__module__ == '__main__' and not k.startswith('__')}
|
|
36
50
|
return user_vars,user_fns
|
|
51
|
+
|
|
52
|
+
# %% ../nbs/00_core.ipynb
|
|
53
|
+
@patch
|
|
54
|
+
@delegates(AsyncKernelClient.execute_interactive)
|
|
55
|
+
async def interactive(self:AsyncKernelClient, code:str, **kwargs):
|
|
56
|
+
"Like AsyncKernelClient.execute_interactive, but also returns outputs"
|
|
57
|
+
outputs = []
|
|
58
|
+
def _h(msg: dict): outputs.append(msg)
|
|
59
|
+
res = await self.execute_interactive(code, output_hook=_h, **kwargs)
|
|
60
|
+
return res,outputs
|
|
61
|
+
|
|
62
|
+
# %% ../nbs/00_core.ipynb
|
|
63
|
+
def _rank(c, s):
|
|
64
|
+
"Rank a completion `c` for text `s` with namespace `ns`."
|
|
65
|
+
parts = s.split('.')
|
|
66
|
+
is_public = not c.text.startswith('_')
|
|
67
|
+
if c.type=='param': r=1
|
|
68
|
+
elif c.mod=='__main__': r=2 # local
|
|
69
|
+
elif len(parts)>1 and parts[0]==c.mod: r=3 # module
|
|
70
|
+
elif c.mod=='builtins': r=4
|
|
71
|
+
else: r=5
|
|
72
|
+
return r if is_public else r+0.1
|
|
73
|
+
|
|
74
|
+
# %% ../nbs/00_core.ipynb
|
|
75
|
+
def ranked_complete(code, line_no=None, col_no=None):
|
|
76
|
+
ipy = get_ipython()
|
|
77
|
+
lines = code.splitlines(True)
|
|
78
|
+
if line_no: offset = sum(len(lines[i]) for i in range(line_no-1)) + col_no -1
|
|
79
|
+
else: offset = len(code)
|
|
80
|
+
cs = ipy.Completer.completions(code, offset)
|
|
81
|
+
def _c(a):
|
|
82
|
+
res = dict2obj({attr: getattr(a, attr) for attr in dir(a) if attr[0]!='_'})
|
|
83
|
+
res['mod']= getattr(ipy.user_ns.get(a.text, None), '__module__', None)
|
|
84
|
+
res['rank'] = _rank(res, s=code)
|
|
85
|
+
return res
|
|
86
|
+
return [_c(c) for c in cs if not c.text.startswith('__')]
|
|
87
|
+
|
|
88
|
+
# %% ../nbs/00_core.ipynb
|
|
89
|
+
def _signatures(ns, s, line, col):
|
|
90
|
+
ctx = Interpreter(s, [ns]).get_signatures(line, col)
|
|
91
|
+
if not ctx: ctx = jscript(s).get_signatures(line, col)
|
|
92
|
+
return ctx
|
|
93
|
+
|
|
94
|
+
def sig_help(code, line_no=None, col_no=None):
|
|
95
|
+
ns = get_ipython().user_ns
|
|
96
|
+
ctx = _signatures(ns, code, line=line_no, col=col_no)
|
|
97
|
+
def _s(s): return {'label':s.description,'typ':s.type, 'mod':s.module_name, 'doc':s.docstring(),
|
|
98
|
+
'idx':s.index, 'params':[{'name':p.name} for p in s.params]}
|
|
99
|
+
return [_s(opt) for opt in ctx]
|
|
100
|
+
|
|
101
|
+
# %% ../nbs/00_core.ipynb
|
|
102
|
+
def get_vars(vs:list):
|
|
103
|
+
"Get variables from namespace."
|
|
104
|
+
ns = get_ipython().user_ns
|
|
105
|
+
return {v:ns[v] for v in vs if v in ns}
|
|
106
|
+
|
|
107
|
+
# %% ../nbs/00_core.ipynb
|
|
108
|
+
def _get_schema(ns: dict, t):
|
|
109
|
+
"Check if tool `t` has errors."
|
|
110
|
+
if t not in ns: return f"`{t}` not found. Did you run it?"
|
|
111
|
+
try: return get_schema(ns[t])
|
|
112
|
+
except Exception as e: return f"`{t}`: {e}."
|
|
113
|
+
|
|
114
|
+
def get_schemas(fs:list):
|
|
115
|
+
"Get schemas from namespace."
|
|
116
|
+
ns = get_ipython().user_ns
|
|
117
|
+
return {f:_get_schema(ns,f) for f in fs}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ipykernel-helper
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.2
|
|
4
4
|
Summary: Helpers for ipykernel and friends
|
|
5
5
|
Home-page: https://github.com/AnswerDotAI/ipykernel-helper
|
|
6
6
|
Author: Jeremy Howard
|
|
@@ -19,6 +19,7 @@ Requires-Python: >=3.9
|
|
|
19
19
|
Description-Content-Type: text/markdown
|
|
20
20
|
License-File: LICENSE
|
|
21
21
|
Requires-Dist: fastcore
|
|
22
|
+
Requires-Dist: toolslm>=0.2.0
|
|
22
23
|
Provides-Extra: dev
|
|
23
24
|
Dynamic: author
|
|
24
25
|
Dynamic: author-email
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ipykernel_helper/__init__.py,sha256=oDLMnoGVIAzRy6kwJGpxSDGyOG-aI7DiiERW6jGauWk,42
|
|
2
|
+
ipykernel_helper/_modidx.py,sha256=juRUbLKiU68mB88Ehn5cMLD2REiCSWOQd9BTdeDQz4Y,1727
|
|
3
|
+
ipykernel_helper/core.py,sha256=UpePoI_QbKQM2BjJ3sQ-_54tdFaHHDfLHmSPmu4i7V4,4494
|
|
4
|
+
ipykernel_helper-0.0.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
+
ipykernel_helper-0.0.2.dist-info/METADATA,sha256=xuDKpEG0317k8OoE-_16n2gkthww1fotP4mPVVmZnLI,2557
|
|
6
|
+
ipykernel_helper-0.0.2.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
|
|
7
|
+
ipykernel_helper-0.0.2.dist-info/entry_points.txt,sha256=HWiK9xz75QtZUaPaYrwpyH5B8MbW0Ea_vi11UmwBImM,54
|
|
8
|
+
ipykernel_helper-0.0.2.dist-info/top_level.txt,sha256=_diD--64d9MauLE0pTxzZ58lkI8DvCrVc1hVAJsyc_Q,17
|
|
9
|
+
ipykernel_helper-0.0.2.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
ipykernel_helper/__init__.py,sha256=XoppFCWM_8XsGAbynKKKg7C3Mca0Kzf_ueJ_7U-l9SE,42
|
|
2
|
-
ipykernel_helper/_modidx.py,sha256=RZGtgKFv14Ujyay4e9gpFdx3LVDpgXfYD8oiqMc_2FA,562
|
|
3
|
-
ipykernel_helper/core.py,sha256=pG8zN9RjWNLLUOs8J130kEcHbBoMQJ-etDCZARiG6TM,1459
|
|
4
|
-
ipykernel_helper-0.0.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
ipykernel_helper-0.0.1.dist-info/METADATA,sha256=9P5TmkNHbAEUIDdP1LKHwOlY_vyP5n6CDwdYTsu-3Dw,2527
|
|
6
|
-
ipykernel_helper-0.0.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
7
|
-
ipykernel_helper-0.0.1.dist-info/entry_points.txt,sha256=HWiK9xz75QtZUaPaYrwpyH5B8MbW0Ea_vi11UmwBImM,54
|
|
8
|
-
ipykernel_helper-0.0.1.dist-info/top_level.txt,sha256=_diD--64d9MauLE0pTxzZ58lkI8DvCrVc1hVAJsyc_Q,17
|
|
9
|
-
ipykernel_helper-0.0.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|