ipykernel-helper 0.0.2__tar.gz → 0.0.4__tar.gz

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.

Files changed (20) hide show
  1. {ipykernel_helper-0.0.2/ipykernel_helper.egg-info → ipykernel_helper-0.0.4}/PKG-INFO +1 -1
  2. ipykernel_helper-0.0.4/ipykernel_helper/__init__.py +2 -0
  3. ipykernel_helper-0.0.4/ipykernel_helper/_modidx.py +27 -0
  4. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/ipykernel_helper/core.py +43 -26
  5. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4/ipykernel_helper.egg-info}/PKG-INFO +1 -1
  6. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/settings.ini +1 -1
  7. ipykernel_helper-0.0.2/ipykernel_helper/__init__.py +0 -2
  8. ipykernel_helper-0.0.2/ipykernel_helper/_modidx.py +0 -18
  9. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/LICENSE +0 -0
  10. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/MANIFEST.in +0 -0
  11. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/README.md +0 -0
  12. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/ipykernel_helper.egg-info/SOURCES.txt +0 -0
  13. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/ipykernel_helper.egg-info/dependency_links.txt +0 -0
  14. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/ipykernel_helper.egg-info/entry_points.txt +0 -0
  15. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/ipykernel_helper.egg-info/not-zip-safe +0 -0
  16. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/ipykernel_helper.egg-info/requires.txt +0 -0
  17. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/ipykernel_helper.egg-info/top_level.txt +0 -0
  18. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/pyproject.toml +0 -0
  19. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/setup.cfg +0 -0
  20. {ipykernel_helper-0.0.2 → ipykernel_helper-0.0.4}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipykernel-helper
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Helpers for ipykernel and friends
5
5
  Home-page: https://github.com/AnswerDotAI/ipykernel-helper
6
6
  Author: Jeremy Howard
@@ -0,0 +1,2 @@
1
+ __version__ = "0.0.4"
2
+ from .core import *
@@ -0,0 +1,27 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'settings': { 'branch': 'main',
4
+ 'doc_baseurl': '/ipykernel-helper',
5
+ 'doc_host': 'https://AnswerDotAI.github.io',
6
+ 'git_url': 'https://github.com/AnswerDotAI/ipykernel-helper',
7
+ 'lib_path': 'ipykernel_helper'},
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.publish': ( 'core.html#interactiveshell.publish',
13
+ 'ipykernel_helper/core.py'),
14
+ 'ipykernel_helper.core.InteractiveShell.ranked_complete': ( 'core.html#interactiveshell.ranked_complete',
15
+ 'ipykernel_helper/core.py'),
16
+ 'ipykernel_helper.core.InteractiveShell.sig_help': ( 'core.html#interactiveshell.sig_help',
17
+ 'ipykernel_helper/core.py'),
18
+ 'ipykernel_helper.core.InteractiveShell.user_items': ( 'core.html#interactiveshell.user_items',
19
+ 'ipykernel_helper/core.py'),
20
+ 'ipykernel_helper.core.InteractiveShell.xpush': ( 'core.html#interactiveshell.xpush',
21
+ 'ipykernel_helper/core.py'),
22
+ 'ipykernel_helper.core._get_schema': ('core.html#_get_schema', 'ipykernel_helper/core.py'),
23
+ 'ipykernel_helper.core._rank': ('core.html#_rank', 'ipykernel_helper/core.py'),
24
+ 'ipykernel_helper.core._signatures': ('core.html#_signatures', 'ipykernel_helper/core.py'),
25
+ 'ipykernel_helper.core.load_ipython_extension': ( 'core.html#load_ipython_extension',
26
+ 'ipykernel_helper/core.py'),
27
+ 'ipykernel_helper.core.safe_repr': ('core.html#safe_repr', 'ipykernel_helper/core.py')}}}
@@ -3,7 +3,7 @@
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', 'ranked_complete', 'sig_help', 'get_vars', 'get_schemas']
6
+ __all__ = ['safe_repr', 'load_ipython_extension']
7
7
 
8
8
  # %% ../nbs/00_core.ipynb
9
9
  from fastcore.meta import delegates
@@ -12,12 +12,17 @@ import typing,warnings
12
12
  from types import ModuleType, FunctionType, MethodType, BuiltinFunctionType
13
13
  from inspect import signature, currentframe
14
14
  from functools import cmp_to_key,partial
15
+ from collections.abc import Mapping
15
16
  from toolslm.funccall import *
16
17
 
17
18
  from jupyter_client import AsyncKernelClient
19
+ from IPython.core.interactiveshell import InteractiveShell
18
20
  from IPython.core.completer import ProvisionalCompleterWarning
19
21
  from jedi import Interpreter, Script as jscript
20
22
 
23
+ from IPython.core.display import DisplayObject
24
+ from IPython.display import display,Markdown,HTML
25
+
21
26
  # %% ../nbs/00_core.ipynb
22
27
  warnings.filterwarnings('ignore', category=ProvisionalCompleterWarning)
23
28
 
@@ -30,10 +35,11 @@ def safe_repr(obj, max_len=200):
30
35
  except Exception as e: return f"<repr error: {str(e)}>"
31
36
 
32
37
  # %% ../nbs/00_core.ipynb
33
- def user_items(ns=None, max_len=200, xtra_skip=()):
38
+ @patch
39
+ def user_items(self:InteractiveShell, max_len=200, xtra_skip=()):
34
40
  "Get user-defined vars & funcs from namespace."
35
- if ns is None: ns = currentframe().f_back.f_globals
36
- ignore = {'In', 'Out', 'exit', 'quit', 'open', 'nbmeta', 'receive_nbmeta'}
41
+ ns,nsh = self.user_ns,self.user_ns_hidden
42
+ ignore = {'nbmeta', 'receive_nbmeta'}
37
43
  ignore.add(xtra_skip)
38
44
  rm_types = (
39
45
  type, FunctionType, ModuleType, MethodType, BuiltinFunctionType,
@@ -42,23 +48,13 @@ def user_items(ns=None, max_len=200, xtra_skip=()):
42
48
  getattr(typing, '_SpecialForm', ())
43
49
  )
44
50
  user_items = {k:v for k, v in ns.items()
45
- if not k in ignore}
51
+ if not k in ignore and k not in nsh}
46
52
  user_vars = {k:safe_repr(v, max_len=max_len)
47
53
  for k, v in user_items.items() if not k.startswith('_') and not isinstance(v, rm_types)}
48
54
  user_fns = {k:str(signature(v)) for k, v in user_items.items()
49
55
  if isinstance(v, FunctionType) and v.__module__ == '__main__' and not k.startswith('__')}
50
56
  return user_vars,user_fns
51
57
 
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
58
  # %% ../nbs/00_core.ipynb
63
59
  def _rank(c, s):
64
60
  "Rank a completion `c` for text `s` with namespace `ns`."
@@ -72,18 +68,20 @@ def _rank(c, s):
72
68
  return r if is_public else r+0.1
73
69
 
74
70
  # %% ../nbs/00_core.ipynb
75
- def ranked_complete(code, line_no=None, col_no=None):
76
- ipy = get_ipython()
71
+ @patch
72
+ def ranked_complete(self:InteractiveShell, code, line_no=None, col_no=None):
73
+ ns = self.user_ns
77
74
  lines = code.splitlines(True)
78
75
  if line_no: offset = sum(len(lines[i]) for i in range(line_no-1)) + col_no -1
79
76
  else: offset = len(code)
80
- cs = ipy.Completer.completions(code, offset)
77
+ cs = self.Completer.completions(code, offset)
81
78
  def _c(a):
82
79
  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)
80
+ res['mod']= getattr(ns.get(a.text, None), '__module__', None)
84
81
  res['rank'] = _rank(res, s=code)
85
82
  return res
86
- return [_c(c) for c in cs if not c.text.startswith('__')]
83
+ # Remove dunder vars, unless the user seems to be looking for them explicitly
84
+ return [_c(c) for c in cs if not c.text.startswith('__') or '__' in code]
87
85
 
88
86
  # %% ../nbs/00_core.ipynb
89
87
  def _signatures(ns, s, line, col):
@@ -91,17 +89,19 @@ def _signatures(ns, s, line, col):
91
89
  if not ctx: ctx = jscript(s).get_signatures(line, col)
92
90
  return ctx
93
91
 
94
- def sig_help(code, line_no=None, col_no=None):
95
- ns = get_ipython().user_ns
92
+ @patch
93
+ def sig_help(self:InteractiveShell, code, line_no=None, col_no=None):
94
+ ns = self.user_ns
96
95
  ctx = _signatures(ns, code, line=line_no, col=col_no)
97
96
  def _s(s): return {'label':s.description,'typ':s.type, 'mod':s.module_name, 'doc':s.docstring(),
98
97
  'idx':s.index, 'params':[{'name':p.name} for p in s.params]}
99
98
  return [_s(opt) for opt in ctx]
100
99
 
101
100
  # %% ../nbs/00_core.ipynb
102
- def get_vars(vs:list):
101
+ @patch
102
+ def get_vars(self:InteractiveShell, vs:list):
103
103
  "Get variables from namespace."
104
- ns = get_ipython().user_ns
104
+ ns = self.user_ns
105
105
  return {v:ns[v] for v in vs if v in ns}
106
106
 
107
107
  # %% ../nbs/00_core.ipynb
@@ -111,7 +111,24 @@ def _get_schema(ns: dict, t):
111
111
  try: return get_schema(ns[t])
112
112
  except Exception as e: return f"`{t}`: {e}."
113
113
 
114
- def get_schemas(fs:list):
114
+ @patch
115
+ def get_schemas(self:InteractiveShell, fs:list):
115
116
  "Get schemas from namespace."
116
- ns = get_ipython().user_ns
117
+ ns = self.user_ns
117
118
  return {f:_get_schema(ns,f) for f in fs}
119
+
120
+ # %% ../nbs/00_core.ipynb
121
+ @patch
122
+ def xpush(self:InteractiveShell, interactive=False, **kw):
123
+ "Like `push`, but with kwargs"
124
+ self.push(kw, interactive=interactive)
125
+
126
+ # %% ../nbs/00_core.ipynb
127
+ @patch
128
+ def publish(self:InteractiveShell, data='', subtype='plain', mimetype='text', meta=None, update=False, **kw):
129
+ if isinstance(data, DisplayObject): data,_ = self.display_formatter.format(data)
130
+ elif not isinstance(data, Mapping): data = {f'{mimetype}/{subtype}': data}
131
+ self.display_pub.publish(data, metadata=meta, transient=kw, update=update)
132
+
133
+ # %% ../nbs/00_core.ipynb
134
+ def load_ipython_extension(ip): import ipykernel_helper as __ipykernel_helper
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ipykernel-helper
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Helpers for ipykernel and friends
5
5
  Home-page: https://github.com/AnswerDotAI/ipykernel-helper
6
6
  Author: Jeremy Howard
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = ipykernel-helper
3
3
  lib_name = ipykernel-helper
4
- version = 0.0.2
4
+ version = 0.0.4
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
@@ -1,2 +0,0 @@
1
- __version__ = "0.0.2"
2
- from .core import *
@@ -1,18 +0,0 @@
1
- # Autogenerated by nbdev
2
-
3
- d = { 'settings': { 'branch': 'main',
4
- 'doc_baseurl': '/ipykernel-helper',
5
- 'doc_host': 'https://AnswerDotAI.github.io',
6
- 'git_url': 'https://github.com/AnswerDotAI/ipykernel-helper',
7
- 'lib_path': 'ipykernel_helper'},
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'),
18
- 'ipykernel_helper.core.user_items': ('core.html#user_items', 'ipykernel_helper/core.py')}}}