aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/ipython/py3/IPython/core
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-11-09 12:07:32 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-11-09 12:17:11 +0300
commit381a9a45520ba56577e90032e086e0168a03b956 (patch)
treef49a7f9feff6df2c4916cf20205e9c22cb26dfd2 /contrib/python/ipython/py3/IPython/core
parent66839121782766f516d9a33982e1968d319e3395 (diff)
downloadydb-381a9a45520ba56577e90032e086e0168a03b956.tar.gz
Intermediate changes
commit_hash:2e32c346f257520a6c3629b88dc628744d3d3386
Diffstat (limited to 'contrib/python/ipython/py3/IPython/core')
-rw-r--r--contrib/python/ipython/py3/IPython/core/completer.py4
-rw-r--r--contrib/python/ipython/py3/IPython/core/completerlib.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/debugger.py4
-rw-r--r--contrib/python/ipython/py3/IPython/core/display.py116
-rw-r--r--contrib/python/ipython/py3/IPython/core/guarded_eval.py8
-rw-r--r--contrib/python/ipython/py3/IPython/core/inputsplitter.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/interactiveshell.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/magics/ast_mod.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/magics/code.py4
-rw-r--r--contrib/python/ipython/py3/IPython/core/magics/execution.py20
-rw-r--r--contrib/python/ipython/py3/IPython/core/magics/packaging.py17
-rw-r--r--contrib/python/ipython/py3/IPython/core/oinspect.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/page.py4
-rw-r--r--contrib/python/ipython/py3/IPython/core/prefilter.py6
-rw-r--r--contrib/python/ipython/py3/IPython/core/pylabtools.py2
-rw-r--r--contrib/python/ipython/py3/IPython/core/release.py19
16 files changed, 156 insertions, 58 deletions
diff --git a/contrib/python/ipython/py3/IPython/core/completer.py b/contrib/python/ipython/py3/IPython/core/completer.py
index c639ce07a1..8f843dd584 100644
--- a/contrib/python/ipython/py3/IPython/core/completer.py
+++ b/contrib/python/ipython/py3/IPython/core/completer.py
@@ -159,7 +159,7 @@ By default results from all matchers are combined, in the order determined by
their priority. Matchers can request to suppress results from subsequent
matchers by setting ``suppress`` to ``True`` in the ``MatcherResult``.
-When multiple matchers simultaneously request surpression, the results from of
+When multiple matchers simultaneously request suppression, the results from of
the matcher with higher priority will be returned.
Sometimes it is desirable to suppress most but not all other matchers;
@@ -2652,7 +2652,7 @@ class IPCompleter(Completer):
)
can_close_quote = can_close_quote and self.auto_close_dict_keys
- # fast path if closing qoute should be appended but not suffix is allowed
+ # fast path if closing quote should be appended but not suffix is allowed
if not can_close_quote and not can_close_bracket and closing_quote:
return [leading + k for k in matches]
diff --git a/contrib/python/ipython/py3/IPython/core/completerlib.py b/contrib/python/ipython/py3/IPython/core/completerlib.py
index 05f39e5015..4612b326de 100644
--- a/contrib/python/ipython/py3/IPython/core/completerlib.py
+++ b/contrib/python/ipython/py3/IPython/core/completerlib.py
@@ -214,7 +214,7 @@ def is_possible_submodule(module, attr):
try:
obj = getattr(module, attr)
except AttributeError:
- # Is possilby an unimported submodule
+ # Is possibly an unimported submodule
return True
except TypeError:
# https://github.com/ipython/ipython/issues/9678
diff --git a/contrib/python/ipython/py3/IPython/core/debugger.py b/contrib/python/ipython/py3/IPython/core/debugger.py
index e7a0b8fb55..84d3de8c5b 100644
--- a/contrib/python/ipython/py3/IPython/core/debugger.py
+++ b/contrib/python/ipython/py3/IPython/core/debugger.py
@@ -19,7 +19,7 @@ Global Configuration
--------------------
The IPython debugger will by read the global ``~/.pdbrc`` file.
-That is to say you can list all comands supported by ipdb in your `~/.pdbrc`
+That is to say you can list all commands supported by ipdb in your `~/.pdbrc`
configuration file, to globally configure pdb.
Example::
@@ -177,7 +177,7 @@ def BdbQuit_excepthook(et, ev, tb, excepthook=None):
parameter.
"""
raise ValueError(
- "`BdbQuit_excepthook` is deprecated since version 5.1. It is still arround only because it is still imported by ipdb.",
+ "`BdbQuit_excepthook` is deprecated since version 5.1. It is still around only because it is still imported by ipdb.",
)
diff --git a/contrib/python/ipython/py3/IPython/core/display.py b/contrib/python/ipython/py3/IPython/core/display.py
index 5c4557b150..c3c44016f4 100644
--- a/contrib/python/ipython/py3/IPython/core/display.py
+++ b/contrib/python/ipython/py3/IPython/core/display.py
@@ -21,13 +21,35 @@ from IPython.testing.skipdoctest import skip_doctest
from . import display_functions
-__all__ = ['display_pretty', 'display_html', 'display_markdown',
- 'display_svg', 'display_png', 'display_jpeg', 'display_latex', 'display_json',
- 'display_javascript', 'display_pdf', 'DisplayObject', 'TextDisplayObject',
- 'Pretty', 'HTML', 'Markdown', 'Math', 'Latex', 'SVG', 'ProgressBar', 'JSON',
- 'GeoJSON', 'Javascript', 'Image', 'set_matplotlib_formats',
- 'set_matplotlib_close',
- 'Video']
+__all__ = [
+ "display_pretty",
+ "display_html",
+ "display_markdown",
+ "display_svg",
+ "display_png",
+ "display_jpeg",
+ "display_webp",
+ "display_latex",
+ "display_json",
+ "display_javascript",
+ "display_pdf",
+ "DisplayObject",
+ "TextDisplayObject",
+ "Pretty",
+ "HTML",
+ "Markdown",
+ "Math",
+ "Latex",
+ "SVG",
+ "ProgressBar",
+ "JSON",
+ "GeoJSON",
+ "Javascript",
+ "Image",
+ "set_matplotlib_formats",
+ "set_matplotlib_close",
+ "Video",
+]
_deprecated_names = ["display", "clear_output", "publish_display_data", "update_display", "DisplayHandle"]
@@ -200,6 +222,23 @@ def display_jpeg(*objs, **kwargs):
_display_mimetype('image/jpeg', objs, **kwargs)
+def display_webp(*objs, **kwargs):
+ """Display the WEBP representation of an object.
+
+ Parameters
+ ----------
+ *objs : object
+ The Python objects to display, or if raw=True raw JPEG data to
+ display.
+ raw : bool
+ Are the data objects raw data or Python objects that need to be
+ formatted before display? [default: False]
+ metadata : dict (optional)
+ Metadata to be associated with the specific mimetype output.
+ """
+ _display_mimetype("image/webp", objs, **kwargs)
+
+
def display_latex(*objs, **kwargs):
"""Display the LaTeX representation of an object.
@@ -776,9 +815,14 @@ class Javascript(TextDisplayObject):
r += _lib_t2*len(self.lib)
return r
-# constants for identifying png/jpeg data
-_PNG = b'\x89PNG\r\n\x1a\n'
-_JPEG = b'\xff\xd8'
+
+# constants for identifying png/jpeg/gif/webp data
+_PNG = b"\x89PNG\r\n\x1a\n"
+_JPEG = b"\xff\xd8"
+_GIF1 = b"GIF87a"
+_GIF2 = b"GIF89a"
+_WEBP = b"WEBP"
+
def _pngxy(data):
"""read the (width, height) from a PNG header"""
@@ -786,6 +830,7 @@ def _pngxy(data):
# next 8 bytes are width/height
return struct.unpack('>ii', data[ihdr+4:ihdr+12])
+
def _jpegxy(data):
"""read the (width, height) from a JPEG header"""
# adapted from http://www.64lines.com/jpeg-width-height
@@ -805,22 +850,45 @@ def _jpegxy(data):
h, w = struct.unpack('>HH', data[iSOF+5:iSOF+9])
return w, h
+
def _gifxy(data):
"""read the (width, height) from a GIF header"""
return struct.unpack('<HH', data[6:10])
+def _webpxy(data):
+ """read the (width, height) from a WEBP header"""
+ if data[12:16] == b"VP8 ":
+ width, height = struct.unpack("<HH", data[24:30])
+ width = width & 0x3FFF
+ height = height & 0x3FFF
+ return (width, height)
+ elif data[12:16] == b"VP8L":
+ size_info = struct.unpack("<I", data[21:25])[0]
+ width = 1 + ((size_info & 0x3F) << 8) | (size_info >> 24)
+ height = 1 + (
+ (((size_info >> 8) & 0xF) << 10)
+ | (((size_info >> 14) & 0x3FC) << 2)
+ | ((size_info >> 22) & 0x3)
+ )
+ return (width, height)
+ else:
+ raise ValueError("Not a valid WEBP header")
+
+
class Image(DisplayObject):
- _read_flags = 'rb'
- _FMT_JPEG = u'jpeg'
- _FMT_PNG = u'png'
- _FMT_GIF = u'gif'
- _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG, _FMT_GIF]
+ _read_flags = "rb"
+ _FMT_JPEG = "jpeg"
+ _FMT_PNG = "png"
+ _FMT_GIF = "gif"
+ _FMT_WEBP = "webp"
+ _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG, _FMT_GIF, _FMT_WEBP]
_MIMETYPES = {
- _FMT_PNG: 'image/png',
- _FMT_JPEG: 'image/jpeg',
- _FMT_GIF: 'image/gif',
+ _FMT_PNG: "image/png",
+ _FMT_JPEG: "image/jpeg",
+ _FMT_GIF: "image/gif",
+ _FMT_WEBP: "image/webp",
}
def __init__(
@@ -837,7 +905,7 @@ class Image(DisplayObject):
metadata=None,
alt=None,
):
- """Create a PNG/JPEG/GIF image object given raw data.
+ """Create a PNG/JPEG/GIF/WEBP image object given raw data.
When this object is returned by an input cell or passed to the
display function, it will result in the image being displayed
@@ -858,7 +926,7 @@ class Image(DisplayObject):
Images from a file are always embedded.
format : unicode
- The format of the image data (png/jpeg/jpg/gif). If a filename or URL is given
+ The format of the image data (png/jpeg/jpg/gif/webp). If a filename or URL is given
for format will be inferred from the filename extension.
embed : bool
@@ -942,6 +1010,8 @@ class Image(DisplayObject):
format = self._FMT_PNG
elif ext == u'gif':
format = self._FMT_GIF
+ elif ext == "webp":
+ format = self._FMT_WEBP
else:
format = ext.lower()
elif isinstance(data, bytes):
@@ -949,6 +1019,12 @@ class Image(DisplayObject):
# only if format has not been specified.
if data[:2] == _JPEG:
format = self._FMT_JPEG
+ elif data[:8] == _PNG:
+ format = self._FMT_PNG
+ elif data[8:12] == _WEBP:
+ format = self._FMT_WEBP
+ elif data[:6] == _GIF1 or data[:6] == _GIF2:
+ format = self._FMT_GIF
# failed to detect format, default png
if format is None:
diff --git a/contrib/python/ipython/py3/IPython/core/guarded_eval.py b/contrib/python/ipython/py3/IPython/core/guarded_eval.py
index d8ac9928af..39fe853f58 100644
--- a/contrib/python/ipython/py3/IPython/core/guarded_eval.py
+++ b/contrib/python/ipython/py3/IPython/core/guarded_eval.py
@@ -132,7 +132,7 @@ def _get_external(module_name: str, access_path: Sequence[str]):
Raises:
* `KeyError` if module is removed not found, and
- * `AttributeError` if acess path does not match an exported object
+ * `AttributeError` if access path does not match an exported object
"""
member_type = sys.modules[module_name]
for attr in access_path:
@@ -235,7 +235,7 @@ class SelectivePolicy(EvaluationPolicy):
accept = has_original_attr and has_original_attribute
if accept:
- # We still need to check for overriden properties.
+ # We still need to check for overridden properties.
value_class = type(value)
if not hasattr(value_class, attr):
@@ -332,7 +332,7 @@ class EvaluationContext(NamedTuple):
evaluation: Literal[
"forbidden", "minimal", "limited", "unsafe", "dangerous"
] = "forbidden"
- #: Whether the evalution of code takes place inside of a subscript.
+ #: Whether the evaluation of code takes place inside of a subscript.
#: Useful for evaluating ``:-1, 'col'`` in ``df[:-1, 'col']``.
in_subscript: bool = False
@@ -373,7 +373,7 @@ def guarded_eval(code: str, context: EvaluationContext):
# getitem at all, for example it fails on simple `[0][1]`
if context.in_subscript:
- # syntatic sugar for ellipsis (:) is only available in susbcripts
+ # syntactic sugar for ellipsis (:) is only available in subscripts
# so we need to trick the ast parser into thinking that we have
# a subscript, but we need to be able to later recognise that we did
# it so we can ignore the actual __getitem__ operation
diff --git a/contrib/python/ipython/py3/IPython/core/inputsplitter.py b/contrib/python/ipython/py3/IPython/core/inputsplitter.py
index af7a12e6e0..092f21408a 100644
--- a/contrib/python/ipython/py3/IPython/core/inputsplitter.py
+++ b/contrib/python/ipython/py3/IPython/core/inputsplitter.py
@@ -97,7 +97,7 @@ def num_ini_spaces(s):
"""
warnings.warn(
"`num_ini_spaces` is Pending Deprecation since IPython 8.17."
- "It is considered fro removal in in future version. "
+ "It is considered for removal in in future version. "
"Please open an issue if you believe it should be kept.",
stacklevel=2,
category=PendingDeprecationWarning,
diff --git a/contrib/python/ipython/py3/IPython/core/interactiveshell.py b/contrib/python/ipython/py3/IPython/core/interactiveshell.py
index d05cb451f8..07fb807760 100644
--- a/contrib/python/ipython/py3/IPython/core/interactiveshell.py
+++ b/contrib/python/ipython/py3/IPython/core/interactiveshell.py
@@ -1627,7 +1627,7 @@ class InteractiveShell(SingletonConfigurable):
Returns
-------
parts_ok: bool
- wether we were properly able to parse parts.
+ whether we were properly able to parse parts.
parts: list of str
extracted parts
diff --git a/contrib/python/ipython/py3/IPython/core/magics/ast_mod.py b/contrib/python/ipython/py3/IPython/core/magics/ast_mod.py
index fa54791443..dc3c5bc768 100644
--- a/contrib/python/ipython/py3/IPython/core/magics/ast_mod.py
+++ b/contrib/python/ipython/py3/IPython/core/magics/ast_mod.py
@@ -5,7 +5,7 @@ with ast-transformers it is not easy to directly manipulate ast.
IPython has pre-code and post-code hooks, but are ran from within the IPython
-machinery so may be inappropriate, for example for performance mesurement.
+machinery so may be inappropriate, for example for performance measurement.
This module give you tools to simplify this, and expose 2 classes:
diff --git a/contrib/python/ipython/py3/IPython/core/magics/code.py b/contrib/python/ipython/py3/IPython/core/magics/code.py
index 4f1574dcef..834ca51473 100644
--- a/contrib/python/ipython/py3/IPython/core/magics/code.py
+++ b/contrib/python/ipython/py3/IPython/core/magics/code.py
@@ -153,7 +153,9 @@ def strip_initial_indent(lines):
for line in it:
if line.startswith(indent):
- yield line[len(indent):]
+ yield line[len(indent) :]
+ elif line in ("\n", "\r\n") or len(line) == 0:
+ yield line
else:
# Less indented than the first line - stop dedenting
yield line
diff --git a/contrib/python/ipython/py3/IPython/core/magics/execution.py b/contrib/python/ipython/py3/IPython/core/magics/execution.py
index abfc4cbda7..3aa0a27fc2 100644
--- a/contrib/python/ipython/py3/IPython/core/magics/execution.py
+++ b/contrib/python/ipython/py3/IPython/core/magics/execution.py
@@ -195,12 +195,16 @@ class ExecutionMagics(Magics):
"""Run a statement through the python code profiler.
- Usage, in line mode:
+ **Usage, in line mode:**
+
%prun [options] statement
- Usage, in cell mode:
+ **Usage, in cell mode:**
+
%%prun [options] [statement]
+
code...
+
code...
In cell mode, the additional code lines are appended to the (possibly
@@ -1028,11 +1032,16 @@ class ExecutionMagics(Magics):
def timeit(self, line='', cell=None, local_ns=None):
"""Time execution of a Python statement or expression
- Usage, in line mode:
+ **Usage, in line mode:**
+
%timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] statement
- or in cell mode:
+
+ **or in cell mode:**
+
%%timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] setup_code
+
code
+
code...
Time execution of a Python statement or expression using the timeit
@@ -1046,6 +1055,7 @@ class ExecutionMagics(Magics):
body has access to any variables created in the setup code.
Options:
+
-n<N>: execute the given statement <N> times in a loop. If <N> is not
provided, <N> is determined so as to get sufficient accuracy.
@@ -1066,7 +1076,7 @@ class ExecutionMagics(Magics):
-q: Quiet, do not print result.
-o: return a TimeitResult that can be stored in a variable to inspect
- the result in more details.
+ the result in more details.
.. versionchanged:: 7.3
User variables are no longer expanded,
diff --git a/contrib/python/ipython/py3/IPython/core/magics/packaging.py b/contrib/python/ipython/py3/IPython/core/magics/packaging.py
index 09d4117270..ed1c1274f3 100644
--- a/contrib/python/ipython/py3/IPython/core/magics/packaging.py
+++ b/contrib/python/ipython/py3/IPython/core/magics/packaging.py
@@ -162,3 +162,20 @@ class PackagingMagics(Magics):
"""
micromamba = _get_conda_like_executable("micromamba")
self._run_command(micromamba, line)
+
+ @line_magic
+ def uv(self, line):
+ """Run the uv package manager within the current kernel.
+
+ Usage:
+ %uv pip install [pkgs]
+ """
+ python = sys.executable
+ if sys.platform == "win32":
+ python = '"' + python + '"'
+ else:
+ python = shlex.quote(python)
+
+ self.shell.system(" ".join([python, "-m", "uv", line]))
+
+ print("Note: you may need to restart the kernel to use updated packages.")
diff --git a/contrib/python/ipython/py3/IPython/core/oinspect.py b/contrib/python/ipython/py3/IPython/core/oinspect.py
index 8aa8429e5d..a4fdc28bde 100644
--- a/contrib/python/ipython/py3/IPython/core/oinspect.py
+++ b/contrib/python/ipython/py3/IPython/core/oinspect.py
@@ -460,7 +460,7 @@ class Inspector(Colorable):
mime_hooks = traitlets.Dict(
config=True,
- help="dictionary of mime to callable to add informations into help mimebundle dict",
+ help="dictionary of mime to callable to add information into help mimebundle dict",
).tag(config=True)
def __init__(
diff --git a/contrib/python/ipython/py3/IPython/core/page.py b/contrib/python/ipython/py3/IPython/core/page.py
index 31b314ec46..2eb6c399b3 100644
--- a/contrib/python/ipython/py3/IPython/core/page.py
+++ b/contrib/python/ipython/py3/IPython/core/page.py
@@ -125,7 +125,7 @@ def _detect_screen_size(screen_lines_def):
# print('***Screen size:',screen_lines_real,'lines x',
# screen_cols,'columns.') # dbg
-def pager_page(strng, start=0, screen_lines=0, pager_cmd=None):
+def pager_page(strng, start=0, screen_lines=0, pager_cmd=None) -> None:
"""Display a string, piping through a pager after a certain length.
strng can be a mime-bundle dict, supplying multiple representations,
@@ -239,7 +239,7 @@ def pager_page(strng, start=0, screen_lines=0, pager_cmd=None):
page_dumb(strng,screen_lines=screen_lines)
-def page(data, start=0, screen_lines=0, pager_cmd=None):
+def page(data, start: int = 0, screen_lines: int = 0, pager_cmd=None):
"""Display content in a pager, piping through a pager after a certain length.
data can be a mime-bundle dict, supplying multiple representations,
diff --git a/contrib/python/ipython/py3/IPython/core/prefilter.py b/contrib/python/ipython/py3/IPython/core/prefilter.py
index a29df0c27a..fc7b1c3416 100644
--- a/contrib/python/ipython/py3/IPython/core/prefilter.py
+++ b/contrib/python/ipython/py3/IPython/core/prefilter.py
@@ -512,8 +512,10 @@ class AutocallChecker(PrefilterChecker):
callable(oinfo.obj)
and (not self.exclude_regexp.match(line_info.the_rest))
and self.function_name_regexp.match(line_info.ifun)
- and line_info.raw_the_rest.startswith(" ")
- or not line_info.raw_the_rest.strip()
+ and (
+ line_info.raw_the_rest.startswith(" ")
+ or not line_info.raw_the_rest.strip()
+ )
):
return self.prefilter_manager.get_handler_by_name("auto")
else:
diff --git a/contrib/python/ipython/py3/IPython/core/pylabtools.py b/contrib/python/ipython/py3/IPython/core/pylabtools.py
index 5c926a9c10..ad2fc74e9e 100644
--- a/contrib/python/ipython/py3/IPython/core/pylabtools.py
+++ b/contrib/python/ipython/py3/IPython/core/pylabtools.py
@@ -528,7 +528,7 @@ def _list_matplotlib_backends_and_gui_loops() -> list[str]:
# Matplotlib and IPython do not always use the same gui framework name.
-# Always use the approprate one of these conversion functions when passing a
+# Always use the appropriate one of these conversion functions when passing a
# gui framework name to/from Matplotlib.
def _convert_gui_to_matplotlib(gui: str | None) -> str | None:
if gui and gui.lower() == "osx":
diff --git a/contrib/python/ipython/py3/IPython/core/release.py b/contrib/python/ipython/py3/IPython/core/release.py
index fb5a54da6a..d9eb28aa95 100644
--- a/contrib/python/ipython/py3/IPython/core/release.py
+++ b/contrib/python/ipython/py3/IPython/core/release.py
@@ -16,7 +16,7 @@
# release. 'dev' as a _version_extra string means this is a development
# version
_version_major = 8
-_version_minor = 28
+_version_minor = 29
_version_patch = 0
_version_extra = ".dev"
# _version_extra = "rc1"
@@ -32,22 +32,13 @@ if _version_extra:
version = __version__ # backwards compatibility name
version_info = (_version_major, _version_minor, _version_patch, _version_extra)
-# Change this when incrementing the kernel protocol version
-kernel_protocol_version_info = (5, 0)
-kernel_protocol_version = "%i.%i" % kernel_protocol_version_info
license = "BSD-3-Clause"
-authors = {'Fernando' : ('Fernando Perez','fperez.net@gmail.com'),
- 'Janko' : ('Janko Hauser','jhauser@zscout.de'),
- 'Nathan' : ('Nathaniel Gray','n8gray@caltech.edu'),
- 'Ville' : ('Ville Vainio','vivainio@gmail.com'),
- 'Brian' : ('Brian E Granger', 'ellisonbg@gmail.com'),
- 'Min' : ('Min Ragan-Kelley', 'benjaminrk@gmail.com'),
- 'Thomas' : ('Thomas A. Kluyver', 'takowl@gmail.com'),
- 'Jorgen' : ('Jorgen Stenarson', 'jorgen.stenarson@bostream.nu'),
- 'Matthias' : ('Matthias Bussonnier', 'bussonniermatthias@gmail.com'),
- }
+authors = {
+ "Fernando": ("Fernando Perez", "fperez.net@gmail.com"),
+ "M": ("M Bussonnier", "mbussonnier@gmail.com"),
+}
author = 'The IPython Development Team'