|
135 | 135 | },
|
136 | 136 | {
|
137 | 137 | "cell_type": "code",
|
138 |
| - "execution_count": 5, |
| 138 | + "execution_count": 6, |
139 | 139 | "metadata": {},
|
140 | 140 | "outputs": [],
|
141 | 141 | "source": [
|
|
144 | 144 | " EXTENSION_SUFFIXES = '.ipynb',\n",
|
145 | 145 | " \n",
|
146 | 146 | " def __init__(\n",
|
147 |
| - " self, fullname=None, path=None, *, stdout=False, stderr=False, display=True, lazy=False\n", |
| 147 | + " self, fullname=None, path=None, *, stdout=False, stderr=False, display=False, lazy=False\n", |
148 | 148 | " ): \n",
|
149 | 149 | " SourceFileLoader.__init__(self, fullname, path)\n",
|
150 | 150 | " ExitStack.__init__(self)\n",
|
|
153 | 153 | " \n",
|
154 | 154 | " def __enter__(self, position=0): \n",
|
155 | 155 | " add_path_hooks(type(self), self.EXTENSION_SUFFIXES, position=position, lazy=self._lazy)\n",
|
156 |
| - " stack = super().__enter__()\n", |
157 |
| - " return stack.enter_context(capture_output(\n", |
158 |
| - " stdout=self._stdout, stderr=self._stderr, display=self._display\n", |
159 |
| - " ))\n", |
160 |
| - " \n", |
161 |
| - " def __exit__(self, *excepts): remove_one_path_hook(type(self))\n", |
| 156 | + " if self._capture:\n", |
| 157 | + " stack = super().__enter__()\n", |
| 158 | + " return stack.enter_context(capture_output(\n", |
| 159 | + " stdout=self._stdout, stderr=self._stderr, display=self._display\n", |
| 160 | + " ))\n", |
162 | 161 | " \n",
|
163 |
| - " def exec_module(self, module): super().exec_module(module) \n", |
| 162 | + " @property\n", |
| 163 | + " def _capture(self): return any((self._stdout, self._stderr, self._display))\n", |
| 164 | + " \n", |
| 165 | + " def __exit__(self, *excepts): \n", |
| 166 | + " remove_one_path_hook(type(self))\n", |
| 167 | + " \n", |
| 168 | + " if self._capture: super().__exit__(*excepts)\n", |
164 | 169 | " \n",
|
165 | 170 | " def source_to_code(Notebook, data, path):\n",
|
166 | 171 | " with __import__('io').BytesIO(data) as stream:\n",
|
|
176 | 181 | },
|
177 | 182 | {
|
178 | 183 | "cell_type": "code",
|
179 |
| - "execution_count": 6, |
| 184 | + "execution_count": 7, |
180 | 185 | "metadata": {},
|
181 | 186 | "outputs": [],
|
182 | 187 | "source": [
|
|
203 | 208 | },
|
204 | 209 | {
|
205 | 210 | "cell_type": "code",
|
206 |
| - "execution_count": 7, |
| 211 | + "execution_count": 8, |
207 | 212 | "metadata": {},
|
208 | 213 | "outputs": [],
|
209 | 214 | "source": [
|
|
222 | 227 | },
|
223 | 228 | {
|
224 | 229 | "cell_type": "code",
|
225 |
| - "execution_count": 8, |
| 230 | + "execution_count": 9, |
226 | 231 | "metadata": {
|
227 | 232 | "scrolled": false
|
228 | 233 | },
|
|
232 | 237 | " export('loader.ipynb', '../importnb/loader.py')\n",
|
233 | 238 | " __import__('doctest').testmod()"
|
234 | 239 | ]
|
| 240 | + }, |
| 241 | + { |
| 242 | + "cell_type": "code", |
| 243 | + "execution_count": null, |
| 244 | + "metadata": {}, |
| 245 | + "outputs": [], |
| 246 | + "source": [] |
235 | 247 | }
|
236 | 248 | ],
|
237 | 249 | "metadata": {
|
|
0 commit comments