ipykernel-helper 0.0.1__py3-none-any.whl → 0.0.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.

Potentially problematic release.


This version of ipykernel-helper might be problematic. Click here for more details.

@@ -1,2 +1,2 @@
1
- __version__ = "0.0.1"
1
+ __version__ = "0.0.3"
2
2
  from .core import *
@@ -5,5 +5,17 @@ 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.safe_repr': ('core.html#safe_repr', 'ipykernel_helper/core.py'),
9
- 'ipykernel_helper.core.user_items': ('core.html#user_items', 'ipykernel_helper/core.py')}}}
8
+ 'syms': { 'ipykernel_helper.core': { 'ipykernel_helper.core.InteractiveShell.get_schemas': ( 'core.html#interactiveshell.get_schemas',
9
+ 'ipykernel_helper/core.py'),
10
+ 'ipykernel_helper.core.InteractiveShell.get_vars': ( 'core.html#interactiveshell.get_vars',
11
+ 'ipykernel_helper/core.py'),
12
+ 'ipykernel_helper.core.InteractiveShell.ranked_complete': ( 'core.html#interactiveshell.ranked_complete',
13
+ 'ipykernel_helper/core.py'),
14
+ 'ipykernel_helper.core.InteractiveShell.sig_help': ( 'core.html#interactiveshell.sig_help',
15
+ 'ipykernel_helper/core.py'),
16
+ 'ipykernel_helper.core.InteractiveShell.user_items': ( 'core.html#interactiveshell.user_items',
17
+ 'ipykernel_helper/core.py'),
18
+ 'ipykernel_helper.core._get_schema': ('core.html#_get_schema', 'ipykernel_helper/core.py'),
19
+ 'ipykernel_helper.core._rank': ('core.html#_rank', 'ipykernel_helper/core.py'),
20
+ 'ipykernel_helper.core._signatures': ('core.html#_signatures', 'ipykernel_helper/core.py'),
21
+ 'ipykernel_helper.core.safe_repr': ('core.html#safe_repr', 'ipykernel_helper/core.py')}}}
ipykernel_helper/core.py CHANGED
@@ -3,12 +3,26 @@
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']
7
7
 
8
8
  # %% ../nbs/00_core.ipynb
9
- import typing
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.interactiveshell import InteractiveShell
19
+ from IPython.core.completer import ProvisionalCompleterWarning
20
+ from jedi import Interpreter, Script as jscript
21
+
22
+ from IPython.core.display import DisplayObject
23
+
24
+ # %% ../nbs/00_core.ipynb
25
+ warnings.filterwarnings('ignore', category=ProvisionalCompleterWarning)
12
26
 
13
27
  # %% ../nbs/00_core.ipynb
14
28
  def safe_repr(obj, max_len=200):
@@ -19,8 +33,10 @@ def safe_repr(obj, max_len=200):
19
33
  except Exception as e: return f"<repr error: {str(e)}>"
20
34
 
21
35
  # %% ../nbs/00_core.ipynb
22
- def user_items(ns, max_len=200, xtra_skip=()):
36
+ @patch
37
+ def user_items(self:InteractiveShell, max_len=200, xtra_skip=()):
23
38
  "Get user-defined vars & funcs from namespace."
39
+ ns = self.user_ns
24
40
  ignore = {'In', 'Out', 'exit', 'quit', 'open', 'nbmeta', 'receive_nbmeta'}
25
41
  ignore.add(xtra_skip)
26
42
  rm_types = (
@@ -29,8 +45,71 @@ def user_items(ns, max_len=200, xtra_skip=()):
29
45
  getattr(typing, '_GenericAlias', ()),
30
46
  getattr(typing, '_SpecialForm', ())
31
47
  )
32
- user_items = {k: v for k, v in ns.items() if not (k.startswith('_') or k in ignore)}
33
- user_vars = {k:safe_repr(v, max_len=max_len) for k, v in user_items.items() if not isinstance(v, rm_types)}
48
+ user_items = {k:v for k, v in ns.items()
49
+ if not k in ignore}
50
+ user_vars = {k:safe_repr(v, max_len=max_len)
51
+ for k, v in user_items.items() if not k.startswith('_') and not isinstance(v, rm_types)}
34
52
  user_fns = {k:str(signature(v)) for k, v in user_items.items()
35
53
  if isinstance(v, FunctionType) and v.__module__ == '__main__' and not k.startswith('__')}
36
54
  return user_vars,user_fns
55
+
56
+ # %% ../nbs/00_core.ipynb
57
+ def _rank(c, s):
58
+ "Rank a completion `c` for text `s` with namespace `ns`."
59
+ parts = s.split('.')
60
+ is_public = not c.text.startswith('_')
61
+ if c.type=='param': r=1
62
+ elif c.mod=='__main__': r=2 # local
63
+ elif len(parts)>1 and parts[0]==c.mod: r=3 # module
64
+ elif c.mod=='builtins': r=4
65
+ else: r=5
66
+ return r if is_public else r+0.1
67
+
68
+ # %% ../nbs/00_core.ipynb
69
+ @patch
70
+ def ranked_complete(self:InteractiveShell, code, line_no=None, col_no=None):
71
+ ns = self.user_ns
72
+ lines = code.splitlines(True)
73
+ if line_no: offset = sum(len(lines[i]) for i in range(line_no-1)) + col_no -1
74
+ else: offset = len(code)
75
+ cs = self.Completer.completions(code, offset)
76
+ def _c(a):
77
+ res = dict2obj({attr: getattr(a, attr) for attr in dir(a) if attr[0]!='_'})
78
+ res['mod']= getattr(ns.get(a.text, None), '__module__', None)
79
+ res['rank'] = _rank(res, s=code)
80
+ return res
81
+ return [_c(c) for c in cs if not c.text.startswith('__')]
82
+
83
+ # %% ../nbs/00_core.ipynb
84
+ def _signatures(ns, s, line, col):
85
+ ctx = Interpreter(s, [ns]).get_signatures(line, col)
86
+ if not ctx: ctx = jscript(s).get_signatures(line, col)
87
+ return ctx
88
+
89
+ @patch
90
+ def sig_help(self:InteractiveShell, code, line_no=None, col_no=None):
91
+ ns = self.user_ns
92
+ ctx = _signatures(ns, code, line=line_no, col=col_no)
93
+ def _s(s): return {'label':s.description,'typ':s.type, 'mod':s.module_name, 'doc':s.docstring(),
94
+ 'idx':s.index, 'params':[{'name':p.name} for p in s.params]}
95
+ return [_s(opt) for opt in ctx]
96
+
97
+ # %% ../nbs/00_core.ipynb
98
+ @patch
99
+ def get_vars(self:InteractiveShell, vs:list):
100
+ "Get variables from namespace."
101
+ ns = self.user_ns
102
+ return {v:ns[v] for v in vs if v in ns}
103
+
104
+ # %% ../nbs/00_core.ipynb
105
+ def _get_schema(ns: dict, t):
106
+ "Check if tool `t` has errors."
107
+ if t not in ns: return f"`{t}` not found. Did you run it?"
108
+ try: return get_schema(ns[t])
109
+ except Exception as e: return f"`{t}`: {e}."
110
+
111
+ @patch
112
+ def get_schemas(self:InteractiveShell, fs:list):
113
+ "Get schemas from namespace."
114
+ ns = self.user_ns
115
+ 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.1
3
+ Version: 0.0.3
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=DyjzzgRJvp3QnEDlrwpSgOvDRy9Thxh14LVq-rV7GgI,42
2
+ ipykernel_helper/_modidx.py,sha256=x8v8AZ9zPUIOCC8aofbBJM-Tjl8saEL7Y6xJbWC5pFs,2110
3
+ ipykernel_helper/core.py,sha256=AyIXAXTGzj-JkPFZ2lQ9GB2AFX6w1UjzaUyQKxyk3ps,4217
4
+ ipykernel_helper-0.0.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
5
+ ipykernel_helper-0.0.3.dist-info/METADATA,sha256=4jZ3HFje70l4Bc3wrDrM2Nzpqh8IjjaF01So7wVa-Ts,2557
6
+ ipykernel_helper-0.0.3.dist-info/WHEEL,sha256=ck4Vq1_RXyvS4Jt6SI0Vz6fyVs4GWg7AINwpsaGEgPE,91
7
+ ipykernel_helper-0.0.3.dist-info/entry_points.txt,sha256=HWiK9xz75QtZUaPaYrwpyH5B8MbW0Ea_vi11UmwBImM,54
8
+ ipykernel_helper-0.0.3.dist-info/top_level.txt,sha256=_diD--64d9MauLE0pTxzZ58lkI8DvCrVc1hVAJsyc_Q,17
9
+ ipykernel_helper-0.0.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -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,,