execnb 0.3.4__tar.gz → 0.4.0__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.
Files changed (61) hide show
  1. execnb-0.4.0/LICENSE-IPython +33 -0
  2. execnb-0.4.0/LICENSE-matplotlib-inline +29 -0
  3. execnb-0.4.0/PKG-INFO +128 -0
  4. execnb-0.4.0/README.md +99 -0
  5. execnb-0.4.0/execnb/__init__.py +7 -0
  6. execnb-0.4.0/execnb/_ipython.py +41 -0
  7. execnb-0.4.0/execnb/_minipy.py +24 -0
  8. execnb-0.4.0/execnb/_modidx.py +48 -0
  9. execnb-0.4.0/execnb/minipy/__init__.py +1 -0
  10. execnb-0.4.0/execnb/minipy/compilerop.py +29 -0
  11. execnb-0.4.0/execnb/minipy/display.py +271 -0
  12. execnb-0.4.0/execnb/minipy/events.py +20 -0
  13. execnb-0.4.0/execnb/minipy/formatters.py +101 -0
  14. execnb-0.4.0/execnb/minipy/inline.py +87 -0
  15. execnb-0.4.0/execnb/minipy/inputtransformer2.py +479 -0
  16. execnb-0.4.0/execnb/minipy/interactiveshell.py +157 -0
  17. execnb-0.4.0/execnb/minipy/magics.py +353 -0
  18. execnb-0.4.0/execnb/minipy/pretty.py +900 -0
  19. execnb-0.4.0/execnb/minipy/script.py +108 -0
  20. execnb-0.4.0/execnb/minipy/text.py +146 -0
  21. execnb-0.4.0/execnb/minipy/timing.py +137 -0
  22. {execnb-0.3.4 → execnb-0.4.0}/execnb/shell.py +92 -176
  23. execnb-0.4.0/execnb.egg-info/PKG-INFO +128 -0
  24. execnb-0.4.0/execnb.egg-info/SOURCES.txt +52 -0
  25. {execnb-0.3.4 → execnb-0.4.0}/execnb.egg-info/requires.txt +4 -1
  26. {execnb-0.3.4 → execnb-0.4.0}/pyproject.toml +8 -6
  27. execnb-0.4.0/tests/test_display.py +58 -0
  28. execnb-0.4.0/tests/test_execution.py +28 -0
  29. execnb-0.4.0/tests/test_inline.py +30 -0
  30. execnb-0.4.0/tests/test_ipython_async_helpers.py +377 -0
  31. execnb-0.4.0/tests/test_ipython_compilerop.py +50 -0
  32. execnb-0.4.0/tests/test_ipython_display.py +84 -0
  33. execnb-0.4.0/tests/test_ipython_display_formatters.py +85 -0
  34. execnb-0.4.0/tests/test_ipython_display_inline.py +36 -0
  35. execnb-0.4.0/tests/test_ipython_events.py +61 -0
  36. execnb-0.4.0/tests/test_ipython_inputtransformer2.py +291 -0
  37. execnb-0.4.0/tests/test_ipython_inputtransformer2_line.py +140 -0
  38. execnb-0.4.0/tests/test_ipython_interactiveshell.py +242 -0
  39. execnb-0.4.0/tests/test_ipython_iplib.py +28 -0
  40. execnb-0.4.0/tests/test_ipython_magic.py +259 -0
  41. execnb-0.4.0/tests/test_ipython_namespace.py +50 -0
  42. execnb-0.4.0/tests/test_ipython_oinspect.py +81 -0
  43. execnb-0.4.0/tests/test_ipython_pretty.py +613 -0
  44. execnb-0.4.0/tests/test_ipython_process.py +23 -0
  45. execnb-0.4.0/tests/test_ipython_run.py +74 -0
  46. execnb-0.4.0/tests/test_ipython_text.py +79 -0
  47. execnb-0.4.0/tests/test_magics.py +77 -0
  48. execnb-0.4.0/tests/test_shell.py +89 -0
  49. execnb-0.4.0/tests/test_transform.py +13 -0
  50. execnb-0.3.4/PKG-INFO +0 -100
  51. execnb-0.3.4/README.md +0 -75
  52. execnb-0.3.4/execnb/__init__.py +0 -1
  53. execnb-0.3.4/execnb/_modidx.py +0 -58
  54. execnb-0.3.4/execnb.egg-info/PKG-INFO +0 -100
  55. execnb-0.3.4/execnb.egg-info/SOURCES.txt +0 -13
  56. execnb-0.3.4/tests/test_shell.py +0 -34
  57. {execnb-0.3.4 → execnb-0.4.0}/LICENSE +0 -0
  58. {execnb-0.3.4 → execnb-0.4.0}/execnb.egg-info/dependency_links.txt +0 -0
  59. {execnb-0.3.4 → execnb-0.4.0}/execnb.egg-info/entry_points.txt +0 -0
  60. {execnb-0.3.4 → execnb-0.4.0}/execnb.egg-info/top_level.txt +0 -0
  61. {execnb-0.3.4 → execnb-0.4.0}/setup.cfg +0 -0
@@ -0,0 +1,33 @@
1
+ BSD 3-Clause License
2
+
3
+ - Copyright (c) 2008-Present, IPython Development Team
4
+ - Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.edu>
5
+ - Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
6
+ - Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
7
+
8
+ All rights reserved.
9
+
10
+ Redistribution and use in source and binary forms, with or without
11
+ modification, are permitted provided that the following conditions are met:
12
+
13
+ * Redistributions of source code must retain the above copyright notice, this
14
+ list of conditions and the following disclaimer.
15
+
16
+ * Redistributions in binary form must reproduce the above copyright notice,
17
+ this list of conditions and the following disclaimer in the documentation
18
+ and/or other materials provided with the distribution.
19
+
20
+ * Neither the name of the copyright holder nor the names of its
21
+ contributors may be used to endorse or promote products derived from
22
+ this software without specific prior written permission.
23
+
24
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2019-2022, IPython Development Team.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
execnb-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,128 @@
1
+ Metadata-Version: 2.4
2
+ Name: execnb
3
+ Version: 0.4.0
4
+ Summary: Execute notebook cells and capture their outputs without a Jupyter server
5
+ Author-email: Jeremy Howard <j@fast.ai>
6
+ License-Expression: Apache-2.0 AND BSD-3-Clause
7
+ Project-URL: Repository, https://github.com/AnswerDotAI/execnb/
8
+ Project-URL: Documentation, https://AnswerDotAI.github.io/execnb/
9
+ Keywords: some,keywords
10
+ Classifier: Natural Language :: English
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Development Status :: 2 - Pre-Alpha
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3 :: Only
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ License-File: LICENSE-IPython
19
+ License-File: LICENSE-matplotlib-inline
20
+ Requires-Dist: fastcore>=2.2.34
21
+ Provides-Extra: ipython
22
+ Requires-Dist: ipython; extra == "ipython"
23
+ Provides-Extra: dev
24
+ Requires-Dist: matplotlib; extra == "dev"
25
+ Requires-Dist: Pillow; extra == "dev"
26
+ Requires-Dist: mistletoe; extra == "dev"
27
+ Requires-Dist: pytest; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # execnb
31
+
32
+
33
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
34
+
35
+ ## Install
36
+
37
+ Install the lightweight shell:
38
+
39
+ pip install execnb
40
+
41
+ For the full IPython shell, including its extensions and magics:
42
+
43
+ pip install 'execnb[ipython]'
44
+
45
+ For conda, run `conda install -c fastai execnb` (`mamba` also works).
46
+
47
+ ## How to use
48
+
49
+ [`CaptureShell`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell) runs cell strings and captures notebook outputs without a notebook file or a Jupyter server. By default it uses IPython if installed, or the built-in lean shell otherwise. To require real IPython, pass `use_ipython=True`. To select lean explicitly, create `CaptureShell(use_ipython=False)` before anything imports IPython. All shells in a process use the same backend.
50
+
51
+ After creating a lean shell, both `from IPython.display import Markdown, display` and `from IPython import display` work in cells and imported Python modules. The first imports the callable `display`; the second imports the module, so use `display.Markdown(...)` or `display.display(...)`. This makes the display API available without installing full IPython.
52
+
53
+ Each shell runs cells on its own event loop in a background thread. Call `run` from a script, notebook, or async server; the cell can use top-level `await`:
54
+
55
+ ``` python
56
+ from execnb.shell import *
57
+ from fastcore.utils import *
58
+ from fastcore.nbio import *
59
+ ```
60
+
61
+ ``` python
62
+ s = CaptureShell()
63
+ s.run('1+1')
64
+ ```
65
+
66
+ [{'data': {'text/plain': ['2']},
67
+ 'metadata': {},
68
+ 'output_type': 'execute_result',
69
+ 'execution_count': 1}]
70
+
71
+ To execute a notebook and save it with outputs filled in, call `s.execute`:
72
+
73
+ ``` python
74
+ try:
75
+ s.execute('../tests/clean.ipynb', 'tmp.ipynb')
76
+ print(read_nb('tmp.ipynb').cells[1].outputs)
77
+ finally: Path('tmp.ipynb').unlink()
78
+ ```
79
+
80
+ [{'name': 'stdout', 'output_type': 'stream', 'text': '1\n'}, {'data': {'text/plain': '2'}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]
81
+
82
+ You can also execute notebooks from the command line with [`exec_nb`](https://AnswerDotAI.github.io/execnb/shell.html#exec_nb):
83
+
84
+ ``` python
85
+ !exec_nb --help
86
+ ```
87
+
88
+ usage: exec_nb [-h] [--dest (str)] [--exc-stop] [--inject-code (str)] [--inject-path (str)] [--inject-idx (int)]
89
+ [--verbose] [--cell-timeout (int)]
90
+ src
91
+
92
+ Execute notebook from `src` and save with outputs to `dest`
93
+
94
+ positional arguments:
95
+ src Notebook path to read from
96
+
97
+ options:
98
+ -h, --help show this help message and exit
99
+ --dest (str) Notebook path to write to (default: '')
100
+ --exc-stop Stop on exceptions? (default: False)
101
+ --inject-code (str) Code to inject into a cell
102
+ --inject-path (str) Path to file containing code to inject into a cell
103
+ --inject-idx (int) Cell to replace with `inject_code` (default: 0)
104
+ --verbose Show stdout/stderr during execution (default: False)
105
+ --cell-timeout (int) Seconds before each cell times out (None: no limit)
106
+
107
+ execnb 0.3.5
108
+
109
+ ## Parsing notebook commands
110
+
111
+ Use `execnb.minipy.inputtransformer2` to recognize notebook commands without installing IPython or running a shell. A linter can find the position of a command in the original source:
112
+
113
+ ``` python
114
+ from execnb.minipy.inputtransformer2 import TransformerManager, TokenTransformBase, make_tokens_by_line
115
+ ```
116
+
117
+ ``` python
118
+ manager = TransformerManager()
119
+ source = 'files = !ls'
120
+ tokens = make_tokens_by_line(source.splitlines(keepends=True))
121
+ matches = [m for cls in manager.token_transformers if (m := cls.find(tokens))]
122
+ first = min(matches, key=TokenTransformBase.sortby)
123
+ first.start_line, first.start_col
124
+ ```
125
+
126
+ (0, 8)
127
+
128
+ Line and column numbers start at zero. Each transformer finds its first match or returns `None`. `sortby` orders matches by position, then by priority. Retokenize after each edit to find the next command. To translate a whole cell to Python, including cell magics such as `%%bash`, use `manager.transform_cell(source)`.
execnb-0.4.0/README.md ADDED
@@ -0,0 +1,99 @@
1
+ # execnb
2
+
3
+
4
+ <!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
5
+
6
+ ## Install
7
+
8
+ Install the lightweight shell:
9
+
10
+ pip install execnb
11
+
12
+ For the full IPython shell, including its extensions and magics:
13
+
14
+ pip install 'execnb[ipython]'
15
+
16
+ For conda, run `conda install -c fastai execnb` (`mamba` also works).
17
+
18
+ ## How to use
19
+
20
+ [`CaptureShell`](https://AnswerDotAI.github.io/execnb/shell.html#captureshell) runs cell strings and captures notebook outputs without a notebook file or a Jupyter server. By default it uses IPython if installed, or the built-in lean shell otherwise. To require real IPython, pass `use_ipython=True`. To select lean explicitly, create `CaptureShell(use_ipython=False)` before anything imports IPython. All shells in a process use the same backend.
21
+
22
+ After creating a lean shell, both `from IPython.display import Markdown, display` and `from IPython import display` work in cells and imported Python modules. The first imports the callable `display`; the second imports the module, so use `display.Markdown(...)` or `display.display(...)`. This makes the display API available without installing full IPython.
23
+
24
+ Each shell runs cells on its own event loop in a background thread. Call `run` from a script, notebook, or async server; the cell can use top-level `await`:
25
+
26
+ ``` python
27
+ from execnb.shell import *
28
+ from fastcore.utils import *
29
+ from fastcore.nbio import *
30
+ ```
31
+
32
+ ``` python
33
+ s = CaptureShell()
34
+ s.run('1+1')
35
+ ```
36
+
37
+ [{'data': {'text/plain': ['2']},
38
+ 'metadata': {},
39
+ 'output_type': 'execute_result',
40
+ 'execution_count': 1}]
41
+
42
+ To execute a notebook and save it with outputs filled in, call `s.execute`:
43
+
44
+ ``` python
45
+ try:
46
+ s.execute('../tests/clean.ipynb', 'tmp.ipynb')
47
+ print(read_nb('tmp.ipynb').cells[1].outputs)
48
+ finally: Path('tmp.ipynb').unlink()
49
+ ```
50
+
51
+ [{'name': 'stdout', 'output_type': 'stream', 'text': '1\n'}, {'data': {'text/plain': '2'}, 'execution_count': 3, 'metadata': {}, 'output_type': 'execute_result'}]
52
+
53
+ You can also execute notebooks from the command line with [`exec_nb`](https://AnswerDotAI.github.io/execnb/shell.html#exec_nb):
54
+
55
+ ``` python
56
+ !exec_nb --help
57
+ ```
58
+
59
+ usage: exec_nb [-h] [--dest (str)] [--exc-stop] [--inject-code (str)] [--inject-path (str)] [--inject-idx (int)]
60
+ [--verbose] [--cell-timeout (int)]
61
+ src
62
+
63
+ Execute notebook from `src` and save with outputs to `dest`
64
+
65
+ positional arguments:
66
+ src Notebook path to read from
67
+
68
+ options:
69
+ -h, --help show this help message and exit
70
+ --dest (str) Notebook path to write to (default: '')
71
+ --exc-stop Stop on exceptions? (default: False)
72
+ --inject-code (str) Code to inject into a cell
73
+ --inject-path (str) Path to file containing code to inject into a cell
74
+ --inject-idx (int) Cell to replace with `inject_code` (default: 0)
75
+ --verbose Show stdout/stderr during execution (default: False)
76
+ --cell-timeout (int) Seconds before each cell times out (None: no limit)
77
+
78
+ execnb 0.3.5
79
+
80
+ ## Parsing notebook commands
81
+
82
+ Use `execnb.minipy.inputtransformer2` to recognize notebook commands without installing IPython or running a shell. A linter can find the position of a command in the original source:
83
+
84
+ ``` python
85
+ from execnb.minipy.inputtransformer2 import TransformerManager, TokenTransformBase, make_tokens_by_line
86
+ ```
87
+
88
+ ``` python
89
+ manager = TransformerManager()
90
+ source = 'files = !ls'
91
+ tokens = make_tokens_by_line(source.splitlines(keepends=True))
92
+ matches = [m for cls in manager.token_transformers if (m := cls.find(tokens))]
93
+ first = min(matches, key=TokenTransformBase.sortby)
94
+ first.start_line, first.start_col
95
+ ```
96
+
97
+ (0, 8)
98
+
99
+ Line and column numbers start at zero. Each transformer finds its first match or returns `None`. `sortby` orders matches by position, then by priority. Retokenize after each edit to find the next command. To translate a whole cell to Python, including cell magics such as `%%bash`, use `manager.transform_cell(source)`.
@@ -0,0 +1,7 @@
1
+ """Execute notebook cells and capture their outputs without a Jupyter server
2
+
3
+ Modules:
4
+
5
+ - `execnb.minipy.pretty`: Python advanced pretty printer. This pretty printer is intended to replace the old `pprint` python module which does not allow developers to provide their own pretty print callbacks."""
6
+
7
+ __version__ = "0.4.0"
@@ -0,0 +1,41 @@
1
+ """Captured execution on the installed IPython shell."""
2
+ import sys
3
+ from fastcore.imports import in_notebook
4
+ from IPython.core.displayhook import DisplayHook
5
+ from IPython.core.error import StdinNotImplementedError, UsageError
6
+ from IPython.core.interactiveshell import InteractiveShell
7
+ from IPython.utils.capture import capture_output
8
+ from traitlets.config import Config
9
+ from .shell import _CaptureShell, _CustDisplayHook
10
+
11
+
12
+ class _IPythonDisplayHook(_CustDisplayHook, DisplayHook):
13
+ def log_output(self, data):
14
+ if self.shell.history_manager.enabled: super().log_output(data)
15
+
16
+
17
+ class IPythonCaptureShell(_CaptureShell, InteractiveShell):
18
+ displayhook_class = _IPythonDisplayHook
19
+ _capture = staticmethod(capture_output)
20
+ _usage_error = UsageError
21
+ _stdin_error = StdinNotImplementedError
22
+
23
+ def __init__(self, path, mpl_format, history, timeout):
24
+ cfg = Config()
25
+ if not history: cfg.HistoryManager.hist_file = ':memory:'
26
+ super().__init__(config=cfg)
27
+ self.history_manager.enabled = history
28
+ old = InteractiveShell._instance
29
+ if not in_notebook() and (old is None or isinstance(old, IPythonCaptureShell)):
30
+ if old is not None and (plt := sys.modules.get('matplotlib.pyplot')): plt.uninstall_repl_displayhook()
31
+ InteractiveShell._instance = self
32
+ self._start(path, mpl_format, timeout)
33
+
34
+ def showsyntaxerror(self, *args, **kwargs):
35
+ r = self.displayhook.exec_result
36
+ if r is not None and r.success: return super().showsyntaxerror(*args, **kwargs)
37
+
38
+ def _enable_inline(self, fmt):
39
+ from matplotlib_inline.backend_inline import set_matplotlib_formats
40
+ self.enable_matplotlib('inline')
41
+ set_matplotlib_formats(fmt)
@@ -0,0 +1,24 @@
1
+ """Captured execution on the built-in minipy shell."""
2
+ from .minipy.display import DisplayHook, capture_output
3
+ from .minipy.interactiveshell import InteractiveShell
4
+ from .minipy.magics import UsageError
5
+ from .shell import _CaptureShell, _CustDisplayHook
6
+
7
+
8
+ class _MiniDisplayHook(_CustDisplayHook, DisplayHook): pass
9
+
10
+
11
+ class MiniCaptureShell(_CaptureShell, InteractiveShell):
12
+ displayhook_class = _MiniDisplayHook
13
+ _usage_error = UsageError
14
+
15
+ def __init__(self, path, mpl_format, history, timeout):
16
+ if history: raise ValueError("history=True needs the IPython backend")
17
+ super().__init__()
18
+ self._start(path, mpl_format, timeout)
19
+
20
+ def _capture(self, stdout, stderr): return capture_output(stdout, stderr, shell=self)
21
+
22
+ def _enable_inline(self, fmt):
23
+ from .minipy.inline import configure_inline_support
24
+ configure_inline_support(self, fmt)
@@ -0,0 +1,48 @@
1
+ # Autogenerated by nbdev
2
+
3
+ d = { 'syms': { 'execnb.shell': { 'execnb.shell._CustDisplayHook': ('shell.html#_custdisplayhook', 'execnb/shell.py'),
4
+ 'execnb.shell._CaptureShell': ('shell.html#_captureshell', 'execnb/shell.py'),
5
+ 'execnb.shell._CustDisplayHook.write_output_prompt': ( 'shell.html#_custdisplayhook.write_output_prompt',
6
+ 'execnb/shell.py'),
7
+ 'execnb.shell._CustDisplayHook.write_format_data': ( 'shell.html#_custdisplayhook.write_format_data',
8
+ 'execnb/shell.py'),
9
+ 'execnb.shell._CaptureShell._start': ('shell.html#_captureshell._start', 'execnb/shell.py'),
10
+ 'execnb.shell._CaptureShell._no_stdin': ('shell.html#_captureshell._no_stdin', 'execnb/shell.py'),
11
+ 'execnb.shell._CaptureShell.set_path': ('shell.html#_captureshell.set_path', 'execnb/shell.py'),
12
+ 'execnb.shell._CaptureShell.close': ('shell.html#_captureshell.close', 'execnb/shell.py'),
13
+ 'execnb.shell._CaptureShell.enable_gui': ('shell.html#_captureshell.enable_gui', 'execnb/shell.py'),
14
+ 'execnb.shell.leading_comment_lines': ('shell.html#leading_comment_lines', 'execnb/shell.py'),
15
+ 'execnb.shell._ipython_selected': ('shell.html#_ipython_selected', 'execnb/shell.py'),
16
+ 'execnb.shell.CaptureShell': ('shell.html#captureshell', 'execnb/shell.py'),
17
+ 'execnb.shell.capture_output': ('shell.html#capture_output', 'execnb/shell.py'),
18
+ 'execnb.shell._CaptureShell._run_async': ('shell.html#_captureshell._run_async', 'execnb/shell.py'),
19
+ 'execnb.shell.format_exc': ('shell.html#format_exc', 'execnb/shell.py'),
20
+ 'execnb.shell.NbResult': ('shell.html#nbresult', 'execnb/shell.py'),
21
+ 'execnb.shell._out_stream': ('shell.html#_out_stream', 'execnb/shell.py'),
22
+ 'execnb.shell._out_exc': ('shell.html#_out_exc', 'execnb/shell.py'),
23
+ 'execnb.shell._format_mimedata': ('shell.html#_format_mimedata', 'execnb/shell.py'),
24
+ 'execnb.shell._mk_out': ('shell.html#_mk_out', 'execnb/shell.py'),
25
+ 'execnb.shell._out_nb': ('shell.html#_out_nb', 'execnb/shell.py'),
26
+ 'execnb.shell._task_stacks': ('shell.html#_task_stacks', 'execnb/shell.py'),
27
+ 'execnb.shell._CaptureShell.run': ('shell.html#_captureshell.run', 'execnb/shell.py'),
28
+ 'execnb.shell._CaptureShell.showtraceback': ('shell.html#_captureshell.showtraceback', 'execnb/shell.py'),
29
+ 'execnb.shell._pre': ('shell.html#_pre', 'execnb/shell.py'),
30
+ 'execnb.shell._strip': ('shell.html#_strip', 'execnb/shell.py'),
31
+ 'execnb.shell.render_outputs': ('shell.html#render_outputs', 'execnb/shell.py'),
32
+ 'execnb.shell._CaptureShell.cell': ('shell.html#_captureshell.cell', 'execnb/shell.py'),
33
+ 'execnb.shell.find_output': ('shell.html#find_output', 'execnb/shell.py'),
34
+ 'execnb.shell.out_exec': ('shell.html#out_exec', 'execnb/shell.py'),
35
+ 'execnb.shell.out_stream': ('shell.html#out_stream', 'execnb/shell.py'),
36
+ 'execnb.shell.out_error': ('shell.html#out_error', 'execnb/shell.py'),
37
+ 'execnb.shell._false': ('shell.html#_false', 'execnb/shell.py'),
38
+ 'execnb.shell._CaptureShell._reap': ('shell.html#_captureshell._reap', 'execnb/shell.py'),
39
+ 'execnb.shell._CaptureShell.run_all': ('shell.html#_captureshell.run_all', 'execnb/shell.py'),
40
+ 'execnb.shell._CaptureShell.execute': ('shell.html#_captureshell.execute', 'execnb/shell.py'),
41
+ 'execnb.shell._CaptureShell.prettytb': ('shell.html#_captureshell.prettytb', 'execnb/shell.py'),
42
+ 'execnb.shell._CaptureShell.run_text': ('shell.html#_captureshell.run_text', 'execnb/shell.py'),
43
+ 'execnb.shell.exec_nb': ('shell.html#exec_nb', 'execnb/shell.py')}},
44
+ 'settings': { 'branch': 'main',
45
+ 'git_url': 'https://github.com/AnswerDotAI/execnb',
46
+ 'doc_host': 'https://AnswerDotAI.github.io',
47
+ 'doc_baseurl': '/execnb',
48
+ 'lib_path': 'execnb'}}
@@ -0,0 +1 @@
1
+ """IPython cell execution and display for execnb's lean backend."""
@@ -0,0 +1,29 @@
1
+ """IPython's cell compiler and traceback source cache."""
2
+ # Copyright (C) 2010-2011 The IPython Development Team. BSD-3-Clause.
3
+
4
+ import ast, codeop, hashlib, linecache
5
+ from contextlib import contextmanager
6
+
7
+
8
+ def code_name(code, number=0):
9
+ hash_digest = hashlib.sha1(code.encode("utf-8"), usedforsecurity=False).hexdigest()
10
+ return f'<ipython-input-{number}-{hash_digest[:12]}>'
11
+
12
+
13
+ class CachingCompiler(codeop.Compile):
14
+ def ast_parse(self, source, filename='<unknown>', symbol='exec'):
15
+ "Parse code to an AST with the current compiler flags active."
16
+ return compile(source, filename, symbol, self.flags | ast.PyCF_ONLY_AST, dont_inherit=True)
17
+
18
+ def cache(self, transformed_code, number=0):
19
+ name = code_name(transformed_code, number)
20
+ # No mtime: linecache.checkcache() must not evict cell source.
21
+ linecache.cache[name] = len(transformed_code), None, [line + '\n' for line in transformed_code.splitlines()], name
22
+ return name
23
+
24
+ @contextmanager
25
+ def extra_flags(self, flags):
26
+ turn_on_bits = ~self.flags & flags
27
+ self.flags |= flags
28
+ try: yield
29
+ finally: self.flags &= ~turn_on_bits # Preserve future flags set by the cell.