summaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py2/IPython/core/magics
diff options
context:
space:
mode:
authorNikita Slyusarev <[email protected]>2022-02-10 16:46:53 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:46:53 +0300
commit469afdc4e2587bf62ecdd096b75a0baa444c4012 (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /contrib/python/ipython/py2/IPython/core/magics
parentcd77cecfc03a3eaf87816af28a33067c4f0cdb59 (diff)
Restoring authorship annotation for Nikita Slyusarev <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/python/ipython/py2/IPython/core/magics')
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/auto.py4
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/basic.py28
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/code.py72
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/config.py4
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/display.py32
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/execution.py112
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/history.py4
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/logging.py2
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/osm.py8
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/pylab.py2
-rw-r--r--contrib/python/ipython/py2/IPython/core/magics/script.py16
11 files changed, 142 insertions, 142 deletions
diff --git a/contrib/python/ipython/py2/IPython/core/magics/auto.py b/contrib/python/ipython/py2/IPython/core/magics/auto.py
index dc229d509bb..f87bafdeb17 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/auto.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/auto.py
@@ -1,7 +1,7 @@
"""Implementation of magic functions that control various automatic behaviors.
"""
from __future__ import print_function
-from __future__ import absolute_import
+from __future__ import absolute_import
#-----------------------------------------------------------------------------
# Copyright (c) 2012 The IPython Development Team.
#
@@ -17,7 +17,7 @@ from __future__ import absolute_import
# Our own packages
from IPython.core.magic import Bunch, Magics, magics_class, line_magic
from IPython.testing.skipdoctest import skip_doctest
-from logging import error
+from logging import error
#-----------------------------------------------------------------------------
# Magic implementation classes
diff --git a/contrib/python/ipython/py2/IPython/core/magics/basic.py b/contrib/python/ipython/py2/IPython/core/magics/basic.py
index 529cdd2b654..ca69e2e698a 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/basic.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/basic.py
@@ -1,7 +1,7 @@
"""Implementation of basic magic functions."""
from __future__ import print_function
-from __future__ import absolute_import
+from __future__ import absolute_import
import argparse
import io
@@ -15,8 +15,8 @@ from IPython.utils.text import format_screen, dedent, indent
from IPython.testing.skipdoctest import skip_doctest
from IPython.utils.ipstruct import Struct
from IPython.utils.py3compat import unicode_type
-from warnings import warn
-from logging import error
+from warnings import warn
+from logging import error
class MagicsDisplay(object):
@@ -328,7 +328,7 @@ Currently the magic system has the following functions:""",
"""
def color_switch_err(name):
warn('Error changing %s color schemes.\n%s' %
- (name, sys.exc_info()[1]), stacklevel=2)
+ (name, sys.exc_info()[1]), stacklevel=2)
new_scheme = parameter_s.strip()
@@ -338,13 +338,13 @@ Currently the magic system has the following functions:""",
# local shortcut
shell = self.shell
- # Set shell colour scheme
+ # Set shell colour scheme
try:
- shell.colors = new_scheme
- shell.refresh_style()
+ shell.colors = new_scheme
+ shell.refresh_style()
except:
- color_switch_err('shell')
-
+ color_switch_err('shell')
+
# Set exception colors
try:
shell.InteractiveTB.set_colors(scheme = new_scheme)
@@ -458,12 +458,12 @@ Currently the magic system has the following functions:""",
shell.magic('xmode ' + dstore.xmode)
- # mode here is the state before we switch; switch_doctest_mode takes
- # the mode we're switching to.
- shell.switch_doctest_mode(not mode)
-
+ # mode here is the state before we switch; switch_doctest_mode takes
+ # the mode we're switching to.
+ shell.switch_doctest_mode(not mode)
+
# Store new mode and inform
- dstore.mode = bool(not mode)
+ dstore.mode = bool(not mode)
mode_label = ['OFF','ON'][dstore.mode]
print('Doctest mode is:', mode_label)
diff --git a/contrib/python/ipython/py2/IPython/core/magics/code.py b/contrib/python/ipython/py2/IPython/core/magics/code.py
index c91d24c6392..4c1a40f197e 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/code.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/code.py
@@ -1,7 +1,7 @@
"""Implementation of code management magic functions.
"""
from __future__ import print_function
-from __future__ import absolute_import
+from __future__ import absolute_import
#-----------------------------------------------------------------------------
# Copyright (c) 2012 The IPython Development Team.
#
@@ -32,9 +32,9 @@ from IPython.testing.skipdoctest import skip_doctest
from IPython.utils import py3compat
from IPython.utils.py3compat import string_types
from IPython.utils.contexts import preserve_keys
-from IPython.utils.path import get_py_filename
-from warnings import warn
-from logging import error
+from IPython.utils.path import get_py_filename
+from warnings import warn
+from logging import error
from IPython.utils.text import get_text_list
#-----------------------------------------------------------------------------
@@ -138,37 +138,37 @@ def extract_symbols(code, symbols):
return blocks, not_found
-def strip_initial_indent(lines):
- """For %load, strip indent from lines until finding an unindented line.
+def strip_initial_indent(lines):
+ """For %load, strip indent from lines until finding an unindented line.
+
+ https://github.com/ipython/ipython/issues/9775
+ """
+ indent_re = re.compile(r'\s+')
+
+ it = iter(lines)
+ first_line = next(it)
+ indent_match = indent_re.match(first_line)
+
+ if indent_match:
+ # First line was indented
+ indent = indent_match.group()
+ yield first_line[len(indent):]
+
+ for line in it:
+ if line.startswith(indent):
+ yield line[len(indent):]
+ else:
+ # Less indented than the first line - stop dedenting
+ yield line
+ break
+ else:
+ yield first_line
+
+ # Pass the remaining lines through without dedenting
+ for line in it:
+ yield line
+
- https://github.com/ipython/ipython/issues/9775
- """
- indent_re = re.compile(r'\s+')
-
- it = iter(lines)
- first_line = next(it)
- indent_match = indent_re.match(first_line)
-
- if indent_match:
- # First line was indented
- indent = indent_match.group()
- yield first_line[len(indent):]
-
- for line in it:
- if line.startswith(indent):
- yield line[len(indent):]
- else:
- # Less indented than the first line - stop dedenting
- yield line
- break
- else:
- yield first_line
-
- # Pass the remaining lines through without dedenting
- for line in it:
- yield line
-
-
class InteractivelyDefined(Exception):
"""Exception for interactively defined variable in magic_edit"""
def __init__(self, index):
@@ -219,7 +219,7 @@ class CodeMagics(Magics):
append = 'a' in opts
mode = 'a' if append else 'w'
ext = u'.ipy' if raw else u'.py'
- fname, codefrom = args[0], " ".join(args[1:])
+ fname, codefrom = args[0], " ".join(args[1:])
if not fname.endswith((u'.py',u'.ipy')):
fname += ext
file_exists = os.path.isfile(fname)
@@ -371,7 +371,7 @@ class CodeMagics(Magics):
lines = contents.split('\n')
slices = extract_code_ranges(ranges)
contents = [lines[slice(*slc)] for slc in slices]
- contents = '\n'.join(strip_initial_indent(chain.from_iterable(contents)))
+ contents = '\n'.join(strip_initial_indent(chain.from_iterable(contents)))
l = len(contents)
diff --git a/contrib/python/ipython/py2/IPython/core/magics/config.py b/contrib/python/ipython/py2/IPython/core/magics/config.py
index 184388f0645..9505697791d 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/config.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/config.py
@@ -1,7 +1,7 @@
"""Implementation of configuration-related magic functions.
"""
from __future__ import print_function
-from __future__ import absolute_import
+from __future__ import absolute_import
#-----------------------------------------------------------------------------
# Copyright (c) 2012 The IPython Development Team.
#
@@ -20,7 +20,7 @@ import re
# Our own packages
from IPython.core.error import UsageError
from IPython.core.magic import Magics, magics_class, line_magic
-from logging import error
+from logging import error
#-----------------------------------------------------------------------------
# Magic implementation classes
diff --git a/contrib/python/ipython/py2/IPython/core/magics/display.py b/contrib/python/ipython/py2/IPython/core/magics/display.py
index a0a74a62cc5..c4a8f44d9ab 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/display.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/display.py
@@ -25,32 +25,32 @@ from IPython.core.magic import (
@magics_class
class DisplayMagics(Magics):
"""Magics for displaying various output types with literals
-
- Defines javascript/latex/svg/html cell magics for writing
+
+ Defines javascript/latex/svg/html cell magics for writing
blocks in those languages, to be rendered in the frontend.
"""
-
+
+ @cell_magic
+ def js(self, line, cell):
+ """Run the cell block of Javascript code
+
+ Alias of `%%javascript`
+ """
+ self.javascript(line, cell)
+
@cell_magic
- def js(self, line, cell):
- """Run the cell block of Javascript code
-
- Alias of `%%javascript`
- """
- self.javascript(line, cell)
-
- @cell_magic
def javascript(self, line, cell):
"""Run the cell block of Javascript code"""
display(Javascript(cell))
-
-
+
+
@cell_magic
def latex(self, line, cell):
"""Render the cell as a block of latex
-
+
The subset of latex which is support depends on the implementation in
- the client. In the Jupyter Notebook, this magic only renders the subset
- of latex defined by MathJax
+ the client. In the Jupyter Notebook, this magic only renders the subset
+ of latex defined by MathJax
[here](https://docs.mathjax.org/en/v2.5-latest/tex.html)."""
display(Latex(cell))
diff --git a/contrib/python/ipython/py2/IPython/core/magics/execution.py b/contrib/python/ipython/py2/IPython/core/magics/execution.py
index 2597cab3fc5..3734b0cdae0 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/execution.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/execution.py
@@ -5,7 +5,7 @@
# Distributed under the terms of the Modified BSD License.
from __future__ import print_function
-from __future__ import absolute_import
+from __future__ import absolute_import
import ast
import bdb
@@ -28,7 +28,7 @@ except ImportError:
except ImportError:
profile = pstats = None
-from IPython.core import oinspect
+from IPython.core import oinspect
from IPython.core import magic_arguments
from IPython.core import page
from IPython.core.error import UsageError
@@ -42,10 +42,10 @@ from IPython.utils.contexts import preserve_keys
from IPython.utils.capture import capture_output
from IPython.utils.ipstruct import Struct
from IPython.utils.module_paths import find_mod
-from IPython.utils.path import get_py_filename, shellglob
+from IPython.utils.path import get_py_filename, shellglob
from IPython.utils.timing import clock, clock2
-from warnings import warn
-from logging import error
+from warnings import warn
+from logging import error
if PY3:
from io import StringIO
@@ -61,12 +61,12 @@ class TimeitResult(object):
"""
Object returned by the timeit magic with info about the run.
- Contains the following attributes :
+ Contains the following attributes :
- loops: (int) number of loops done per measurement
- repeat: (int) number of times the measurement has been repeated
- best: (float) best execution time / number
- all_runs: (list of float) execution time of each run (in s)
+ loops: (int) number of loops done per measurement
+ repeat: (int) number of times the measurement has been repeated
+ best: (float) best execution time / number
+ all_runs: (list of float) execution time of each run (in s)
compile_time: (float) time of statement compilation (s)
"""
@@ -705,54 +705,54 @@ python-profiler package from non-free.""")
try:
stats = None
- if 'p' in opts:
- stats = self._run_with_profiler(code, opts, code_ns)
- else:
- if 'd' in opts:
- bp_file, bp_line = parse_breakpoint(
- opts.get('b', ['1'])[0], filename)
- self._run_with_debugger(
- code, code_ns, filename, bp_line, bp_file)
+ if 'p' in opts:
+ stats = self._run_with_profiler(code, opts, code_ns)
+ else:
+ if 'd' in opts:
+ bp_file, bp_line = parse_breakpoint(
+ opts.get('b', ['1'])[0], filename)
+ self._run_with_debugger(
+ code, code_ns, filename, bp_line, bp_file)
else:
- if 'm' in opts:
- def run():
- self.shell.safe_run_module(modulename, prog_ns)
+ if 'm' in opts:
+ def run():
+ self.shell.safe_run_module(modulename, prog_ns)
else:
- if runner is None:
- runner = self.default_runner
- if runner is None:
- runner = self.shell.safe_execfile
+ if runner is None:
+ runner = self.default_runner
+ if runner is None:
+ runner = self.shell.safe_execfile
- def run():
- runner(filename, prog_ns, prog_ns,
- exit_ignore=exit_ignore)
+ def run():
+ runner(filename, prog_ns, prog_ns,
+ exit_ignore=exit_ignore)
- if 't' in opts:
- # timed execution
- try:
- nruns = int(opts['N'][0])
- if nruns < 1:
- error('Number of runs must be >=1')
- return
- except (KeyError):
- nruns = 1
- self._run_with_timing(run, nruns)
- else:
- # regular execution
- run()
+ if 't' in opts:
+ # timed execution
+ try:
+ nruns = int(opts['N'][0])
+ if nruns < 1:
+ error('Number of runs must be >=1')
+ return
+ except (KeyError):
+ nruns = 1
+ self._run_with_timing(run, nruns)
+ else:
+ # regular execution
+ run()
- if 'i' in opts:
- self.shell.user_ns['__name__'] = __name__save
- else:
- # update IPython interactive namespace
+ if 'i' in opts:
+ self.shell.user_ns['__name__'] = __name__save
+ else:
+ # update IPython interactive namespace
- # Some forms of read errors on the file may mean the
- # __name__ key was never set; using pop we don't have to
- # worry about a possible KeyError.
- prog_ns.pop('__name__', None)
+ # Some forms of read errors on the file may mean the
+ # __name__ key was never set; using pop we don't have to
+ # worry about a possible KeyError.
+ prog_ns.pop('__name__', None)
- with preserve_keys(self.shell.user_ns, '__file__'):
- self.shell.user_ns.update(prog_ns)
+ with preserve_keys(self.shell.user_ns, '__file__'):
+ self.shell.user_ns.update(prog_ns)
finally:
# It's a bit of a mystery why, but __builtins__ can change from
# being a module to becoming a dict missing some key data after
@@ -801,11 +801,11 @@ python-profiler package from non-free.""")
If the break point given by `bp_line` is not valid.
"""
- deb = self.shell.InteractiveTB.pdb
- if not deb:
- self.shell.InteractiveTB.pdb = self.shell.InteractiveTB.debugger_cls()
- deb = self.shell.InteractiveTB.pdb
-
+ deb = self.shell.InteractiveTB.pdb
+ if not deb:
+ self.shell.InteractiveTB.pdb = self.shell.InteractiveTB.debugger_cls()
+ deb = self.shell.InteractiveTB.pdb
+
# deb.checkline() fails if deb.curframe exists but is None; it can
# handle it not existing. https://github.com/ipython/ipython/issues/10028
if hasattr(deb, 'curframe'):
diff --git a/contrib/python/ipython/py2/IPython/core/magics/history.py b/contrib/python/ipython/py2/IPython/core/magics/history.py
index d24bfd2a4ec..5967591394a 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/history.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/history.py
@@ -15,7 +15,7 @@ from __future__ import print_function
# Stdlib
import os
-import sys
+import sys
from io import open as io_open
# Our own packages
@@ -148,7 +148,7 @@ class HistoryMagics(Magics):
# Check if output to specific file was requested.
outfname = args.filename
if not outfname:
- outfile = sys.stdout # default
+ outfile = sys.stdout # default
# We don't want to close stdout at the end!
close_at_end = False
else:
diff --git a/contrib/python/ipython/py2/IPython/core/magics/logging.py b/contrib/python/ipython/py2/IPython/core/magics/logging.py
index 22500f81560..90214ab54ab 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/logging.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/logging.py
@@ -18,7 +18,7 @@ import sys
# Our own packages
from IPython.core.magic import Magics, magics_class, line_magic
-from warnings import warn
+from warnings import warn
from IPython.utils.py3compat import str_to_unicode
#-----------------------------------------------------------------------------
diff --git a/contrib/python/ipython/py2/IPython/core/magics/osm.py b/contrib/python/ipython/py2/IPython/core/magics/osm.py
index f48259ee025..352cf2d4513 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/osm.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/osm.py
@@ -323,7 +323,7 @@ class OSMagics(Magics):
else:
- opts, ps = self.parse_options(parameter_s, 'qb', mode='string')
+ opts, ps = self.parse_options(parameter_s, 'qb', mode='string')
# jump to previous
if ps == '-':
try:
@@ -437,7 +437,7 @@ class OSMagics(Magics):
"""
dir_s = self.shell.dir_stack
- tgt = os.path.expanduser(parameter_s)
+ tgt = os.path.expanduser(parameter_s)
cwd = py3compat.getcwd().replace(self.shell.home_dir,'~')
if tgt:
self.cd(parameter_s)
@@ -775,8 +775,8 @@ class OSMagics(Magics):
The file will be overwritten unless the -a (--append) flag is specified.
"""
args = magic_arguments.parse_argstring(self.writefile, line)
- filename = os.path.expanduser(args.filename)
-
+ filename = os.path.expanduser(args.filename)
+
if os.path.exists(filename):
if args.append:
print("Appending to %s" % filename)
diff --git a/contrib/python/ipython/py2/IPython/core/magics/pylab.py b/contrib/python/ipython/py2/IPython/core/magics/pylab.py
index 62308d5e494..6c5cd68a597 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/pylab.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/pylab.py
@@ -18,7 +18,7 @@ from traitlets.config.application import Application
from IPython.core import magic_arguments
from IPython.core.magic import Magics, magics_class, line_magic
from IPython.testing.skipdoctest import skip_doctest
-from warnings import warn
+from warnings import warn
from IPython.core.pylabtools import backends
#-----------------------------------------------------------------------------
diff --git a/contrib/python/ipython/py2/IPython/core/magics/script.py b/contrib/python/ipython/py2/IPython/core/magics/script.py
index bfcad64919a..3fbddc38a80 100644
--- a/contrib/python/ipython/py2/IPython/core/magics/script.py
+++ b/contrib/python/ipython/py2/IPython/core/magics/script.py
@@ -1,8 +1,8 @@
"""Magic functions for running cells in various scripts."""
from __future__ import print_function
-# Copyright (c) IPython Development Team.
-# Distributed under the terms of the Modified BSD License.
+# Copyright (c) IPython Development Team.
+# Distributed under the terms of the Modified BSD License.
import errno
import os
@@ -19,7 +19,7 @@ from IPython.core.magic import (
from IPython.lib.backgroundjobs import BackgroundJobManager
from IPython.utils import py3compat
from IPython.utils.process import arg_split
-from traitlets import List, Dict, default
+from traitlets import List, Dict, default
#-----------------------------------------------------------------------------
# Magic implementation classes
@@ -68,7 +68,7 @@ class ScriptMagics(Magics):
with a program in a subprocess, and registers a few top-level
magics that call %%script with common interpreters.
"""
- script_magics = List(
+ script_magics = List(
help="""Extra script cell magics to define
This generates simple wrappers of `%%script foo` as `%%foo`.
@@ -76,8 +76,8 @@ class ScriptMagics(Magics):
If you want to add script magics that aren't on your path,
specify them in script_paths
""",
- ).tag(config=True)
- @default('script_magics')
+ ).tag(config=True)
+ @default('script_magics')
def _script_magics_default(self):
"""default to a common list of programs"""
@@ -98,13 +98,13 @@ class ScriptMagics(Magics):
return defaults
- script_paths = Dict(
+ script_paths = Dict(
help="""Dict mapping short 'ruby' names to full paths, such as '/opt/secret/bin/ruby'
Only necessary for items in script_magics where the default path will not
find the right interpreter.
"""
- ).tag(config=True)
+ ).tag(config=True)
def __init__(self, shell=None):
super(ScriptMagics, self).__init__(shell=shell)