Show More
@@ -260,7 +260,7 class BaseIPythonApplication(Application): | |||
|
260 | 260 | # ensure current working directory exists |
|
261 | 261 | try: |
|
262 | 262 | os.getcwd() |
|
263 |
except |
|
|
263 | except: | |
|
264 | 264 | # exit if cwd doesn't exist |
|
265 | 265 | self.log.error("Current working directory doesn't exist.") |
|
266 | 266 | self.exit(1) |
@@ -342,7 +342,7 class BaseIPythonApplication(Application): | |||
|
342 | 342 | try: |
|
343 | 343 | if suppress_errors is not None: |
|
344 | 344 | old_value = Application.raise_config_file_errors |
|
345 | Application.raise_config_file_errors = not suppress_errors | |
|
345 | Application.raise_config_file_errors = not suppress_errors; | |
|
346 | 346 | Application.load_config_file( |
|
347 | 347 | self, |
|
348 | 348 | base_config, |
@@ -10,13 +10,10 from traitlets.config.configurable import Configurable | |||
|
10 | 10 | from traitlets import Instance |
|
11 | 11 | |
|
12 | 12 | |
|
13 | class __BuiltinUndefined: | |
|
14 | pass | |
|
13 | class __BuiltinUndefined(object): pass | |
|
15 | 14 | BuiltinUndefined = __BuiltinUndefined() |
|
16 | 15 | |
|
17 | ||
|
18 | class __HideBuiltin: | |
|
19 | pass | |
|
16 | class __HideBuiltin(object): pass | |
|
20 | 17 | HideBuiltin = __HideBuiltin() |
|
21 | 18 | |
|
22 | 19 |
@@ -34,6 +34,7 import functools | |||
|
34 | 34 | import hashlib |
|
35 | 35 | import linecache |
|
36 | 36 | import operator |
|
37 | import time | |
|
37 | 38 | from contextlib import contextmanager |
|
38 | 39 | |
|
39 | 40 | #----------------------------------------------------------------------------- |
@@ -226,6 +226,7 from IPython.testing.skipdoctest import skip_doctest | |||
|
226 | 226 | from IPython.utils import generics |
|
227 | 227 | from IPython.utils.decorators import sphinx_options |
|
228 | 228 | from IPython.utils.dir2 import dir2, get_real_method |
|
229 | from IPython.utils.docs import GENERATING_DOCUMENTATION | |
|
229 | 230 | from IPython.utils.path import ensure_dir_exists |
|
230 | 231 | from IPython.utils.process import arg_split |
|
231 | 232 | from traitlets import ( |
@@ -133,7 +133,7 from functools import lru_cache | |||
|
133 | 133 | |
|
134 | 134 | from IPython import get_ipython |
|
135 | 135 | from IPython.core.excolors import exception_colors |
|
136 | from IPython.utils import PyColorize, py3compat | |
|
136 | from IPython.utils import PyColorize, coloransi, py3compat | |
|
137 | 137 | |
|
138 | 138 | from typing import TYPE_CHECKING |
|
139 | 139 | |
@@ -281,6 +281,11 class Pdb(OldPdb): | |||
|
281 | 281 | # module and add a few attributes needed for debugging |
|
282 | 282 | self.color_scheme_table = exception_colors() |
|
283 | 283 | |
|
284 | # shorthands | |
|
285 | C = coloransi.TermColors | |
|
286 | cst = self.color_scheme_table | |
|
287 | ||
|
288 | ||
|
284 | 289 | # Add a python parser so we can syntax highlight source while |
|
285 | 290 | # debugging. |
|
286 | 291 | self.parser = PyColorize.Parser(style=color_scheme) |
@@ -214,7 +214,7 class DisplayHook(Configurable): | |||
|
214 | 214 | # by the user. |
|
215 | 215 | update_unders = True |
|
216 | 216 | for unders in ['_'*i for i in range(1,4)]: |
|
217 |
if unders |
|
|
217 | if not unders in self.shell.user_ns: | |
|
218 | 218 | continue |
|
219 | 219 | if getattr(self, unders) is not self.shell.user_ns.get(unders): |
|
220 | 220 | update_unders = False |
@@ -21,6 +21,9 import sys | |||
|
21 | 21 | from traitlets.config.configurable import Configurable |
|
22 | 22 | from traitlets import List |
|
23 | 23 | |
|
24 | # This used to be defined here - it is imported for backwards compatibility | |
|
25 | from .display_functions import publish_display_data | |
|
26 | ||
|
24 | 27 | import typing as t |
|
25 | 28 | |
|
26 | 29 | # ----------------------------------------------------------------------------- |
@@ -4,10 +4,13 | |||
|
4 | 4 | # Copyright (c) IPython Development Team. |
|
5 | 5 | # Distributed under the terms of the Modified BSD License. |
|
6 | 6 | |
|
7 | import os | |
|
8 | import os.path | |
|
7 | 9 | import sys |
|
8 | 10 | from importlib import import_module, reload |
|
9 | 11 | |
|
10 | 12 | from traitlets.config.configurable import Configurable |
|
13 | from IPython.utils.path import ensure_dir_exists | |
|
11 | 14 | from traitlets import Instance |
|
12 | 15 | |
|
13 | 16 |
@@ -954,6 +954,7 class HistoryManager(HistoryAccessor): | |||
|
954 | 954 | """ |
|
955 | 955 | if (not self.db_log_output) or (line_num not in self.output_hist_reprs): |
|
956 | 956 | return |
|
957 | lnum: int = line_num | |
|
957 | 958 | output = self.output_hist_reprs[line_num] |
|
958 | 959 | |
|
959 | 960 | with self.db_output_cache_lock: |
@@ -33,7 +33,7 from io import open as io_open | |||
|
33 | 33 | from logging import error |
|
34 | 34 | from pathlib import Path |
|
35 | 35 | from typing import Callable |
|
36 | from typing import List as ListType, Any as AnyType | |
|
36 | from typing import List as ListType, Dict as DictType, Any as AnyType | |
|
37 | 37 | from typing import Optional, Sequence, Tuple |
|
38 | 38 | from warnings import warn |
|
39 | 39 | |
@@ -118,7 +118,7 from IPython.core.usage import default_banner | |||
|
118 | 118 | from IPython.display import display |
|
119 | 119 | from IPython.paths import get_ipython_dir |
|
120 | 120 | from IPython.testing.skipdoctest import skip_doctest |
|
121 | from IPython.utils import PyColorize, openpy, py3compat | |
|
121 | from IPython.utils import PyColorize, io, openpy, py3compat | |
|
122 | 122 | from IPython.utils.decorators import undoc |
|
123 | 123 | from IPython.utils.io import ask_yes_no |
|
124 | 124 | from IPython.utils.ipstruct import Struct |
@@ -129,18 +129,6 from IPython.utils.syspathcontext import prepended_to_syspath | |||
|
129 | 129 | from IPython.utils.text import DollarFormatter, LSString, SList, format_screen |
|
130 | 130 | from IPython.core.oinspect import OInfo |
|
131 | 131 | |
|
132 | from ast import Module | |
|
133 | ||
|
134 | # we still need to run things using the asyncio eventloop, but there is no | |
|
135 | # async integration | |
|
136 | ||
|
137 | from .async_helpers import ( | |
|
138 | _asyncio_runner, | |
|
139 | _curio_runner, | |
|
140 | _pseudo_sync_runner, | |
|
141 | _should_be_async, | |
|
142 | _trio_runner, | |
|
143 | ) | |
|
144 | 132 | |
|
145 | 133 | sphinxify: Optional[Callable] |
|
146 | 134 | |
@@ -168,11 +156,26 class ProvisionalWarning(DeprecationWarning): | |||
|
168 | 156 | """ |
|
169 | 157 | pass |
|
170 | 158 | |
|
159 | from ast import Module | |
|
171 | 160 | |
|
172 | 161 | _assign_nodes = (ast.AugAssign, ast.AnnAssign, ast.Assign) |
|
173 | 162 | _single_targets_nodes = (ast.AugAssign, ast.AnnAssign) |
|
174 | 163 | |
|
175 | 164 | #----------------------------------------------------------------------------- |
|
165 | # Await Helpers | |
|
166 | #----------------------------------------------------------------------------- | |
|
167 | ||
|
168 | # we still need to run things using the asyncio eventloop, but there is no | |
|
169 | # async integration | |
|
170 | from .async_helpers import ( | |
|
171 | _asyncio_runner, | |
|
172 | _curio_runner, | |
|
173 | _pseudo_sync_runner, | |
|
174 | _should_be_async, | |
|
175 | _trio_runner, | |
|
176 | ) | |
|
177 | ||
|
178 | #----------------------------------------------------------------------------- | |
|
176 | 179 | # Globals |
|
177 | 180 | #----------------------------------------------------------------------------- |
|
178 | 181 | |
@@ -217,8 +220,7 def no_op(*a, **kw): | |||
|
217 | 220 | pass |
|
218 | 221 | |
|
219 | 222 | |
|
220 | class SpaceInInput(Exception): | |
|
221 | pass | |
|
223 | class SpaceInInput(Exception): pass | |
|
222 | 224 | |
|
223 | 225 | |
|
224 | 226 | class SeparateUnicode(Unicode): |
@@ -228,9 +230,8 class SeparateUnicode(Unicode): | |||
|
228 | 230 | """ |
|
229 | 231 | |
|
230 | 232 | def validate(self, obj, value): |
|
231 |
if value == |
|
|
232 | value = "" | |
|
233 | value = value.replace("\\n", "\n") | |
|
233 | if value == '0': value = '' | |
|
234 | value = value.replace('\\n','\n') | |
|
234 | 235 | return super(SeparateUnicode, self).validate(obj, value) |
|
235 | 236 | |
|
236 | 237 | |
@@ -1571,7 +1572,7 class InteractiveShell(SingletonConfigurable): | |||
|
1571 | 1572 | for name in vlist: |
|
1572 | 1573 | try: |
|
1573 | 1574 | vdict[name] = eval(name, cf.f_globals, cf.f_locals) |
|
1574 |
except |
|
|
1575 | except: | |
|
1575 | 1576 | print('Could not get variable %s from %s' % |
|
1576 | 1577 | (name,cf.f_code.co_name)) |
|
1577 | 1578 | else: |
@@ -1730,7 +1731,7 class InteractiveShell(SingletonConfigurable): | |||
|
1730 | 1731 | obj = obj[int(part)] |
|
1731 | 1732 | else: |
|
1732 | 1733 | obj = getattr(obj, part) |
|
1733 |
except |
|
|
1734 | except: | |
|
1734 | 1735 | # Blanket except b/c some badly implemented objects |
|
1735 | 1736 | # allow __getattr__ to raise exceptions other than |
|
1736 | 1737 | # AttributeError, which then crashes IPython. |
@@ -2021,7 +2022,7 class InteractiveShell(SingletonConfigurable): | |||
|
2021 | 2022 | try: |
|
2022 | 2023 | stb = handler(self,etype,value,tb,tb_offset=tb_offset) |
|
2023 | 2024 | return validate_stb(stb) |
|
2024 |
except |
|
|
2025 | except: | |
|
2025 | 2026 | # clear custom handler immediately |
|
2026 | 2027 | self.set_custom_exc((), None) |
|
2027 | 2028 | print("Custom TB Handler failed, unregistering", file=sys.stderr) |
@@ -2214,7 +2215,7 class InteractiveShell(SingletonConfigurable): | |||
|
2214 | 2215 | if filename and issubclass(etype, SyntaxError): |
|
2215 | 2216 | try: |
|
2216 | 2217 | value.filename = filename |
|
2217 |
except |
|
|
2218 | except: | |
|
2218 | 2219 | # Not the format we expect; leave it alone |
|
2219 | 2220 | pass |
|
2220 | 2221 | |
@@ -2860,7 +2861,7 class InteractiveShell(SingletonConfigurable): | |||
|
2860 | 2861 | for key, expr in expressions.items(): |
|
2861 | 2862 | try: |
|
2862 | 2863 | value = self._format_user_obj(eval(expr, global_ns, user_ns)) |
|
2863 |
except |
|
|
2864 | except: | |
|
2864 | 2865 | value = self._user_obj_error() |
|
2865 | 2866 | out[key] = value |
|
2866 | 2867 | return out |
@@ -2914,7 +2915,7 class InteractiveShell(SingletonConfigurable): | |||
|
2914 | 2915 | try: |
|
2915 | 2916 | with fname.open("rb"): |
|
2916 | 2917 | pass |
|
2917 |
except |
|
|
2918 | except: | |
|
2918 | 2919 | warn('Could not open file <%s> for safe execution.' % fname) |
|
2919 | 2920 | return |
|
2920 | 2921 | |
@@ -2944,7 +2945,7 class InteractiveShell(SingletonConfigurable): | |||
|
2944 | 2945 | raise |
|
2945 | 2946 | if not exit_ignore: |
|
2946 | 2947 | self.showtraceback(exception_only=True) |
|
2947 |
except |
|
|
2948 | except: | |
|
2948 | 2949 | if raise_exceptions: |
|
2949 | 2950 | raise |
|
2950 | 2951 | # tb offset is 2 because we wrap execfile |
@@ -2972,7 +2973,7 class InteractiveShell(SingletonConfigurable): | |||
|
2972 | 2973 | try: |
|
2973 | 2974 | with fname.open("rb"): |
|
2974 | 2975 | pass |
|
2975 |
except |
|
|
2976 | except: | |
|
2976 | 2977 | warn('Could not open file <%s> for safe execution.' % fname) |
|
2977 | 2978 | return |
|
2978 | 2979 | |
@@ -3002,7 +3003,7 class InteractiveShell(SingletonConfigurable): | |||
|
3002 | 3003 | result.raise_error() |
|
3003 | 3004 | elif not result.success: |
|
3004 | 3005 | break |
|
3005 |
except |
|
|
3006 | except: | |
|
3006 | 3007 | if raise_exceptions: |
|
3007 | 3008 | raise |
|
3008 | 3009 | self.showtraceback() |
@@ -3032,7 +3033,7 class InteractiveShell(SingletonConfigurable): | |||
|
3032 | 3033 | except SystemExit as status: |
|
3033 | 3034 | if status.code: |
|
3034 | 3035 | raise |
|
3035 |
except |
|
|
3036 | except: | |
|
3036 | 3037 | self.showtraceback() |
|
3037 | 3038 | warn('Unknown failure executing module: <%s>' % mod_name) |
|
3038 | 3039 | |
@@ -3518,7 +3519,7 class InteractiveShell(SingletonConfigurable): | |||
|
3518 | 3519 | if softspace(sys.stdout, 0): |
|
3519 | 3520 | print() |
|
3520 | 3521 | |
|
3521 |
except |
|
|
3522 | except: | |
|
3522 | 3523 | # It's possible to have exceptions raised here, typically by |
|
3523 | 3524 | # compilation of odd code (such as a naked 'return' outside a |
|
3524 | 3525 | # function) that did parse but isn't valid. Typically the exception |
@@ -3590,7 +3591,7 class InteractiveShell(SingletonConfigurable): | |||
|
3590 | 3591 | if result is not None: |
|
3591 | 3592 | result.error_in_exec = value |
|
3592 | 3593 | self.CustomTB(etype, value, tb) |
|
3593 |
except |
|
|
3594 | except: | |
|
3594 | 3595 | if result is not None: |
|
3595 | 3596 | result.error_in_exec = sys.exc_info()[1] |
|
3596 | 3597 | self.showtraceback(running_compiled_code=True) |
@@ -3656,12 +3657,12 class InteractiveShell(SingletonConfigurable): | |||
|
3656 | 3657 | if not _matplotlib_manages_backends() and gui in (None, "auto"): |
|
3657 | 3658 | # Early import of backend_inline required for its side effect of |
|
3658 | 3659 | # calling _enable_matplotlib_integration() |
|
3659 |
import matplotlib_inline.backend_inline |
|
|
3660 | import matplotlib_inline.backend_inline | |
|
3660 | 3661 | |
|
3661 | 3662 | from IPython.core import pylabtools as pt |
|
3662 | 3663 | gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select) |
|
3663 | 3664 | |
|
3664 |
if gui |
|
|
3665 | if gui != None: | |
|
3665 | 3666 | # If we have our first gui selection, store it |
|
3666 | 3667 | if self.pylab_gui_select is None: |
|
3667 | 3668 | self.pylab_gui_select = gui |
@@ -1,39 +1,36 | |||
|
1 | 1 | """Implementation of all the magic functions built into IPython. |
|
2 | 2 | """ |
|
3 | ||
|
4 | # ----------------------------------------------------------------------------- | |
|
3 | #----------------------------------------------------------------------------- | |
|
5 | 4 | # Copyright (c) 2012 The IPython Development Team. |
|
6 | 5 | # |
|
7 | 6 | # Distributed under the terms of the Modified BSD License. |
|
8 | 7 | # |
|
9 | 8 | # The full license is in the file COPYING.txt, distributed with this software. |
|
10 |
# |
|
|
9 | #----------------------------------------------------------------------------- | |
|
11 | 10 | |
|
12 |
# |
|
|
11 | #----------------------------------------------------------------------------- | |
|
13 | 12 | # Imports |
|
14 |
# |
|
|
15 | ||
|
16 |
from ..magic import Magics |
|
|
17 |
from .auto import AutoMagics |
|
|
18 |
from .basic import BasicMagics |
|
|
19 |
from .code import CodeMagics |
|
|
20 |
from .config import ConfigMagics |
|
|
21 |
from .display import DisplayMagics |
|
|
22 |
from .execution import ExecutionMagics |
|
|
23 |
from .extension import ExtensionMagics |
|
|
24 |
from .history import HistoryMagics |
|
|
25 |
from .logging import LoggingMagics |
|
|
26 |
from .namespace import NamespaceMagics |
|
|
27 |
from .osm import OSMagics |
|
|
28 |
from .packaging import PackagingMagics |
|
|
29 |
from .pylab import PylabMagics |
|
|
30 |
from .script import ScriptMagics |
|
|
31 | ||
|
32 | ||
|
33 | # ----------------------------------------------------------------------------- | |
|
13 | #----------------------------------------------------------------------------- | |
|
14 | ||
|
15 | from ..magic import Magics, magics_class | |
|
16 | from .auto import AutoMagics | |
|
17 | from .basic import BasicMagics, AsyncMagics | |
|
18 | from .code import CodeMagics, MacroToEdit | |
|
19 | from .config import ConfigMagics | |
|
20 | from .display import DisplayMagics | |
|
21 | from .execution import ExecutionMagics | |
|
22 | from .extension import ExtensionMagics | |
|
23 | from .history import HistoryMagics | |
|
24 | from .logging import LoggingMagics | |
|
25 | from .namespace import NamespaceMagics | |
|
26 | from .osm import OSMagics | |
|
27 | from .packaging import PackagingMagics | |
|
28 | from .pylab import PylabMagics | |
|
29 | from .script import ScriptMagics | |
|
30 | ||
|
31 | #----------------------------------------------------------------------------- | |
|
34 | 32 | # Magic implementation classes |
|
35 |
# |
|
|
36 | ||
|
33 | #----------------------------------------------------------------------------- | |
|
37 | 34 | |
|
38 | 35 | @magics_class |
|
39 | 36 | class UserMagics(Magics): |
@@ -118,14 +118,14 class AutoMagics(Magics): | |||
|
118 | 118 | return error |
|
119 | 119 | |
|
120 | 120 | if parameter_s: |
|
121 |
if parameter_s |
|
|
121 | if not parameter_s in map(str, valid_modes.keys()): | |
|
122 | 122 | error(errorMessage()) |
|
123 | 123 | return |
|
124 | 124 | arg = int(parameter_s) |
|
125 | 125 | else: |
|
126 | 126 | arg = 'toggle' |
|
127 | 127 | |
|
128 |
if arg |
|
|
128 | if not arg in (*list(valid_modes.keys()), "toggle"): | |
|
129 | 129 | error(errorMessage()) |
|
130 | 130 | return |
|
131 | 131 |
@@ -8,6 +8,7 | |||
|
8 | 8 | import ast |
|
9 | 9 | import bdb |
|
10 | 10 | import builtins as builtin_mod |
|
11 | import copy | |
|
11 | 12 | import cProfile as profile |
|
12 | 13 | import gc |
|
13 | 14 | import itertools |
@@ -21,16 +22,25 import time | |||
|
21 | 22 | import timeit |
|
22 | 23 | from typing import Dict, Any |
|
23 | 24 | from ast import ( |
|
25 | Assign, | |
|
26 | Call, | |
|
27 | Expr, | |
|
28 | Load, | |
|
24 | 29 | Module, |
|
30 | Name, | |
|
31 | NodeTransformer, | |
|
32 | Store, | |
|
33 | parse, | |
|
34 | unparse, | |
|
25 | 35 | ) |
|
26 | 36 | from io import StringIO |
|
27 | 37 | from logging import error |
|
28 | 38 | from pathlib import Path |
|
29 | 39 | from pdb import Restart |
|
30 | from textwrap import indent | |
|
40 | from textwrap import dedent, indent | |
|
31 | 41 | from warnings import warn |
|
32 | 42 | |
|
33 | from IPython.core import magic_arguments, page | |
|
43 | from IPython.core import magic_arguments, oinspect, page | |
|
34 | 44 | from IPython.core.displayhook import DisplayHook |
|
35 | 45 | from IPython.core.error import UsageError |
|
36 | 46 | from IPython.core.macro import Macro |
@@ -1447,12 +1457,10 class ExecutionMagics(Magics): | |||
|
1447 | 1457 | return |
|
1448 | 1458 | macro = Macro(lines) |
|
1449 | 1459 | self.shell.define_macro(name, macro) |
|
1450 |
if |
|
|
1451 | print( | |
|
1452 | "Macro `%s` created. To execute, type its name (without quotes)." % name | |
|
1453 | ) | |
|
1454 | print("=== Macro contents: ===") | |
|
1455 | print(macro, end=" ") | |
|
1460 | if not ( 'q' in opts) : | |
|
1461 | print('Macro `%s` created. To execute, type its name (without quotes).' % name) | |
|
1462 | print('=== Macro contents: ===') | |
|
1463 | print(macro, end=' ') | |
|
1456 | 1464 | |
|
1457 | 1465 | @magic_arguments.magic_arguments() |
|
1458 | 1466 | @magic_arguments.argument('output', type=str, default='', nargs='?', |
@@ -425,9 +425,9 class OSMagics(Magics): | |||
|
425 | 425 | |
|
426 | 426 | if oldcwd != cwd: |
|
427 | 427 | dhist.append(cwd) |
|
428 |
self.shell.db[ |
|
|
429 |
if |
|
|
430 |
print(self.shell.user_ns[ |
|
|
428 | self.shell.db['dhist'] = compress_dhist(dhist)[-100:] | |
|
429 | if not 'q' in opts and not self.cd_force_quiet and self.shell.user_ns['_dh']: | |
|
430 | print(self.shell.user_ns['_dh'][-1]) | |
|
431 | 431 | |
|
432 | 432 | @line_magic |
|
433 | 433 | def env(self, parameter_s=''): |
@@ -255,6 +255,7 def getsource(obj, oname='') -> Union[str,None]: | |||
|
255 | 255 | for attrname in ['fget', 'fset', 'fdel']: |
|
256 | 256 | fn = getattr(obj, attrname) |
|
257 | 257 | if fn is not None: |
|
258 | encoding = get_encoding(fn) | |
|
258 | 259 | oname_prefix = ('%s.' % oname) if oname else '' |
|
259 | 260 | sources.append(''.join(('# ', oname_prefix, attrname))) |
|
260 | 261 | if inspect.isfunction(fn): |
@@ -223,6 +223,7 def pager_page(strng, start=0, screen_lines=0, pager_cmd=None) -> None: | |||
|
223 | 223 | io.TextIOWrapper(proc.stdin, encoding="utf-8"), proc |
|
224 | 224 | ) |
|
225 | 225 | try: |
|
226 | pager_encoding = pager.encoding or sys.stdout.encoding | |
|
226 | 227 | pager.write(strng) |
|
227 | 228 | finally: |
|
228 | 229 | retval = pager.close() |
@@ -3,6 +3,7 | |||
|
3 | 3 | # Copyright (c) IPython Development Team. |
|
4 | 4 | # Distributed under the terms of the Modified BSD License. |
|
5 | 5 | |
|
6 | import warnings | |
|
6 | 7 | from IPython.core.getipython import get_ipython |
|
7 | 8 | |
|
8 | 9 | # see https://github.com/ipython/ipykernel/issues/1304 |
@@ -30,8 +30,8 if __name__ == '__main__': | |||
|
30 | 30 | |
|
31 | 31 | ip = get_ipython() |
|
32 | 32 | |
|
33 |
if |
|
|
34 |
ip.user_ns[ |
|
|
33 | if not '_refbug_cache' in ip.user_ns: | |
|
34 | ip.user_ns['_refbug_cache'] = [] | |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | aglobal = 'Hello' |
@@ -1,5 +1,10 | |||
|
1 | import unittest | |
|
2 | import re | |
|
1 | 3 | from IPython.utils.capture import capture_output |
|
4 | import sys | |
|
2 | 5 | import pytest |
|
6 | from tempfile import TemporaryDirectory | |
|
7 | from IPython.testing import tools as tt | |
|
3 | 8 | |
|
4 | 9 | |
|
5 | 10 | def _exceptiongroup_common( |
@@ -12,6 +12,7 from IPython import get_ipython | |||
|
12 | 12 | from traitlets.config import Config |
|
13 | 13 | from IPython.core.formatters import ( |
|
14 | 14 | PlainTextFormatter, HTMLFormatter, PDFFormatter, _mod_name_key, |
|
15 | DisplayFormatter, JSONFormatter, | |
|
15 | 16 | ) |
|
16 | 17 | from IPython.utils.io import capture_output |
|
17 | 18 |
@@ -6,6 +6,7 | |||
|
6 | 6 | |
|
7 | 7 | # our own packages |
|
8 | 8 | from IPython.core import autocall |
|
9 | from IPython.testing import tools as tt | |
|
9 | 10 | import pytest |
|
10 | 11 | from collections.abc import Callable |
|
11 | 12 |
@@ -23,6 +23,7 from unittest import mock | |||
|
23 | 23 | from os.path import join |
|
24 | 24 | |
|
25 | 25 | from IPython.core.error import InputRejected |
|
26 | from IPython.core.inputtransformer import InputTransformer | |
|
26 | 27 | from IPython.core import interactiveshell |
|
27 | 28 | from IPython.core.oinspect import OInfo |
|
28 | 29 | from IPython.testing.decorators import ( |
@@ -2,6 +2,7 | |||
|
2 | 2 | """ |
|
3 | 3 | |
|
4 | 4 | import stack_data |
|
5 | import sys | |
|
5 | 6 | |
|
6 | 7 | SV_VERSION = tuple([int(x) for x in stack_data.__version__.split(".")[0:2]]) |
|
7 | 8 |
@@ -35,16 +35,12 from IPython.utils.process import find_cmd | |||
|
35 | 35 | from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory |
|
36 | 36 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
37 | 37 | |
|
38 | # import needed by doctest | |
|
39 | from .test_debugger import PdbTestInput # noqa: F401 | |
|
40 | ||
|
41 | _ip = get_ipython() | |
|
38 | from .test_debugger import PdbTestInput | |
|
42 | 39 | |
|
40 | from tempfile import NamedTemporaryFile | |
|
43 | 41 | |
|
44 | 42 | @magic.magics_class |
|
45 | class DummyMagics(magic.Magics): | |
|
46 | pass | |
|
47 | ||
|
43 | class DummyMagics(magic.Magics): pass | |
|
48 | 44 | |
|
49 | 45 | def test_extract_code_ranges(): |
|
50 | 46 | instr = "1 3 5-6 7-9 10:15 17: :10 10- -13 :" |
@@ -63,24 +59,24 def test_extract_code_ranges(): | |||
|
63 | 59 | actual = list(code.extract_code_ranges(instr)) |
|
64 | 60 | assert actual == expected |
|
65 | 61 | |
|
66 | ||
|
67 | 62 | def test_extract_symbols(): |
|
68 | 63 | source = """import foo\na = 10\ndef b():\n return 42\n\n\nclass A: pass\n\n\n""" |
|
69 | 64 | symbols_args = ["a", "b", "A", "A,b", "A,a", "z"] |
|
70 | expected = [ | |
|
71 | ([], ["a"]), | |
|
72 | (["def b():\n return 42\n"], []), | |
|
73 | (["class A: pass\n"], []), | |
|
74 |
(["class A: pass\n" |
|
|
75 | (["class A: pass\n"], ["a"]), | |
|
76 | ([], ["z"]), | |
|
77 | ] | |
|
65 | expected = [([], ['a']), | |
|
66 | (["def b():\n return 42\n"], []), | |
|
67 | (["class A: pass\n"], []), | |
|
68 | (["class A: pass\n", "def b():\n return 42\n"], []), | |
|
69 | (["class A: pass\n"], ['a']), | |
|
70 | ([], ['z'])] | |
|
78 | 71 | for symbols, exp in zip(symbols_args, expected): |
|
79 | 72 | assert code.extract_symbols(source, symbols) == exp |
|
80 | 73 | |
|
81 | 74 | |
|
82 | 75 | def test_extract_symbols_raises_exception_with_non_python_code(): |
|
83 |
source = "=begin A Ruby program :)=end\n" |
|
|
76 | source = ("=begin A Ruby program :)=end\n" | |
|
77 | "def hello\n" | |
|
78 | "puts 'Hello world'\n" | |
|
79 | "end") | |
|
84 | 80 | with pytest.raises(SyntaxError): |
|
85 | 81 | code.extract_symbols(source, "hello") |
|
86 | 82 | |
@@ -91,31 +87,30 def test_magic_not_found(): | |||
|
91 | 87 | _ip.run_line_magic("doesntexist", "") |
|
92 | 88 | |
|
93 | 89 | # ensure result isn't success when a magic isn't found |
|
94 |
result = _ip.run_cell( |
|
|
90 | result = _ip.run_cell('%doesntexist') | |
|
95 | 91 | assert isinstance(result.error_in_exec, UsageError) |
|
96 | 92 | |
|
97 | 93 | |
|
98 | 94 | def test_cell_magic_not_found(): |
|
99 | 95 | # magic not found raises UsageError |
|
100 | 96 | with pytest.raises(UsageError): |
|
101 |
_ip.run_cell_magic( |
|
|
97 | _ip.run_cell_magic('doesntexist', 'line', 'cell') | |
|
102 | 98 | |
|
103 | 99 | # ensure result isn't success when a magic isn't found |
|
104 |
result = _ip.run_cell( |
|
|
100 | result = _ip.run_cell('%%doesntexist') | |
|
105 | 101 | assert isinstance(result.error_in_exec, UsageError) |
|
106 | 102 | |
|
107 | 103 | |
|
108 | 104 | def test_magic_error_status(): |
|
109 | 105 | def fail(shell): |
|
110 |
1 |
|
|
111 | ||
|
106 | 1/0 | |
|
112 | 107 | _ip.register_magic_function(fail) |
|
113 |
result = _ip.run_cell( |
|
|
108 | result = _ip.run_cell('%fail') | |
|
114 | 109 | assert isinstance(result.error_in_exec, ZeroDivisionError) |
|
115 | 110 | |
|
116 | 111 | |
|
117 | 112 | def test_config(): |
|
118 | """test that config magic does not raise | |
|
113 | """ test that config magic does not raise | |
|
119 | 114 | can happen if Configurable init is moved too early into |
|
120 | 115 | Magics.__init__ as then a Config object will be registered as a |
|
121 | 116 | magic. |
@@ -125,18 +120,17 def test_config(): | |||
|
125 | 120 | |
|
126 | 121 | |
|
127 | 122 | def test_config_available_configs(): |
|
128 | """test that config magic prints available configs in unique and | |
|
129 | sorted order.""" | |
|
123 | """ test that config magic prints available configs in unique and | |
|
124 | sorted order. """ | |
|
130 | 125 | with capture_output() as captured: |
|
131 | 126 | _ip.run_line_magic("config", "") |
|
132 | 127 | |
|
133 | 128 | stdout = captured.stdout |
|
134 |
config_classes = stdout.strip().split( |
|
|
129 | config_classes = stdout.strip().split('\n')[1:] | |
|
135 | 130 | assert config_classes == sorted(set(config_classes)) |
|
136 | 131 | |
|
137 | ||
|
138 | 132 | def test_config_print_class(): |
|
139 | """test that config with a classname prints the class's options.""" | |
|
133 | """ test that config with a classname prints the class's options. """ | |
|
140 | 134 | with capture_output() as captured: |
|
141 | 135 | _ip.run_line_magic("config", "TerminalInteractiveShell") |
|
142 | 136 | |
@@ -149,7 +143,7 def test_config_print_class(): | |||
|
149 | 143 | def test_rehashx(): |
|
150 | 144 | # clear up everything |
|
151 | 145 | _ip.alias_manager.clear_aliases() |
|
152 |
del _ip.db[ |
|
|
146 | del _ip.db['syscmdlist'] | |
|
153 | 147 | |
|
154 | 148 | _ip.run_line_magic("rehashx", "") |
|
155 | 149 | # Practically ALL ipython development systems will have more than 10 aliases |
@@ -160,19 +154,19 def test_rehashx(): | |||
|
160 | 154 | assert "." not in name |
|
161 | 155 | |
|
162 | 156 | # rehashx must fill up syscmdlist |
|
163 |
scoms = _ip.db[ |
|
|
157 | scoms = _ip.db['syscmdlist'] | |
|
164 | 158 | assert len(scoms) > 10 |
|
165 | 159 | |
|
166 | 160 | |
|
167 | 161 | def test_magic_parse_options(): |
|
168 | 162 | """Test that we don't mangle paths when parsing magic options.""" |
|
169 | 163 | ip = get_ipython() |
|
170 |
path = |
|
|
164 | path = 'c:\\x' | |
|
171 | 165 | m = DummyMagics(ip) |
|
172 |
opts = m.parse_options( |
|
|
166 | opts = m.parse_options('-f %s' % path,'f:')[0] | |
|
173 | 167 | # argv splitting is os-dependent |
|
174 |
if os.name == |
|
|
175 |
expected = |
|
|
168 | if os.name == 'posix': | |
|
169 | expected = 'c:x' | |
|
176 | 170 | else: |
|
177 | 171 | expected = path |
|
178 | 172 | assert opts["f"] == expected |
@@ -267,21 +261,20 def doctest_hist_op(): | |||
|
267 | 261 | >>> |
|
268 | 262 | """ |
|
269 | 263 | |
|
270 | ||
|
271 | 264 | def test_hist_pof(): |
|
272 | 265 | ip = get_ipython() |
|
273 | 266 | ip.run_cell("1+2", store_history=True) |
|
274 |
# |
|
|
275 |
# |
|
|
267 | #raise Exception(ip.history_manager.session_number) | |
|
268 | #raise Exception(list(ip.history_manager._get_range_session())) | |
|
276 | 269 | with TemporaryDirectory() as td: |
|
277 |
tf = os.path.join(td, |
|
|
278 |
ip.run_line_magic( |
|
|
270 | tf = os.path.join(td, 'hist.py') | |
|
271 | ip.run_line_magic('history', '-pof %s' % tf) | |
|
279 | 272 | assert os.path.isfile(tf) |
|
280 | 273 | |
|
281 | 274 | |
|
282 | 275 | def test_macro(): |
|
283 | 276 | ip = get_ipython() |
|
284 | ip.history_manager.reset() # Clear any existing history. | |
|
277 | ip.history_manager.reset() # Clear any existing history. | |
|
285 | 278 | cmds = ["a=1", "def b():\n return a**2", "print(a,b())"] |
|
286 | 279 | for i, cmd in enumerate(cmds, start=1): |
|
287 | 280 | ip.history_manager.store_inputs(i, cmd) |
@@ -368,12 +361,13 def test_reset_in_length(): | |||
|
368 | 361 | |
|
369 | 362 | |
|
370 | 363 | class TestResetErrors(TestCase): |
|
364 | ||
|
371 | 365 | def test_reset_redefine(self): |
|
366 | ||
|
372 | 367 | @magics_class |
|
373 | 368 | class KernelMagics(Magics): |
|
374 | @line_magic | |
|
375 | def less(self, shell): | |
|
376 | pass | |
|
369 | @line_magic | |
|
370 | def less(self, shell): pass | |
|
377 | 371 | |
|
378 | 372 | _ip.register_magics(KernelMagics) |
|
379 | 373 | |
@@ -382,9 +376,8 class TestResetErrors(TestCase): | |||
|
382 | 376 | # logs get produce. |
|
383 | 377 | # so log one things we ignore. |
|
384 | 378 | import logging as log_mod |
|
385 | ||
|
386 | 379 | log = log_mod.getLogger() |
|
387 |
log.info( |
|
|
380 | log.info('Nothing') | |
|
388 | 381 | # end hack. |
|
389 | 382 | _ip.run_cell("reset -f") |
|
390 | 383 | |
@@ -392,7 +385,6 class TestResetErrors(TestCase): | |||
|
392 | 385 | for out in cm.output: |
|
393 | 386 | assert "Invalid alias" not in out |
|
394 | 387 | |
|
395 | ||
|
396 | 388 | def test_tb_syntaxerror(): |
|
397 | 389 | """test %tb after a SyntaxError""" |
|
398 | 390 | ip = get_ipython() |
@@ -417,7 +409,8 def test_time(): | |||
|
417 | 409 | with tt.AssertPrints("Wall time: "): |
|
418 | 410 | ip.run_cell("%time None") |
|
419 | 411 | |
|
420 |
ip.run_cell("def f(kmjy):\n" |
|
|
412 | ip.run_cell("def f(kmjy):\n" | |
|
413 | " %time print (2*kmjy)") | |
|
421 | 414 | |
|
422 | 415 | with tt.AssertPrints("Wall time: "): |
|
423 | 416 | with tt.AssertPrints("hihi", suppress=False): |
@@ -483,11 +476,13 def test_time_no_output_with_semicolon(): | |||
|
483 | 476 | |
|
484 | 477 | |
|
485 | 478 | def test_time_last_not_expression(): |
|
486 |
|
|
|
487 | assert _ip.user_ns["var_1"] == 1 | |
|
488 | del _ip.user_ns["var_1"] | |
|
489 |
assert |
|
|
490 |
del |
|
|
479 | ip.run_cell("%%time\n" | |
|
480 | "var_1 = 1\n" | |
|
481 | "var_2 = 2\n") | |
|
482 | assert ip.user_ns['var_1'] == 1 | |
|
483 | del ip.user_ns['var_1'] | |
|
484 | assert ip.user_ns['var_2'] == 2 | |
|
485 | del ip.user_ns['var_2'] | |
|
491 | 486 | |
|
492 | 487 | |
|
493 | 488 | @dec.skip_win32 |
@@ -497,20 +492,20 def test_time2(): | |||
|
497 | 492 | with tt.AssertPrints("CPU times: user "): |
|
498 | 493 | ip.run_cell("%time None") |
|
499 | 494 | |
|
500 | ||
|
501 | 495 | def test_time3(): |
|
502 | 496 | """Erroneous magic function calls, issue gh-3334""" |
|
503 | 497 | ip = get_ipython() |
|
504 |
ip.user_ns.pop( |
|
|
505 | ||
|
506 | with tt.AssertNotPrints("not found", channel="stderr"): | |
|
507 | ip.run_cell("%%time\n" "run = 0\n" "run += 1") | |
|
498 | ip.user_ns.pop('run', None) | |
|
508 | 499 | |
|
500 | with tt.AssertNotPrints("not found", channel='stderr'): | |
|
501 | ip.run_cell("%%time\n" | |
|
502 | "run = 0\n" | |
|
503 | "run += 1") | |
|
509 | 504 | |
|
510 | 505 | def test_multiline_time(): |
|
511 | 506 | """Make sure last statement from time return a value.""" |
|
512 | 507 | ip = get_ipython() |
|
513 |
ip.user_ns.pop( |
|
|
508 | ip.user_ns.pop('run', None) | |
|
514 | 509 | |
|
515 | 510 | ip.run_cell( |
|
516 | 511 | dedent( |
@@ -627,7 +622,7 def test_cd_force_quiet(): | |||
|
627 | 622 | with tt.AssertNotPrints(ipdir): |
|
628 | 623 | osmagics.cd('"%s"' % ipdir) |
|
629 | 624 | with tt.AssertNotPrints(startdir): |
|
630 |
osmagics.cd( |
|
|
625 | osmagics.cd('-') | |
|
631 | 626 | finally: |
|
632 | 627 | os.chdir(startdir) |
|
633 | 628 | |
@@ -639,14 +634,11 def test_xmode(): | |||
|
639 | 634 | _ip.run_line_magic("xmode", "") |
|
640 | 635 | assert _ip.InteractiveTB.mode == xmode |
|
641 | 636 | |
|
642 | ||
|
643 | 637 | def test_reset_hard(): |
|
644 | 638 | monitor = [] |
|
645 | ||
|
646 | 639 | class A(object): |
|
647 | 640 | def __del__(self): |
|
648 | 641 | monitor.append(1) |
|
649 | ||
|
650 | 642 | def __repr__(self): |
|
651 | 643 | return "<A instance>" |
|
652 | 644 | |
@@ -657,17 +649,14 def test_reset_hard(): | |||
|
657 | 649 | _ip.run_line_magic("reset", "-f") |
|
658 | 650 | assert monitor == [1] |
|
659 | 651 | |
|
660 | ||
|
661 | 652 | class TestXdel(tt.TempFileMixin): |
|
662 | 653 | def test_xdel(self): |
|
663 | 654 | """Test that references from %run are cleared by xdel.""" |
|
664 | src = ( | |
|
665 | "class A(object):\n" | |
|
666 | " monitor = []\n" | |
|
667 | " def __del__(self):\n" | |
|
668 | " self.monitor.append(1)\n" | |
|
669 | "a = A()\n" | |
|
670 | ) | |
|
655 | src = ("class A(object):\n" | |
|
656 | " monitor = []\n" | |
|
657 | " def __del__(self):\n" | |
|
658 | " self.monitor.append(1)\n" | |
|
659 | "a = A()\n") | |
|
671 | 660 | self.mktmp(src) |
|
672 | 661 | # %run creates some hidden references... |
|
673 | 662 | _ip.run_line_magic("run", "%s" % self.fname) |
@@ -683,7 +672,6 class TestXdel(tt.TempFileMixin): | |||
|
683 | 672 | gc.collect(0) |
|
684 | 673 | assert monitor == [1] |
|
685 | 674 | |
|
686 | ||
|
687 | 675 | def doctest_who(): |
|
688 | 676 | """doctest for %who |
|
689 | 677 | |
@@ -709,18 +697,14 def doctest_who(): | |||
|
709 | 697 | Out[7]: ['alpha', 'beta'] |
|
710 | 698 | """ |
|
711 | 699 | |
|
712 | ||
|
713 | 700 | def test_whos(): |
|
714 | 701 | """Check that whos is protected against objects where repr() fails.""" |
|
715 | ||
|
716 | 702 | class A(object): |
|
717 | 703 | def __repr__(self): |
|
718 | 704 | raise Exception() |
|
719 | ||
|
720 | _ip.user_ns["a"] = A() | |
|
705 | _ip.user_ns['a'] = A() | |
|
721 | 706 | _ip.run_line_magic("whos", "") |
|
722 | 707 | |
|
723 | ||
|
724 | 708 | def doctest_precision(): |
|
725 | 709 | """doctest for %precision |
|
726 | 710 | |
@@ -768,14 +752,12 def test_debug_magic_locals(): | |||
|
768 | 752 | In [2]: |
|
769 | 753 | """ |
|
770 | 754 | |
|
771 | ||
|
772 | 755 | def test_psearch(): |
|
773 | 756 | with tt.AssertPrints("dict.fromkeys"): |
|
774 | 757 | _ip.run_cell("dict.fr*?") |
|
775 | 758 | with tt.AssertPrints("Ï€.is_integer"): |
|
776 | 759 | _ip.run_cell("π = 3.14;\nπ.is_integ*?") |
|
777 | 760 | |
|
778 | ||
|
779 | 761 | def test_timeit_shlex(): |
|
780 | 762 | """test shlex issues with timeit (#1109)""" |
|
781 | 763 | _ip.ex("def f(*a,**kw): pass") |
@@ -789,11 +771,10 def test_timeit_shlex(): | |||
|
789 | 771 | |
|
790 | 772 | def test_timeit_special_syntax(): |
|
791 | 773 | "Test %%timeit with IPython special syntax" |
|
792 | ||
|
793 | 774 | @register_line_magic |
|
794 | 775 | def lmagic(line): |
|
795 | 776 | ip = get_ipython() |
|
796 |
ip.user_ns[ |
|
|
777 | ip.user_ns['lmagic_out'] = line | |
|
797 | 778 | |
|
798 | 779 | # line mode test |
|
799 | 780 | _ip.run_line_magic("timeit", "-n1 -r1 %lmagic my line") |
@@ -808,9 +789,8 def test_timeit_return(): | |||
|
808 | 789 | test whether timeit -o return object |
|
809 | 790 | """ |
|
810 | 791 | |
|
811 |
res = _ip.run_line_magic( |
|
|
812 |
assert |
|
|
813 | ||
|
792 | res = _ip.run_line_magic('timeit','-n10 -r10 -o 1') | |
|
793 | assert(res is not None) | |
|
814 | 794 | |
|
815 | 795 | def test_timeit_quiet(): |
|
816 | 796 | """ |
@@ -819,26 +799,22 def test_timeit_quiet(): | |||
|
819 | 799 | with tt.AssertNotPrints("loops"): |
|
820 | 800 | _ip.run_cell("%timeit -n1 -r1 -q 1") |
|
821 | 801 | |
|
822 | ||
|
823 | 802 | def test_timeit_return_quiet(): |
|
824 | 803 | with tt.AssertNotPrints("loops"): |
|
825 |
res = _ip.run_line_magic( |
|
|
826 | assert res is not None | |
|
827 | ||
|
804 | res = _ip.run_line_magic('timeit', '-n1 -r1 -q -o 1') | |
|
805 | assert (res is not None) | |
|
828 | 806 | |
|
829 | 807 | def test_timeit_invalid_return(): |
|
830 | 808 | with pytest.raises(SyntaxError): |
|
831 |
_ip.run_line_magic( |
|
|
832 | ||
|
809 | _ip.run_line_magic('timeit', 'return') | |
|
833 | 810 | |
|
834 | 811 | @dec.skipif(execution.profile is None) |
|
835 | 812 | def test_prun_special_syntax(): |
|
836 | 813 | "Test %%prun with IPython special syntax" |
|
837 | ||
|
838 | 814 | @register_line_magic |
|
839 | 815 | def lmagic(line): |
|
840 | 816 | ip = get_ipython() |
|
841 |
ip.user_ns[ |
|
|
817 | ip.user_ns['lmagic_out'] = line | |
|
842 | 818 | |
|
843 | 819 | # line mode test |
|
844 | 820 | _ip.run_line_magic("prun", "-q %lmagic my line") |
@@ -857,21 +833,21 def test_prun_quotes(): | |||
|
857 | 833 | |
|
858 | 834 | def test_extension(): |
|
859 | 835 | # Debugging information for failures of this test |
|
860 |
print( |
|
|
836 | print('sys.path:') | |
|
861 | 837 | for p in sys.path: |
|
862 |
print( |
|
|
863 |
print( |
|
|
838 | print(' ', p) | |
|
839 | print('CWD', os.getcwd()) | |
|
864 | 840 | |
|
865 | 841 | pytest.raises(ImportError, _ip.run_line_magic, "load_ext", "daft_extension") |
|
866 | 842 | daft_path = os.path.join(os.path.dirname(__file__), "daft_extension") |
|
867 | 843 | sys.path.insert(0, daft_path) |
|
868 | 844 | try: |
|
869 |
_ip.user_ns.pop( |
|
|
870 | invalidate_caches() # Clear import caches | |
|
845 | _ip.user_ns.pop('arq', None) | |
|
846 | invalidate_caches() # Clear import caches | |
|
871 | 847 | _ip.run_line_magic("load_ext", "daft_extension") |
|
872 | 848 | assert _ip.user_ns["arq"] == 185 |
|
873 | 849 | _ip.run_line_magic("unload_ext", "daft_extension") |
|
874 |
assert |
|
|
850 | assert 'arq' not in _ip.user_ns | |
|
875 | 851 | finally: |
|
876 | 852 | sys.path.remove(daft_path) |
|
877 | 853 | |
@@ -879,7 +855,7 def test_extension(): | |||
|
879 | 855 | def test_notebook_export_json(): |
|
880 | 856 | pytest.importorskip("nbformat") |
|
881 | 857 | _ip = get_ipython() |
|
882 | _ip.history_manager.reset() # Clear any existing history. | |
|
858 | _ip.history_manager.reset() # Clear any existing history. | |
|
883 | 859 | cmds = ["a=1", "def b():\n return a**2", "print('noël, été', b())"] |
|
884 | 860 | for i, cmd in enumerate(cmds, start=1): |
|
885 | 861 | _ip.history_manager.store_inputs(i, cmd) |
@@ -889,6 +865,7 def test_notebook_export_json(): | |||
|
889 | 865 | |
|
890 | 866 | |
|
891 | 867 | class TestEnv(TestCase): |
|
868 | ||
|
892 | 869 | def test_env(self): |
|
893 | 870 | env = _ip.run_line_magic("env", "") |
|
894 | 871 | self.assertTrue(isinstance(env, dict)) |
@@ -902,8 +879,8 class TestEnv(TestCase): | |||
|
902 | 879 | "API_KEY": "abc123", |
|
903 | 880 | "SECRET_THING": "ssshhh", |
|
904 | 881 | "JUPYTER_TOKEN": "", |
|
905 |
"VAR": "abc" |
|
|
906 |
} |
|
|
882 | "VAR": "abc" | |
|
883 | } | |
|
907 | 884 | ): |
|
908 | 885 | env = _ip.run_line_magic("env", "") |
|
909 | 886 | assert env["API_KEY"] == hidden |
@@ -918,16 +895,16 class TestEnv(TestCase): | |||
|
918 | 895 | self.assertEqual(_ip.run_line_magic("env", "var"), "val1") |
|
919 | 896 | env = _ip.run_line_magic("env", "var=val2") |
|
920 | 897 | self.assertEqual(env, None) |
|
921 |
self.assertEqual(os.environ[ |
|
|
898 | self.assertEqual(os.environ['var'], 'val2') | |
|
922 | 899 | |
|
923 | 900 | def test_env_get_set_complex(self): |
|
924 | 901 | env = _ip.run_line_magic("env", "var 'val1 '' 'val2") |
|
925 | 902 | self.assertEqual(env, None) |
|
926 |
self.assertEqual(os.environ[ |
|
|
903 | self.assertEqual(os.environ['var'], "'val1 '' 'val2") | |
|
927 | 904 | self.assertEqual(_ip.run_line_magic("env", "var"), "'val1 '' 'val2") |
|
928 | 905 | env = _ip.run_line_magic("env", 'var=val2 val3="val4') |
|
929 | 906 | self.assertEqual(env, None) |
|
930 |
self.assertEqual(os.environ[ |
|
|
907 | self.assertEqual(os.environ['var'], 'val2 val3="val4') | |
|
931 | 908 | |
|
932 | 909 | def test_env_set_bad_input(self): |
|
933 | 910 | self.assertRaises(UsageError, lambda: _ip.run_line_magic("set_env", "var")) |
@@ -937,6 +914,7 class TestEnv(TestCase): | |||
|
937 | 914 | |
|
938 | 915 | |
|
939 | 916 | class CellMagicTestCase(TestCase): |
|
917 | ||
|
940 | 918 | def check_ident(self, magic): |
|
941 | 919 | # Manually called, we get the result |
|
942 | 920 | out = _ip.run_cell_magic(magic, "a", "b") |
@@ -947,49 +925,46 class CellMagicTestCase(TestCase): | |||
|
947 | 925 | |
|
948 | 926 | def test_cell_magic_func_deco(self): |
|
949 | 927 | "Cell magic using simple decorator" |
|
950 | ||
|
951 | 928 | @register_cell_magic |
|
952 | 929 | def cellm(line, cell): |
|
953 | 930 | return line, cell |
|
954 | 931 | |
|
955 |
self.check_ident( |
|
|
932 | self.check_ident('cellm') | |
|
956 | 933 | |
|
957 | 934 | def test_cell_magic_reg(self): |
|
958 | 935 | "Cell magic manually registered" |
|
959 | ||
|
960 | 936 | def cellm(line, cell): |
|
961 | 937 | return line, cell |
|
962 | 938 | |
|
963 |
_ip.register_magic_function(cellm, |
|
|
964 |
self.check_ident( |
|
|
939 | _ip.register_magic_function(cellm, 'cell', 'cellm2') | |
|
940 | self.check_ident('cellm2') | |
|
965 | 941 | |
|
966 | 942 | def test_cell_magic_class(self): |
|
967 | 943 | "Cell magics declared via a class" |
|
968 | ||
|
969 | 944 | @magics_class |
|
970 | 945 | class MyMagics(Magics): |
|
946 | ||
|
971 | 947 | @cell_magic |
|
972 | 948 | def cellm3(self, line, cell): |
|
973 | 949 | return line, cell |
|
974 | 950 | |
|
975 | 951 | _ip.register_magics(MyMagics) |
|
976 |
self.check_ident( |
|
|
952 | self.check_ident('cellm3') | |
|
977 | 953 | |
|
978 | 954 | def test_cell_magic_class2(self): |
|
979 | 955 | "Cell magics declared via a class, #2" |
|
980 | ||
|
981 | 956 | @magics_class |
|
982 | 957 | class MyMagics2(Magics): |
|
983 | @cell_magic("cellm4") | |
|
958 | ||
|
959 | @cell_magic('cellm4') | |
|
984 | 960 | def cellm33(self, line, cell): |
|
985 | 961 | return line, cell |
|
986 | 962 | |
|
987 | 963 | _ip.register_magics(MyMagics2) |
|
988 |
self.check_ident( |
|
|
964 | self.check_ident('cellm4') | |
|
989 | 965 | # Check that nothing is registered as 'cellm33' |
|
990 |
c33 = _ip.find_cell_magic( |
|
|
991 |
assert c33 |
|
|
992 | ||
|
966 | c33 = _ip.find_cell_magic('cellm33') | |
|
967 | assert c33 == None | |
|
993 | 968 | |
|
994 | 969 | def test_file(): |
|
995 | 970 | """Basic %%writefile""" |
@@ -1078,18 +1053,12 def test_file_unicode(): | |||
|
1078 | 1053 | """%%writefile with unicode cell""" |
|
1079 | 1054 | ip = get_ipython() |
|
1080 | 1055 | with TemporaryDirectory() as td: |
|
1081 |
fname = os.path.join(td, |
|
|
1082 | ip.run_cell_magic( | |
|
1083 |
|
|
|
1084 |
|
|
|
1085 | "\n".join( | |
|
1086 | [ | |
|
1087 | "liné1", | |
|
1088 | "liné2", | |
|
1089 | ] | |
|
1090 | ), | |
|
1091 | ) | |
|
1092 | with io.open(fname, encoding="utf-8") as f: | |
|
1056 | fname = os.path.join(td, 'file1') | |
|
1057 | ip.run_cell_magic("writefile", fname, u'\n'.join([ | |
|
1058 | u'liné1', | |
|
1059 | u'liné2', | |
|
1060 | ])) | |
|
1061 | with io.open(fname, encoding='utf-8') as f: | |
|
1093 | 1062 | s = f.read() |
|
1094 | 1063 | assert "liné1\n" in s |
|
1095 | 1064 | assert "liné2" in s |
@@ -1128,7 +1097,7 def test_file_amend(): | |||
|
1128 | 1097 | def test_file_spaces(): |
|
1129 | 1098 | """%%file with spaces in filename""" |
|
1130 | 1099 | ip = get_ipython() |
|
1131 | with TemporaryWorkingDirectory(): | |
|
1100 | with TemporaryWorkingDirectory() as td: | |
|
1132 | 1101 | fname = "file name" |
|
1133 | 1102 | ip.run_cell_magic( |
|
1134 | 1103 | "file", |
@@ -1147,7 +1116,7 def test_file_spaces(): | |||
|
1147 | 1116 | |
|
1148 | 1117 | def test_script_config(): |
|
1149 | 1118 | ip = get_ipython() |
|
1150 |
ip.config.ScriptMagics.script_magics = [ |
|
|
1119 | ip.config.ScriptMagics.script_magics = ['whoda'] | |
|
1151 | 1120 | sm = script.ScriptMagics(shell=ip) |
|
1152 | 1121 | assert "whoda" in sm.magics["cell"] |
|
1153 | 1122 | |
@@ -1247,7 +1216,7 async def test_script_bg_proc(): | |||
|
1247 | 1216 | |
|
1248 | 1217 | def test_script_defaults(): |
|
1249 | 1218 | ip = get_ipython() |
|
1250 |
for cmd in [ |
|
|
1219 | for cmd in ['sh', 'bash', 'perl', 'ruby']: | |
|
1251 | 1220 | try: |
|
1252 | 1221 | find_cmd(cmd) |
|
1253 | 1222 | except Exception: |
@@ -1259,8 +1228,7 def test_script_defaults(): | |||
|
1259 | 1228 | @magics_class |
|
1260 | 1229 | class FooFoo(Magics): |
|
1261 | 1230 | """class with both %foo and %%foo magics""" |
|
1262 | ||
|
1263 | @line_magic("foo") | |
|
1231 | @line_magic('foo') | |
|
1264 | 1232 | def line_foo(self, line): |
|
1265 | 1233 | "I am line foo" |
|
1266 | 1234 | pass |
@@ -1270,7 +1238,6 class FooFoo(Magics): | |||
|
1270 | 1238 | "I am cell foo, not line foo" |
|
1271 | 1239 | pass |
|
1272 | 1240 | |
|
1273 | ||
|
1274 | 1241 | def test_line_cell_info(): |
|
1275 | 1242 | """%%foo and %foo magics are distinguishable to inspect""" |
|
1276 | 1243 | ip = get_ipython() |
@@ -1330,7 +1297,7 def test_alias_magic(): | |||
|
1330 | 1297 | def test_save(): |
|
1331 | 1298 | """Test %save.""" |
|
1332 | 1299 | ip = get_ipython() |
|
1333 | ip.history_manager.reset() # Clear any existing history. | |
|
1300 | ip.history_manager.reset() # Clear any existing history. | |
|
1334 | 1301 | cmds = ["a=1", "def b():\n return a**2", "print(a, b())"] |
|
1335 | 1302 | for i, cmd in enumerate(cmds, start=1): |
|
1336 | 1303 | ip.history_manager.store_inputs(i, cmd) |
@@ -1372,7 +1339,7 def test_save_with_no_args(): | |||
|
1372 | 1339 | def test_store(): |
|
1373 | 1340 | """Test %store.""" |
|
1374 | 1341 | ip = get_ipython() |
|
1375 |
ip.run_line_magic( |
|
|
1342 | ip.run_line_magic('load_ext', 'storemagic') | |
|
1376 | 1343 | |
|
1377 | 1344 | # make sure the storage is empty |
|
1378 | 1345 | ip.run_line_magic("store", "-z") |
@@ -1388,19 +1355,20 def test_store(): | |||
|
1388 | 1355 | assert ip.user_ns["var"] == 39 |
|
1389 | 1356 | |
|
1390 | 1357 | |
|
1391 | def _run_edit_test( | |
|
1392 | arg_s, exp_filename=None, exp_lineno=-1, exp_contents=None, exp_is_temp=None | |
|
1393 | ): | |
|
1358 | def _run_edit_test(arg_s, exp_filename=None, | |
|
1359 | exp_lineno=-1, | |
|
1360 | exp_contents=None, | |
|
1361 | exp_is_temp=None): | |
|
1394 | 1362 | ip = get_ipython() |
|
1395 | 1363 | M = code.CodeMagics(ip) |
|
1396 |
last_call = [ |
|
|
1397 |
opts, |
|
|
1364 | last_call = ['',''] | |
|
1365 | opts,args = M.parse_options(arg_s,'prxn:') | |
|
1398 | 1366 | filename, lineno, is_temp = M._find_edit_target(ip, args, opts, last_call) |
|
1399 | 1367 | |
|
1400 | 1368 | if exp_filename is not None: |
|
1401 | 1369 | assert exp_filename == filename |
|
1402 | 1370 | if exp_contents is not None: |
|
1403 |
with io.open(filename, |
|
|
1371 | with io.open(filename, 'r', encoding='utf-8') as f: | |
|
1404 | 1372 | contents = f.read() |
|
1405 | 1373 | assert exp_contents == contents |
|
1406 | 1374 | if exp_lineno != -1: |
@@ -1427,26 +1395,23 def test_edit_cell(): | |||
|
1427 | 1395 | ip.run_cell("def foo(): return 1", store_history=True) |
|
1428 | 1396 | |
|
1429 | 1397 | # test |
|
1430 |
_run_edit_test("1", exp_contents=ip.user_ns[ |
|
|
1431 | ||
|
1398 | _run_edit_test("1", exp_contents=ip.user_ns['In'][1], exp_is_temp=True) | |
|
1432 | 1399 | |
|
1433 | 1400 | def test_edit_fname(): |
|
1434 | 1401 | """%edit file""" |
|
1435 | 1402 | # test |
|
1436 | 1403 | _run_edit_test("test file.py", exp_filename="test file.py") |
|
1437 | 1404 | |
|
1438 | ||
|
1439 | 1405 | def test_bookmark(): |
|
1440 | 1406 | ip = get_ipython() |
|
1441 |
ip.run_line_magic( |
|
|
1442 |
with tt.AssertPrints( |
|
|
1443 |
ip.run_line_magic( |
|
|
1444 |
ip.run_line_magic( |
|
|
1445 | ||
|
1407 | ip.run_line_magic('bookmark', 'bmname') | |
|
1408 | with tt.AssertPrints('bmname'): | |
|
1409 | ip.run_line_magic('bookmark', '-l') | |
|
1410 | ip.run_line_magic('bookmark', '-d bmname') | |
|
1446 | 1411 | |
|
1447 | 1412 | def test_ls_magic(): |
|
1448 | 1413 | ip = get_ipython() |
|
1449 |
json_formatter = ip.display_formatter.formatters[ |
|
|
1414 | json_formatter = ip.display_formatter.formatters['application/json'] | |
|
1450 | 1415 | json_formatter.enabled = True |
|
1451 | 1416 | lsmagic = ip.run_line_magic("lsmagic", "") |
|
1452 | 1417 | with warnings.catch_warnings(record=True) as w: |
@@ -1458,24 +1423,23 def test_ls_magic(): | |||
|
1458 | 1423 | def test_strip_initial_indent(): |
|
1459 | 1424 | def sii(s): |
|
1460 | 1425 | lines = s.splitlines() |
|
1461 |
return |
|
|
1426 | return '\n'.join(code.strip_initial_indent(lines)) | |
|
1462 | 1427 | |
|
1463 | 1428 | assert sii(" a = 1\nb = 2") == "a = 1\nb = 2" |
|
1464 | 1429 | assert sii(" a\n b\nc") == "a\n b\nc" |
|
1465 | 1430 | assert sii("a\n b") == "a\n b" |
|
1466 | 1431 | |
|
1467 | ||
|
1468 | 1432 | def test_logging_magic_quiet_from_arg(): |
|
1469 | 1433 | _ip.config.LoggingMagics.quiet = False |
|
1470 | 1434 | lm = logging.LoggingMagics(shell=_ip) |
|
1471 | 1435 | with TemporaryDirectory() as td: |
|
1472 | 1436 | try: |
|
1473 | 1437 | with tt.AssertNotPrints(re.compile("Activating.*")): |
|
1474 |
lm.logstart( |
|
|
1438 | lm.logstart('-q {}'.format( | |
|
1439 | os.path.join(td, "quiet_from_arg.log"))) | |
|
1475 | 1440 | finally: |
|
1476 | 1441 | _ip.logger.logstop() |
|
1477 | 1442 | |
|
1478 | ||
|
1479 | 1443 | def test_logging_magic_quiet_from_config(): |
|
1480 | 1444 | _ip.config.LoggingMagics.quiet = True |
|
1481 | 1445 | lm = logging.LoggingMagics(shell=_ip) |
@@ -1538,16 +1502,18 def load_ipython_extension(ipython): | |||
|
1538 | 1502 | |
|
1539 | 1503 | def test_lazy_magics(): |
|
1540 | 1504 | with pytest.raises(UsageError): |
|
1541 |
|
|
|
1505 | ip.run_line_magic("lazy_line", "") | |
|
1506 | ||
|
1507 | startdir = os.getcwd() | |
|
1542 | 1508 | |
|
1543 | 1509 | with TemporaryDirectory() as tmpdir: |
|
1544 | 1510 | with prepended_to_syspath(tmpdir): |
|
1545 | 1511 | ptempdir = Path(tmpdir) |
|
1546 | 1512 | tf = ptempdir / "lazy_magic_module.py" |
|
1547 | 1513 | tf.write_text(MINIMAL_LAZY_MAGIC) |
|
1548 |
|
|
|
1514 | ip.magics_manager.register_lazy("lazy_line", Path(tf.name).name[:-3]) | |
|
1549 | 1515 | with tt.AssertPrints("Lazy Line"): |
|
1550 |
|
|
|
1516 | ip.run_line_magic("lazy_line", "") | |
|
1551 | 1517 | |
|
1552 | 1518 | |
|
1553 | 1519 | TEST_MODULE = """ |
@@ -1556,7 +1522,6 if __name__ == "__main__": | |||
|
1556 | 1522 | print('I just ran a script') |
|
1557 | 1523 | """ |
|
1558 | 1524 | |
|
1559 | ||
|
1560 | 1525 | def test_run_module_from_import_hook(): |
|
1561 | 1526 | "Test that a module can be loaded via an import hook" |
|
1562 | 1527 | with TemporaryDirectory() as tmpdir: |
@@ -100,7 +100,7 def test_get_ipython_dir_4(): | |||
|
100 | 100 | 'IPYTHONDIR': None, |
|
101 | 101 | 'XDG_CONFIG_HOME': XDG_TEST_DIR, |
|
102 | 102 | }), warnings.catch_warnings(record=True) as w: |
|
103 |
|
|
|
103 | ipdir = paths.get_ipython_dir() | |
|
104 | 104 | |
|
105 | 105 | assert len(w) == 1 |
|
106 | 106 | assert "Ignoring" in str(w[0]) |
@@ -3,6 +3,7 | |||
|
3 | 3 | #----------------------------------------------------------------------------- |
|
4 | 4 | # Imports |
|
5 | 5 | #----------------------------------------------------------------------------- |
|
6 | import pytest | |
|
6 | 7 | |
|
7 | 8 | from IPython.core.prefilter import AutocallChecker |
|
8 | 9 |
@@ -257,6 +257,7 bar() | |||
|
257 | 257 | with tt.AssertPrints('QWERTY'): |
|
258 | 258 | ip.showsyntaxerror() |
|
259 | 259 | |
|
260 | import sys | |
|
260 | 261 | |
|
261 | 262 | if platform.python_implementation() != "PyPy": |
|
262 | 263 | """ |
@@ -188,7 +188,7 def _safe_string(value, what, func=str): | |||
|
188 | 188 | # Copied from cpython/Lib/traceback.py |
|
189 | 189 | try: |
|
190 | 190 | return func(value) |
|
191 |
except |
|
|
191 | except: | |
|
192 | 192 | return f"<{what} {func.__name__}() failed>" |
|
193 | 193 | |
|
194 | 194 | |
@@ -730,9 +730,9 class ListTB(TBTools): | |||
|
730 | 730 | def _some_str(self, value): |
|
731 | 731 | # Lifted from traceback.py |
|
732 | 732 | try: |
|
733 | return str(value) | |
|
733 | return py3compat.cast_unicode(str(value)) | |
|
734 | 734 | except: |
|
735 |
return |
|
|
735 | return u'<unprintable %s object>' % type(value).__name__ | |
|
736 | 736 | |
|
737 | 737 | |
|
738 | 738 | class FrameInfo: |
@@ -1048,7 +1048,7 class VerboseTB(TBTools): | |||
|
1048 | 1048 | colors.excName, |
|
1049 | 1049 | etype_str, |
|
1050 | 1050 | colorsnormal, |
|
1051 | evalue_str, | |
|
1051 | py3compat.cast_unicode(evalue_str), | |
|
1052 | 1052 | ), |
|
1053 | 1053 | *( |
|
1054 | 1054 | "{}{}".format( |
@@ -1071,6 +1071,8 class VerboseTB(TBTools): | |||
|
1071 | 1071 | This may be called multiple times by Python 3 exception chaining |
|
1072 | 1072 | (PEP 3134). |
|
1073 | 1073 | """ |
|
1074 | # some locals | |
|
1075 | orig_etype = etype | |
|
1074 | 1076 | try: |
|
1075 | 1077 | etype = etype.__name__ # type: ignore |
|
1076 | 1078 | except AttributeError: |
@@ -1213,7 +1215,7 class VerboseTB(TBTools): | |||
|
1213 | 1215 | chained_exceptions_tb_offset) |
|
1214 | 1216 | exception = self.get_parts_of_chained_exception(evalue) |
|
1215 | 1217 | |
|
1216 |
if exception and id(exception[1]) |
|
|
1218 | if exception and not id(exception[1]) in chained_exc_ids: | |
|
1217 | 1219 | chained_exc_ids.add(id(exception[1])) # trace exception to avoid infinite 'cause' loop |
|
1218 | 1220 | formatted_exceptions += self.prepare_chained_exception_message(evalue.__cause__) |
|
1219 | 1221 | etype, evalue, etb = exception |
@@ -1408,7 +1410,7 class AutoFormattedTB(FormattedTB): | |||
|
1408 | 1410 | AutoTB = AutoFormattedTB(mode = 'Verbose',color_scheme='Linux') |
|
1409 | 1411 | try: |
|
1410 | 1412 | ... |
|
1411 |
except |
|
|
1413 | except: | |
|
1412 | 1414 | AutoTB() # or AutoTB(out=logfile) where logfile is an open file object |
|
1413 | 1415 | """ |
|
1414 | 1416 | |
@@ -1515,12 +1517,12 def text_repr(value): | |||
|
1515 | 1517 | return pydoc.text.repr(value) # type: ignore[call-arg] |
|
1516 | 1518 | except KeyboardInterrupt: |
|
1517 | 1519 | raise |
|
1518 |
except |
|
|
1520 | except: | |
|
1519 | 1521 | try: |
|
1520 | 1522 | return repr(value) |
|
1521 | 1523 | except KeyboardInterrupt: |
|
1522 | 1524 | raise |
|
1523 |
except |
|
|
1525 | except: | |
|
1524 | 1526 | try: |
|
1525 | 1527 | # all still in an except block so we catch |
|
1526 | 1528 | # getattr raising |
@@ -1533,7 +1535,7 def text_repr(value): | |||
|
1533 | 1535 | return '%s instance' % text_repr(klass) |
|
1534 | 1536 | except KeyboardInterrupt: |
|
1535 | 1537 | raise |
|
1536 |
except |
|
|
1538 | except: | |
|
1537 | 1539 | return 'UNRECOVERABLE REPR FAILURE' |
|
1538 | 1540 | |
|
1539 | 1541 |
@@ -429,7 +429,7 class Demo(object): | |||
|
429 | 429 | def show_all(self): |
|
430 | 430 | """Show entire demo on screen, block by block""" |
|
431 | 431 | |
|
432 | self.title | |
|
432 | fname = self.title | |
|
433 | 433 | title = self.title |
|
434 | 434 | nblocks = self.nblocks |
|
435 | 435 | silent = self._silent |
@@ -56,21 +56,21 def test_warning_on_non_existent_path_FileLink(): | |||
|
56 | 56 | def test_existing_path_FileLink(): |
|
57 | 57 | """FileLink: Calling _repr_html_ functions as expected on existing filepath |
|
58 | 58 | """ |
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
59 | tf = NamedTemporaryFile() | |
|
60 | fl = display.FileLink(tf.name) | |
|
61 | actual = fl._repr_html_() | |
|
62 | expected = "<a href='%s' target='_blank'>%s</a><br>" % (tf.name, tf.name) | |
|
63 | assert actual == expected | |
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | def test_existing_path_FileLink_repr(): |
|
67 | 67 | """FileLink: Calling repr() functions as expected on existing filepath |
|
68 | 68 | """ |
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
69 | tf = NamedTemporaryFile() | |
|
70 | fl = display.FileLink(tf.name) | |
|
71 | actual = repr(fl) | |
|
72 | expected = tf.name | |
|
73 | assert actual == expected | |
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | def test_error_on_directory_to_FileLink(): |
@@ -98,104 +98,98 def test_existing_path_FileLinks(): | |||
|
98 | 98 | """FileLinks: Calling _repr_html_ functions as expected on existing dir |
|
99 | 99 | """ |
|
100 | 100 | td = mkdtemp() |
|
101 | with NamedTemporaryFile(dir=td) as tf1, NamedTemporaryFile(dir=td) as tf2: | |
|
102 | fl = display.FileLinks(td) | |
|
103 | actual = fl._repr_html_() | |
|
104 | actual = actual.split("\n") | |
|
105 | actual.sort() | |
|
106 | # the links should always have forward slashes, even on windows, so replace | |
|
107 | # backslashes with forward slashes here | |
|
108 | expected = [ | |
|
109 |
|
|
|
110 | " <a href='%s' target='_blank'>%s</a><br>" | |
|
111 |
|
|
|
112 | " <a href='%s' target='_blank'>%s</a><br>" | |
|
113 |
|
|
|
114 | ] | |
|
115 | expected.sort() | |
|
116 | # We compare the sorted list of links here as that's more reliable | |
|
117 | assert actual == expected | |
|
101 | tf1 = NamedTemporaryFile(dir=td) | |
|
102 | tf2 = NamedTemporaryFile(dir=td) | |
|
103 | fl = display.FileLinks(td) | |
|
104 | actual = fl._repr_html_() | |
|
105 | actual = actual.split('\n') | |
|
106 | actual.sort() | |
|
107 | # the links should always have forward slashes, even on windows, so replace | |
|
108 | # backslashes with forward slashes here | |
|
109 | expected = ["%s/<br>" % td, | |
|
110 | " <a href='%s' target='_blank'>%s</a><br>" %\ | |
|
111 | (tf2.name.replace("\\","/"),split(tf2.name)[1]), | |
|
112 | " <a href='%s' target='_blank'>%s</a><br>" %\ | |
|
113 | (tf1.name.replace("\\","/"),split(tf1.name)[1])] | |
|
114 | expected.sort() | |
|
115 | # We compare the sorted list of links here as that's more reliable | |
|
116 | assert actual == expected | |
|
118 | 117 | |
|
119 | 118 | |
|
120 | 119 | def test_existing_path_FileLinks_alt_formatter(): |
|
121 | 120 | """FileLinks: Calling _repr_html_ functions as expected w/ an alt formatter |
|
122 | 121 | """ |
|
123 | 122 | td = mkdtemp() |
|
124 |
|
|
|
125 | ||
|
126 |
|
|
|
127 |
|
|
|
128 | ||
|
129 | fl = display.FileLinks(td, notebook_display_formatter=fake_formatter) | |
|
130 | actual = fl._repr_html_() | |
|
131 | actual = actual.split("\n") | |
|
132 | actual.sort() | |
|
133 | expected = ["hello", "world"] | |
|
134 | expected.sort() | |
|
135 | # We compare the sorted list of links here as that's more reliable | |
|
136 | assert actual == expected | |
|
123 | tf1 = NamedTemporaryFile(dir=td) | |
|
124 | tf2 = NamedTemporaryFile(dir=td) | |
|
125 | def fake_formatter(dirname,fnames,included_suffixes): | |
|
126 | return ["hello","world"] | |
|
127 | fl = display.FileLinks(td,notebook_display_formatter=fake_formatter) | |
|
128 | actual = fl._repr_html_() | |
|
129 | actual = actual.split('\n') | |
|
130 | actual.sort() | |
|
131 | expected = ["hello","world"] | |
|
132 | expected.sort() | |
|
133 | # We compare the sorted list of links here as that's more reliable | |
|
134 | assert actual == expected | |
|
137 | 135 | |
|
138 | 136 | |
|
139 | 137 | def test_existing_path_FileLinks_repr(): |
|
140 | 138 | """FileLinks: Calling repr() functions as expected on existing directory """ |
|
141 | 139 | td = mkdtemp() |
|
142 | with NamedTemporaryFile(dir=td) as tf1, NamedTemporaryFile(dir=td) as tf2: | |
|
143 | fl = display.FileLinks(td) | |
|
144 | actual = repr(fl) | |
|
145 | actual = actual.split("\n") | |
|
146 | actual.sort() | |
|
147 | expected = [ | |
|
148 | "%s/" % td, | |
|
149 | " %s" % split(tf1.name)[1], | |
|
150 | " %s" % split(tf2.name)[1], | |
|
151 | ] | |
|
152 | expected.sort() | |
|
153 | # We compare the sorted list of links here as that's more reliable | |
|
154 | assert actual == expected | |
|
140 | tf1 = NamedTemporaryFile(dir=td) | |
|
141 | tf2 = NamedTemporaryFile(dir=td) | |
|
142 | fl = display.FileLinks(td) | |
|
143 | actual = repr(fl) | |
|
144 | actual = actual.split('\n') | |
|
145 | actual.sort() | |
|
146 | expected = ['%s/' % td, ' %s' % split(tf1.name)[1],' %s' % split(tf2.name)[1]] | |
|
147 | expected.sort() | |
|
148 | # We compare the sorted list of links here as that's more reliable | |
|
149 | assert actual == expected | |
|
155 | 150 | |
|
156 | 151 | |
|
157 | 152 | def test_existing_path_FileLinks_repr_alt_formatter(): |
|
158 | 153 | """FileLinks: Calling repr() functions as expected w/ alt formatter |
|
159 | 154 | """ |
|
160 | 155 | td = mkdtemp() |
|
161 |
|
|
|
162 | ||
|
163 |
|
|
|
164 |
|
|
|
165 | ||
|
166 | fl = display.FileLinks(td, terminal_display_formatter=fake_formatter) | |
|
167 | actual = repr(fl) | |
|
168 | actual = actual.split("\n") | |
|
169 | actual.sort() | |
|
170 | expected = ["hello", "world"] | |
|
171 | expected.sort() | |
|
172 | # We compare the sorted list of links here as that's more reliable | |
|
173 | assert actual == expected | |
|
156 | tf1 = NamedTemporaryFile(dir=td) | |
|
157 | tf2 = NamedTemporaryFile(dir=td) | |
|
158 | def fake_formatter(dirname,fnames,included_suffixes): | |
|
159 | return ["hello","world"] | |
|
160 | fl = display.FileLinks(td,terminal_display_formatter=fake_formatter) | |
|
161 | actual = repr(fl) | |
|
162 | actual = actual.split('\n') | |
|
163 | actual.sort() | |
|
164 | expected = ["hello","world"] | |
|
165 | expected.sort() | |
|
166 | # We compare the sorted list of links here as that's more reliable | |
|
167 | assert actual == expected | |
|
174 | 168 | |
|
175 | 169 | |
|
176 | 170 | def test_error_on_file_to_FileLinks(): |
|
177 | 171 | """FileLinks: Raises error when passed file |
|
178 | 172 | """ |
|
179 | 173 | td = mkdtemp() |
|
180 |
|
|
|
181 |
|
|
|
174 | tf1 = NamedTemporaryFile(dir=td) | |
|
175 | pytest.raises(ValueError, display.FileLinks, tf1.name) | |
|
182 | 176 | |
|
183 | 177 | |
|
184 | 178 | def test_recursive_FileLinks(): |
|
185 | 179 | """FileLinks: Does not recurse when recursive=False |
|
186 | 180 | """ |
|
187 | 181 | td = mkdtemp() |
|
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
|
|
|
182 | tf = NamedTemporaryFile(dir=td) | |
|
183 | subtd = mkdtemp(dir=td) | |
|
184 | subtf = NamedTemporaryFile(dir=subtd) | |
|
185 | fl = display.FileLinks(td) | |
|
186 | actual = str(fl) | |
|
187 | actual = actual.split('\n') | |
|
188 | assert len(actual) == 4, actual | |
|
189 | fl = display.FileLinks(td, recursive=False) | |
|
190 | actual = str(fl) | |
|
191 | actual = actual.split('\n') | |
|
192 | assert len(actual) == 2, actual | |
|
199 | 193 | |
|
200 | 194 | def test_audio_from_file(): |
|
201 | 195 | path = pjoin(dirname(__file__), 'test.wav') |
@@ -120,7 +120,7 class IPythonPTCompleter(Completer): | |||
|
120 | 120 | offset = cursor_to_position(body, cursor_row, cursor_col) |
|
121 | 121 | try: |
|
122 | 122 | yield from self._get_completions(body, offset, cursor_position, self.ipy_completer) |
|
123 | except Exception: | |
|
123 | except Exception as e: | |
|
124 | 124 | try: |
|
125 | 125 | exc_type, exc_value, exc_tb = sys.exc_info() |
|
126 | 126 | traceback.print_exception(exc_type, exc_value, exc_tb) |
@@ -132,6 +132,7 class IPythonPTCompleter(Completer): | |||
|
132 | 132 | """ |
|
133 | 133 | Private equivalent of get_completions() use only for unit_testing. |
|
134 | 134 | """ |
|
135 | debug = getattr(ipyc, 'debug', False) | |
|
135 | 136 | completions = _deduplicate_completions( |
|
136 | 137 | body, ipyc.completions(body, offset)) |
|
137 | 138 | for c in completions: |
@@ -393,7 +393,7 def reformat_text_before_cursor(buffer, document, shell): | |||
|
393 | 393 | try: |
|
394 | 394 | formatted_text = shell.reformat_handler(text) |
|
395 | 395 | buffer.insert_text(formatted_text) |
|
396 | except Exception: | |
|
396 | except Exception as e: | |
|
397 | 397 | buffer.insert_text(text) |
|
398 | 398 | |
|
399 | 399 |
@@ -120,17 +120,19 def onlyif(condition, msg): | |||
|
120 | 120 | |
|
121 | 121 | #----------------------------------------------------------------------------- |
|
122 | 122 | # Utility functions for decorators |
|
123 | def module_available(module): | |
|
123 | def module_not_available(module): | |
|
124 | 124 | """Can module be imported? Returns true if module does NOT import. |
|
125 | 125 | |
|
126 | 126 | This is used to make a decorator to skip tests that require module to be |
|
127 | 127 | available, but delay the 'import numpy' to test execution time. |
|
128 | 128 | """ |
|
129 | 129 | try: |
|
130 | import_module(module) | |
|
131 | return True | |
|
130 | mod = import_module(module) | |
|
131 | mod_not_avail = False | |
|
132 | 132 | except ImportError: |
|
133 | return False | |
|
133 | mod_not_avail = True | |
|
134 | ||
|
135 | return mod_not_avail | |
|
134 | 136 | |
|
135 | 137 | |
|
136 | 138 | #----------------------------------------------------------------------------- |
@@ -162,9 +164,7 skip_if_no_x11 = skipif(_x11_skip_cond, _x11_skip_msg) | |||
|
162 | 164 | # Other skip decorators |
|
163 | 165 | |
|
164 | 166 | # generic skip without module |
|
165 | skip_without = lambda mod: skipif( | |
|
166 | not module_available(mod), "This test requires %s" % mod | |
|
167 | ) | |
|
167 | skip_without = lambda mod: skipif(module_not_available(mod), "This test requires %s" % mod) | |
|
168 | 168 | |
|
169 | 169 | skipif_not_numpy = skip_without('numpy') |
|
170 | 170 |
@@ -30,7 +30,7 def test_cve_2022_21699(): | |||
|
30 | 30 | [random.choice(string.ascii_letters) for i in range(10)] |
|
31 | 31 | ) |
|
32 | 32 | |
|
33 | with TemporaryWorkingDirectory(): | |
|
33 | with TemporaryWorkingDirectory() as t: | |
|
34 | 34 | dangerous_startup_dir.mkdir(parents=True) |
|
35 | 35 | (dangerous_startup_dir / "foo.py").write_text( |
|
36 | 36 | f'print("{dangerous_expected}")', encoding="utf-8" |
@@ -22,7 +22,7 import os | |||
|
22 | 22 | from ._process_common import arg_split |
|
23 | 23 | |
|
24 | 24 | |
|
25 |
def system(cmd |
|
|
25 | def system(cmd): | |
|
26 | 26 | """ |
|
27 | 27 | system(cmd) should work in a cli environment on Mac OSX, Linux, |
|
28 | 28 | and Windows |
@@ -33,10 +33,10 def system(cmd: str): | |||
|
33 | 33 | psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal |
|
34 | 34 | psi.UseShellExecute = False |
|
35 | 35 | # Start up process: |
|
36 |
|
|
|
36 | reg = System.Diagnostics.Process.Start(psi) | |
|
37 | 37 | |
|
38 | 38 | |
|
39 |
def getoutput(cmd |
|
|
39 | def getoutput(cmd): | |
|
40 | 40 | """ |
|
41 | 41 | getoutput(cmd) should work in a cli environment on Mac OSX, Linux, |
|
42 | 42 | and Windows |
@@ -51,11 +51,11 def getoutput(cmd: str): | |||
|
51 | 51 | myOutput = reg.StandardOutput |
|
52 | 52 | output = myOutput.ReadToEnd() |
|
53 | 53 | myError = reg.StandardError |
|
54 |
|
|
|
54 | error = myError.ReadToEnd() | |
|
55 | 55 | return output |
|
56 | 56 | |
|
57 | 57 | |
|
58 |
def check_pid(pid |
|
|
58 | def check_pid(pid): | |
|
59 | 59 | """ |
|
60 | 60 | Check if a process with the given PID (pid) exists |
|
61 | 61 | """ |
@@ -8,11 +8,15 IO related utilities. | |||
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | |
|
11 | import atexit | |
|
12 | import os | |
|
11 | 13 | import sys |
|
12 | 14 | import tempfile |
|
13 | 15 | from pathlib import Path |
|
16 | from warnings import warn | |
|
14 | 17 | |
|
15 | from .capture import capture_output as capture_output | |
|
18 | from IPython.utils.decorators import undoc | |
|
19 | from .capture import CapturedIO, capture_output | |
|
16 | 20 | |
|
17 | 21 | class Tee(object): |
|
18 | 22 | """A class to duplicate an output stream to stdout/err. |
@@ -36,7 +36,7 class TeeTestCase(unittest.TestCase): | |||
|
36 | 36 | tee = Tee(chan, channel=channel) |
|
37 | 37 | |
|
38 | 38 | print(text, end='', file=chan) |
|
39 |
|
|
|
39 | trap_val = trap.getvalue() | |
|
40 | 40 | self.assertEqual(chan.getvalue(), text) |
|
41 | 41 | |
|
42 | 42 | tee.close() |
@@ -158,7 +158,7 def test_get_home_dir_4(): | |||
|
158 | 158 | |
|
159 | 159 | if 'HOME' in env: del env['HOME'] |
|
160 | 160 | # this should still succeed, but we don't care what the answer is |
|
161 |
|
|
|
161 | home = path.get_home_dir(False) | |
|
162 | 162 | |
|
163 | 163 | @skip_win32 |
|
164 | 164 | @with_environment |
@@ -254,7 +254,7 def test_filefind(): | |||
|
254 | 254 | f = tempfile.NamedTemporaryFile() |
|
255 | 255 | # print('fname:',f.name) |
|
256 | 256 | alt_dirs = paths.get_ipython_dir() |
|
257 |
|
|
|
257 | t = path.filefind(f.name, alt_dirs) | |
|
258 | 258 | # print('found:',t) |
|
259 | 259 | |
|
260 | 260 |
@@ -31,6 +31,7 def test_simple(): | |||
|
31 | 31 | |
|
32 | 32 | def test_function(): |
|
33 | 33 | cell = "foo(a=5, b='10')" |
|
34 | expected = 'foo' | |
|
34 | 35 | # up to `foo(|a=` |
|
35 | 36 | for i in range(cell.find('a=') + 1): |
|
36 | 37 | expect_token("foo", cell, i) |
@@ -79,6 +79,7 def ghissue_role(name, rawtext, text, lineno, inliner, options=None, content=Non | |||
|
79 | 79 | '"%s" is invalid.' % text, line=lineno) |
|
80 | 80 | prb = inliner.problematic(rawtext, rawtext, msg) |
|
81 | 81 | return [prb], [msg] |
|
82 | app = inliner.document.settings.env.app | |
|
82 | 83 | #info('issue %r' % text) |
|
83 | 84 | if 'pull' in name.lower(): |
|
84 | 85 | category = 'pull' |
@@ -90,7 +91,6 def ghissue_role(name, rawtext, text, lineno, inliner, options=None, content=Non | |||
|
90 | 91 | '"%s" is invalid.' % name, line=lineno) |
|
91 | 92 | prb = inliner.problematic(rawtext, rawtext, msg) |
|
92 | 93 | return [prb], [msg] |
|
93 | app = inliner.document.settings.env.app | |
|
94 | 94 | node = make_link_node(rawtext, app, category, str(issue_num), options) |
|
95 | 95 | return [node], [] |
|
96 | 96 | |
@@ -112,6 +112,7 def ghuser_role(name, rawtext, text, lineno, inliner, options=None, content=None | |||
|
112 | 112 | if options is None: |
|
113 | 113 | options = {} |
|
114 | 114 | |
|
115 | app = inliner.document.settings.env.app | |
|
115 | 116 | #info('user link %r' % text) |
|
116 | 117 | ref = 'https://www.github.com/' + text |
|
117 | 118 | node = nodes.reference(rawtext, text, refuri=ref, **options) |
@@ -135,6 +136,7 def ghcommit_role(name, rawtext, text, lineno, inliner, options=None, content=No | |||
|
135 | 136 | if options is None: |
|
136 | 137 | options = {} |
|
137 | 138 | |
|
139 | app = inliner.document.settings.env.app | |
|
138 | 140 | #info('user link %r' % text) |
|
139 | 141 | try: |
|
140 | 142 | base = app.config.github_project_url |
@@ -2,7 +2,7 | |||
|
2 | 2 | requires = ["setuptools>=61.2"] |
|
3 | 3 | # We need access to the 'setupbase' module at build time. |
|
4 | 4 | # Hence we declare a custom build backend. |
|
5 | build-backend = "_build_meta" # just re-exports setuptools.build_meta definitions | |
|
5 | build-backend = "_build_meta" # just re-exports setuptools.build_meta definitions | |
|
6 | 6 | backend-path = ["."] |
|
7 | 7 | |
|
8 | 8 | [project] |
@@ -56,7 +56,9 Source = "https://github.com/ipython/ipython" | |||
|
56 | 56 | Tracker = "https://github.com/ipython/ipython/issues" |
|
57 | 57 | |
|
58 | 58 | [project.optional-dependencies] |
|
59 |
black = [ |
|
|
59 | black = [ | |
|
60 | "black", | |
|
61 | ] | |
|
60 | 62 | doc = [ |
|
61 | 63 | "docrepr", |
|
62 | 64 | "exceptiongroup", |
@@ -69,14 +71,33 doc = [ | |||
|
69 | 71 | "sphinx>=1.3", |
|
70 | 72 | "sphinxcontrib-jquery", |
|
71 | 73 | ] |
|
72 |
kernel = [ |
|
|
73 | nbconvert = ["nbconvert"] | |
|
74 | nbformat = ["nbformat"] | |
|
75 | notebook = ["ipywidgets", "notebook"] | |
|
76 | parallel = ["ipyparallel"] | |
|
77 | qtconsole = ["qtconsole"] | |
|
74 | kernel = [ | |
|
75 | "ipykernel", | |
|
76 | ] | |
|
77 | nbconvert = [ | |
|
78 | "nbconvert", | |
|
79 | ] | |
|
80 | nbformat = [ | |
|
81 | "nbformat", | |
|
82 | ] | |
|
83 | notebook = [ | |
|
84 | "ipywidgets", | |
|
85 | "notebook", | |
|
86 | ] | |
|
87 | parallel = [ | |
|
88 | "ipyparallel", | |
|
89 | ] | |
|
90 | qtconsole = [ | |
|
91 | "qtconsole", | |
|
92 | ] | |
|
78 | 93 | terminal = [] |
|
79 | test = ["pytest", "pytest-asyncio<0.22", "testpath", "pickleshare", "packaging"] | |
|
94 | test = [ | |
|
95 | "pytest", | |
|
96 | "pytest-asyncio<0.22", | |
|
97 | "testpath", | |
|
98 | "pickleshare", | |
|
99 | "packaging", | |
|
100 | ] | |
|
80 | 101 | test_extra = [ |
|
81 | 102 | "ipython[test]", |
|
82 | 103 | "curio", |
@@ -86,7 +107,9 test_extra = [ | |||
|
86 | 107 | "pandas", |
|
87 | 108 | "trio", |
|
88 | 109 | ] |
|
89 |
matplotlib = [ |
|
|
110 | matplotlib = [ | |
|
111 | "matplotlib" | |
|
112 | ] | |
|
90 | 113 | all = [ |
|
91 | 114 | "ipython[black,doc,kernel,nbconvert,nbformat,notebook,parallel,qtconsole,matplotlib]", |
|
92 | 115 | "ipython[test,test_extra]", |
@@ -97,18 +120,18 python_version = "3.10" | |||
|
97 | 120 | ignore_missing_imports = true |
|
98 | 121 | follow_imports = 'silent' |
|
99 | 122 | exclude = [ |
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
123 | 'test_\.+\.py', | |
|
124 | 'IPython.utils.tests.test_wildcard', | |
|
125 | 'testing', | |
|
126 | 'tests', | |
|
127 | 'PyColorize.py', | |
|
128 | '_process_win32_controller.py', | |
|
129 | 'IPython/core/application.py', | |
|
130 | 'IPython/core/profileapp.py', | |
|
131 | 'IPython/lib/deepreload.py', | |
|
132 | 'IPython/sphinxext/ipython_directive.py', | |
|
133 | 'IPython/terminal/ipapp.py', | |
|
134 | 'IPython/utils/path.py', | |
|
112 | 135 | ] |
|
113 | 136 | # check_untyped_defs = true |
|
114 | 137 | # disallow_untyped_calls = true |
@@ -120,7 +143,9 disallow_untyped_defs = true | |||
|
120 | 143 | warn_redundant_casts = true |
|
121 | 144 | |
|
122 | 145 | [[tool.mypy.overrides]] |
|
123 | module = ["IPython.core.crashhandler"] | |
|
146 | module = [ | |
|
147 | "IPython.core.crashhandler", | |
|
148 | ] | |
|
124 | 149 | check_untyped_defs = true |
|
125 | 150 | disallow_incomplete_defs = true |
|
126 | 151 | disallow_untyped_calls = true |
@@ -130,13 +155,16 ignore_errors = false | |||
|
130 | 155 | ignore_missing_imports = false |
|
131 | 156 | |
|
132 | 157 | [[tool.mypy.overrides]] |
|
133 | module = ["IPython.utils.text"] | |
|
158 | module = [ | |
|
159 | "IPython.utils.text", | |
|
160 | ] | |
|
134 | 161 | disallow_untyped_defs = true |
|
135 | 162 | check_untyped_defs = false |
|
136 | 163 | disallow_untyped_decorators = true |
|
137 | 164 | |
|
138 | 165 | [[tool.mypy.overrides]] |
|
139 |
module = [ |
|
|
166 | module = [ | |
|
167 | ] | |
|
140 | 168 | disallow_untyped_defs = false |
|
141 | 169 | ignore_errors = true |
|
142 | 170 | ignore_missing_imports = true |
@@ -283,46 +311,52 disallow_untyped_decorators = false | |||
|
283 | 311 | |
|
284 | 312 | [tool.pytest.ini_options] |
|
285 | 313 | addopts = [ |
|
286 |
|
|
|
287 |
|
|
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
314 | "--durations=10", | |
|
315 | "-pIPython.testing.plugin.pytest_ipdoctest", | |
|
316 | "--ipdoctest-modules", | |
|
317 | "--ignore=docs", | |
|
318 | "--ignore=examples", | |
|
319 | "--ignore=htmlcov", | |
|
320 | "--ignore=ipython_kernel", | |
|
321 | "--ignore=ipython_parallel", | |
|
322 | "--ignore=results", | |
|
323 | "--ignore=tmp", | |
|
324 | "--ignore=tools", | |
|
325 | "--ignore=traitlets", | |
|
326 | "--ignore=IPython/core/tests/daft_extension", | |
|
327 | "--ignore=IPython/sphinxext", | |
|
328 | "--ignore=IPython/terminal/pt_inputhooks", | |
|
329 | "--ignore=IPython/__main__.py", | |
|
330 | "--ignore=IPython/external/qt_for_kernel.py", | |
|
331 | "--ignore=IPython/html/widgets/widget_link.py", | |
|
332 | "--ignore=IPython/html/widgets/widget_output.py", | |
|
333 | "--ignore=IPython/terminal/console.py", | |
|
334 | "--ignore=IPython/utils/_process_cli.py", | |
|
335 | "--ignore=IPython/utils/_process_posix.py", | |
|
336 | "--ignore=IPython/utils/_process_win32_controller.py", | |
|
337 | "--ignore=IPython/utils/daemonize.py", | |
|
338 | "--ignore=IPython/utils/eventful.py", | |
|
339 | "--ignore=IPython/kernel", | |
|
340 | "--ignore=IPython/consoleapp.py", | |
|
341 | "--ignore=IPython/lib/kernel.py", | |
|
342 | "--ignore=IPython/utils/jsonutil.py", | |
|
343 | "--ignore=IPython/utils/localinterfaces.py", | |
|
344 | "--ignore=IPython/utils/log.py", | |
|
345 | "--ignore=IPython/utils/signatures.py", | |
|
346 | "--ignore=IPython/utils/version.py" | |
|
347 | ] | |
|
348 | doctest_optionflags = [ | |
|
349 | "NORMALIZE_WHITESPACE", | |
|
350 | "ELLIPSIS" | |
|
351 | ] | |
|
352 | ipdoctest_optionflags = [ | |
|
353 | "NORMALIZE_WHITESPACE", | |
|
354 | "ELLIPSIS" | |
|
319 | 355 | ] |
|
320 | doctest_optionflags = ["NORMALIZE_WHITESPACE", "ELLIPSIS"] | |
|
321 | ipdoctest_optionflags = ["NORMALIZE_WHITESPACE", "ELLIPSIS"] | |
|
322 | 356 | asyncio_mode = "strict" |
|
323 | 357 | |
|
324 | 358 | [tool.pyright] |
|
325 |
pythonPlatform |
|
|
359 | pythonPlatform="All" | |
|
326 | 360 | |
|
327 | 361 | [tool.setuptools] |
|
328 | 362 | zip-safe = false |
@@ -342,51 +376,10 namespaces = false | |||
|
342 | 376 | "IPython.testing.plugin" = ["*.txt"] |
|
343 | 377 | |
|
344 | 378 | [tool.setuptools.dynamic] |
|
345 |
version = { |
|
|
379 | version = {attr = "IPython.core.release.__version__"} | |
|
346 | 380 | |
|
347 | 381 | [tool.coverage.run] |
|
348 | 382 | omit = [ |
|
349 | 383 | # omit everything in /tmp as we run tempfile |
|
350 | 384 | "/tmp/*", |
|
351 | ] | |
|
352 | ||
|
353 | [tool.ruff.lint] | |
|
354 | extend-select = [ | |
|
355 | # "B", # flake8-bugbear | |
|
356 | # "I", # isort | |
|
357 | # that will be a problem for pytest fixture unless you swap with the usefixture decorator https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#use-fixtures-in-classes-and-modules-with-usefixtures | |
|
358 | # "ARG", # flake8-unused-arguments | |
|
359 | # "C4", # flake8-comprehensions | |
|
360 | # "EM", # flake8-errmsg | |
|
361 | # "ICN", # flake8-import-conventions | |
|
362 | # "G", # flake8-logging-format | |
|
363 | # "PGH", # pygrep-hooks | |
|
364 | # "PIE", # flake8-pie | |
|
365 | # "PL", # pylint | |
|
366 | # "PTH", # flake8-use-pathlib | |
|
367 | # "PT", # flake8-pytest-style | |
|
368 | # "RET", # flake8-return | |
|
369 | # "RUF", # Ruff-specific | |
|
370 | # "SIM", # flake8-simplify | |
|
371 | # "T20", # flake8-print | |
|
372 | # "UP", # pyupgrade | |
|
373 | # "YTT", # flake8-2020 | |
|
374 | # "EXE", # flake8-executable | |
|
375 | # "PYI", # flake8-pyi | |
|
376 | # "S", # flake8-bandit | |
|
377 | ] | |
|
378 | ignore = [ | |
|
379 | # "E501", # E501 Line too long (158 > 100 characters) | |
|
380 | # "SIM105", # SIM105 Use `contextlib.suppress(...)` | |
|
381 | # "PLR", # Design related pylint codes | |
|
382 | # "S101", # Use of `assert` detected | |
|
383 | ] | |
|
384 | unfixable = [ | |
|
385 | # Don't touch print statements | |
|
386 | "T201", | |
|
387 | # Don't touch noqa lines | |
|
388 | "RUF100", | |
|
389 | ] | |
|
390 | ||
|
391 | [tool.ruff] | |
|
392 | extend-exclude = ["tests"] | |
|
385 | ] |
General Comments 0
You need to be logged in to leave comments.
Login now