repo
stringclasses
454 values
file_path
stringlengths
5
201
extension
stringclasses
1 value
content
stringlengths
8
509k
num_lines
int64
3
16.9k
size_bytes
int64
8
511k
ipython
tests/test_exceptiongroup_tb.py
.py
import unittest import re from IPython.utils.capture import capture_output import sys import pytest from tempfile import TemporaryDirectory from IPython.testing import tools as tt def _exceptiongroup_common( outer_chain: str, inner_chain: str, native: bool, ) -> None: pre_raise = "exceptiongroup." if ...
109
3,410
ipython
tests/test_data.py
.py
"""Tests for IPython.utils.data.""" import warnings import pytest from IPython.utils.data import chop, uniq_stable # --------------------------------------------------------------------------- # chop # --------------------------------------------------------------------------- def test_chop_even_division(): ...
77
2,011
ipython
tests/test_cve.py
.py
""" Test that CVEs stay fixed. """ from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory from pathlib import Path import random import sys import os import string import subprocess def test_cve_2022_21699(): """ Here we test CVE-2022-21699. We create a temporary directory, cd i...
67
1,999
ipython
tests/test_utils_terminal.py
.py
"""Tests for IPython.utils.terminal.""" import importlib import os import pytest from IPython.testing.decorators import skip_win32 from IPython.utils import terminal @pytest.fixture def reload_with_term(): """Reload the terminal module with a given TERM, then restore it.""" def reload(term_value): ...
141
4,970
ipython
tests/test_magic_arguments.py
.py
# ----------------------------------------------------------------------------- # Copyright (C) 2010-2011, IPython Development Team. # # Distributed under the terms of the Modified BSD License. # # The full license is in the file COPYING.txt, distributed with this software. # -------------------------------------------...
146
4,737
ipython
tests/test_display_trap.py
.py
"""Tests for IPython.core.display_trap.""" import sys import pytest from IPython.core.display_trap import DisplayTrap def _custom_hook(value): pass def test_display_trap_sets_displayhook(): original_hook = sys.displayhook trap = DisplayTrap(hook=_custom_hook) with trap: assert sys.display...
73
1,897
ipython
tests/test_latextools.py
.py
"""Tests for IPython.utils.path.py""" # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. from contextlib import contextmanager from unittest.mock import patch import pytest from IPython.lib import latextools from IPython.testing.decorators import ( onlyif_cmds_e...
210
5,715
ipython
tests/test_tokenutil.py
.py
"""Tests for tokenutil""" # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import io import sys import textwrap import tokenize import pytest from IPython.utils.tokenutil import ( generate_tokens_catch_errors, line_at_cursor, token_at_cursor, ) def e...
222
6,612
ipython
tests/test_tools.py
.py
# encoding: utf-8 """ Tests for testing.tools """ # ----------------------------------------------------------------------------- # Copyright (C) 2008-2011 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this softwa...
138
3,815
ipython
tests/test_extension.py
.py
import os.path from tempfile import TemporaryDirectory import IPython.testing.tools as tt from IPython.utils.syspathcontext import prepended_to_syspath ext1_content = """ def load_ipython_extension(ip): print("Running ext1 load") def unload_ipython_extension(ip): print("Running ext1 unload") """ ext2_conte...
97
2,907
ipython
tests/test_hooks.py
.py
# -*- coding: utf-8 -*- """Tests for CommandChainDispatcher.""" # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- import pytest from IPython.core.error import TryNext from IPython.core.hooks import...
148
3,910
ipython
tests/test_profile.py
.py
# coding: utf-8 """Tests for profile-related functions. Currently only the startup-dir functionality is tested, but more tests should be added for: * ipython profile create * ipython profile list * ipython profile create --parallel * security dir permissions Authors ------- * MinRK """ # ---------...
292
9,535
ipython
tests/test_text.py
.py
# encoding: utf-8 """Tests for IPython.utils.text""" # ----------------------------------------------------------------------------- # Copyright (C) 2011 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software...
152
4,314
ipython
tests/conftest.py
.py
import builtins import inspect import os import pathlib import shutil import sys import types import pytest # Must register before it gets imported pytest.register_assert_rewrite("IPython.testing.tools") from IPython.testing import tools def get_ipython(): from IPython.terminal.interactiveshell import Terminal...
82
2,350
ipython
tests/fake_ext_dir/daft_extension.py
.py
# -*- coding: utf-8 -*- """ Useless IPython extension to test installing and loading extensions. """ some_vars = {"arq": 185} def load_ipython_extension(ip): # set up simplified quantity input ip.push(some_vars) def unload_ipython_extension(ip): ip.drop_by_id(some_vars)
15
287
ipython
examples/auto_suggest_llm.py
.py
""" This is an example of Fake LLM Completer for IPython, as well as example on how to configure IPython for LLMs. 8.32 – this is provisional and may change. To test this you can run the following command from the root of IPython directory: $ ipython --TerminalInteractiveShell.llm_provider_class=examples.auto_su...
175
5,682
ipython
examples/utils/cwd_prompt.py
.py
"""This is an example that shows how to create new prompts for IPython""" from IPython.terminal.prompts import Prompts, Token import os class MyPrompt(Prompts): def in_prompt_tokens(self): return [(Token, os.getcwd()), (Token.Prompt, ">>>")] def load_ipython_extension(shell): new_prompts = MyPrompt...
23
584
ipython
examples/IPython Kernel/ipython-get-history.py
.py
#!/usr/bin/env python """Extract a session from the IPython input history. Usage: ipython-get-history.py sessionnumber [outputfile] If outputfile is not given, the relevant history is written to stdout. If outputfile has a .py extension, the translated history (without IPython's special syntax) will be extracted. ...
42
1,139
ipython
examples/IPython Kernel/example-demo.py
.py
# -*- coding: utf-8 -*- """A simple interactive demo to illustrate the use of IPython's Demo class. Any python script can be run as a demo, but that does little more than showing it on-screen, syntax-highlighted in one shot. If you add a little simple markup, you can stop at specified intervals and return to the ipyt...
43
1,182
ipython
examples/IPython Kernel/gui/gui-qt.py
.py
#!/usr/bin/env python """Simple Qt4 example to manually test event loop integration. This is meant to run tests manually in ipython as: In [5]: %gui qt In [6]: %run gui-qt.py Ref: Modified from http://zetcode.com/tutorials/pyqt4/firstprograms/ """ from PyQt4 import QtGui, QtCore class SimpleWindow(QtGui.QWidget):...
41
1,009
ipython
examples/IPython Kernel/gui/gui-glut.py
.py
#!/usr/bin/env python """Simple GLUT example to manually test event loop integration. This is meant to run tests manually in ipython as: In [5]: %gui glut In [6]: %run gui-glut.py In [7]: gl.glClearColor(1,1,1,1) """ #!/usr/bin/env python import sys import OpenGL.GL as gl import OpenGL.GLUT as glut def close(): ...
52
1,297
ipython
examples/IPython Kernel/gui/gui-gtk4.py
.py
#!/usr/bin/env python """Simple Gtk example to manually test event loop integration. This is meant to run tests manually in ipython as: In [1]: %gui gtk4 In [2]: %run gui-gtk4.py """ import gi gi.require_version("Gtk", "4.0") from gi.repository import Gtk, GLib # noqa def hello_world(widget, data=None): pri...
38
716
ipython
examples/Embedding/start_ipython_config.py
.py
"""Quick snippet explaining how to set config options when using start_ipython.""" # First create a config object from the traitlets library from traitlets.config import Config c = Config() # Now we can set options as we would in a config file: # c.Class.config_value = value # For example, we can set the exec_lines...
23
738
ipython
examples/Embedding/embed_function.py
.py
"""Embed IPython using the simple embed function rather than the class API.""" from IPython import embed a = 10 b = 20 embed(header="First time", banner1="") c = 30 d = 40 try: raise Exception("adsfasdf") except: embed(header="The second time")
17
258
ipython
examples/Embedding/embed_class_short.py
.py
"""Quick code snippets for embedding IPython into other programs. See embed_class_long.py for full details, this file has the bare minimum code for cut and paste use once you understand how to use the system.""" #--------------------------------------------------------------------------- # This code loads IPython but...
46
1,674
ipython
examples/Embedding/embed_class_long.py
.py
#!/usr/bin/env python """An example of how to embed an IPython shell into a running program. Please see the documentation in the IPython.Shell module for more details. The accompanying file embed_class_short.py has quick code fragments for embedding which you can cut and paste in your code once you understand how thi...
146
4,836
ipython
IPython/display.py
.py
"""Public API for display tools in IPython.""" # ----------------------------------------------------------------------------- # Copyright (C) 2012 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. ...
42
1,392
ipython
IPython/__init__.py
.py
# PYTHON_ARGCOMPLETE_OK """ IPython: tools for interactive and parallel computing in Python. https://ipython.org """ #----------------------------------------------------------------------------- # Copyright (c) 2008-2011, IPython Development Team. # Copyright (c) 2001-2007, Fernando Perez <fernando.perez@colorado.e...
196
8,324
ipython
IPython/paths.py
.py
"""Find files and directories which IPython uses. """ from __future__ import annotations import os.path from warnings import warn from IPython.utils.importstring import import_item from IPython.utils.path import ( get_home_dir, get_xdg_dir, get_xdg_cache_dir, compress_user, _writable_dir, ensu...
124
4,153
ipython
IPython/testing/globalipapp.py
.py
"""Global IPython app to support test running. We must start our own ipython object and heavily muck with it so that all the modifications IPython makes to system behavior don't send the doctest machinery into a fit. This code should be considered a gross hack, but it gets the job done. """ # Copyright (c) IPython D...
115
3,944
ipython
IPython/testing/decorators.py
.py
import os import shutil import sys import tempfile from importlib import import_module import pytest # Expose the unittest-driven decorators from .ipunittest import ipdoctest, ipdocstring from _pytest.mark.structures import MarkDecorator def skipif(skip_condition: bool, msg: str | None=None) -> MarkDecorator: ""...
152
4,805
ipython
IPython/testing/ipunittest.py
.py
"""Experimental code for cleaner support of IPython syntax with unittest. In IPython up until 0.10, we've used very hacked up nose machinery for running tests with IPython special syntax, and this has proved to be extremely slow. This module provides decorators to try a different approach, stemming from a conversation...
188
6,710
ipython
IPython/testing/tools.py
.py
"""Generic testing tools. Authors ------- - Fernando Perez <Fernando.Perez@berkeley.edu> """ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. from __future__ import annotations import os from pathlib import Path import re import sys import tempfile import unittes...
436
13,312
ipython
IPython/testing/skipdoctest.py
.py
"""Decorators marks that a doctest should be skipped. The IPython.testing.decorators module triggers various extra imports, including numpy and sympy if they're present. Since this decorator is used in core parts of IPython, it's in a separate module so that running IPython doesn't trigger those imports.""" from __fut...
23
788
ipython
IPython/testing/plugin/simple.py
.py
"""Simple example using doctests. This file just contains doctests both using plain python and IPython prompts. All tests should be loaded by Pytest. """ def pyfunc(): """Some pure python tests... >>> pyfunc() 'pyfunc' >>> import os >>> 2+3 5 >>> for i in range(3): ... print(i...
46
727
ipython
IPython/testing/plugin/setup.py
.py
#!/usr/bin/env python """A Nose plugin to support IPython doctests. """ from setuptools import setup setup(name='IPython doctest plugin', version='0.1', author='The IPython Team', description = 'Nose plugin to load IPython-extended doctests', license = 'LGPL', py_modules = ['ipdoctest'],...
19
539
ipython
IPython/testing/plugin/dtexample.py
.py
"""Simple example using doctests. This file just contains doctests both using plain python and IPython prompts. All tests should be loaded by nose. """ import os def pyfunc(): """Some pure python tests... >>> pyfunc() 'pyfunc' >>> import os >>> 2+3 5 >>> for i in range(3): ... ...
168
2,916
ipython
IPython/testing/plugin/test_ipdoctest.py
.py
"""Tests for the ipdoctest machinery itself. Note: in a file named test_X, functions whose only test is their docstring (as a doctest) and which have no test functionality of their own, should be called 'doctest_foo' instead of 'test_foo', otherwise they get double-counted (the empty function call is counted as a test...
93
1,884
ipython
IPython/testing/plugin/test_refs.py
.py
"""Some simple tests for the plugin while running scripts. """ # Module imports # Std lib # Our own #----------------------------------------------------------------------------- # Testing functions def test_trivial(): """A trivial passing test.""" pass def doctest_run(): """Test running a trivial scrip...
39
700
ipython
IPython/testing/plugin/pytest_ipdoctest.py
.py
# Based on Pytest doctest.py # Original license: # The MIT License (MIT) # # Copyright (c) 2004-2021 Holger Krekel and others """Discover and run ipdoctests in modules and test files.""" from __future__ import annotations import bdb import builtins import inspect import os import platform import sys import traceback i...
869
29,873
ipython
IPython/testing/plugin/ipdoctest.py
.py
"""Nose Plugin that supports IPython doctests. Limitations: - When generating examples for use as doctests, make sure that you have pretty-printing OFF. This can be done either by setting the ``PlainTextFormatter.pprint`` option in your configuration file to False, or by interactively disabling it with %Ppri...
300
11,861
ipython
IPython/testing/plugin/simplevars.py
.py
x = 1 print("x is:", x)
3
24
ipython
IPython/extensions/storemagic.py
.py
""" %store magic for lightweight persistence. Stores variables, aliases and macros in IPython's database. To automatically restore stored variables at startup, add this to your :file:`ipython_config.py` file:: c.StoreMagics.autorestore = True """ # Copyright (c) IPython Development Team. # Distributed under the t...
235
8,141
ipython
IPython/extensions/autoreload.py
.py
"""IPython extension to reload modules before executing user code. ``autoreload`` reloads modules automatically before entering the execution of code typed at the IPython prompt. This makes for example the following workflow possible: .. sourcecode:: ipython In [1]: %load_ext autoreload In [2]: %autoreload 2...
916
32,208
ipython
IPython/extensions/tests/test_deduperreload.py
.py
#!/usr/bin/env python from __future__ import annotations import ast import os import platform import pytest import random import shutil import sys import tempfile import textwrap import time from types import ModuleType from IPython.extensions.autoreload import AutoreloadMagics from IPython.extensions.deduperreload.d...
2,311
57,358
ipython
IPython/extensions/deduperreload/deduperreload_patching.py
.py
from __future__ import annotations import ctypes from typing import Any NOT_FOUND: object = object() NULL: object = object() _MAX_FIELD_SEARCH_OFFSET = 50 POINTER_N_BYTES = ctypes.sizeof(ctypes.c_void_p) class DeduperReloaderPatchingMixin: @staticmethod def infer_field_offset( obj: object, f...
142
4,974
ipython
IPython/extensions/deduperreload/deduperreload.py
.py
from __future__ import annotations import ast import builtins import contextlib import itertools import logging import os import pickle import platform import sys import textwrap import tokenize from types import ModuleType from typing import TYPE_CHECKING, Any, NamedTuple, cast from collections.abc import Generator, I...
643
26,301
ipython
IPython/terminal/debugger.py
.py
import asyncio import os import sys from IPython.core.debugger import Pdb from IPython.core.completer import IPCompleter from .ptutils import IPythonPTCompleter from .shortcuts import create_ipython_shortcuts from pathlib import Path from pygments.token import Token from prompt_toolkit.application import create_app_s...
182
6,910
ipython
IPython/terminal/embed.py
.py
""" An embedded IPython shell. """ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import sys import warnings from IPython.core import ultratb, compilerop from IPython.core import magic_arguments from IPython.core.magic import Magics, magics_class, line_magic from...
495
18,917
ipython
IPython/terminal/ptutils.py
.py
"""prompt-toolkit utilities Everything in this module is a private API, not to be used outside IPython. """ from __future__ import annotations # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import unicodedata from wcwidth import wcwidth from IPython.core.complet...
265
9,136
ipython
IPython/terminal/interactiveshell.py
.py
"""IPython terminal interface using prompt_toolkit""" import os import sys import inspect from warnings import warn from IPython.core.async_helpers import get_asyncio_loop from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC from IPython.core.kitty import ( display_formatter_default_act...
1,148
41,019
ipython
IPython/terminal/ipapp.py
.py
""" The :class:`~traitlets.config.application.Application` object for the command line :command:`ipython` program. """ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import logging import os import sys import warnings from traitlets.config.loader import Config f...
348
12,464
ipython
IPython/terminal/prompts.py
.py
"""Terminal input and output prompts.""" from __future__ import annotations from pygments.token import _TokenType, Token import sys from IPython.core.displayhook import DisplayHook from prompt_toolkit.formatted_text import fragment_list_width, PygmentsTokens from prompt_toolkit.shortcuts import print_formatted_text...
147
4,821
ipython
IPython/terminal/magics.py
.py
"""Extra magics for terminal use.""" # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. from logging import error import os import sys from IPython.core.error import TryNext, UsageError from IPython.core.magic import Magics, magics_class, line_magic from IPython.lib...
214
7,638
ipython
IPython/terminal/shortcuts/filters.py
.py
""" Filters restricting scope of IPython Terminal shortcuts. """ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import ast import re import signal import sys from collections.abc import Callable from prompt_toolkit.application.current import get_app from prompt_t...
323
11,053
ipython
IPython/terminal/shortcuts/__init__.py
.py
""" Module to define and register Terminal IPython shortcuts with :mod:`prompt_toolkit` """ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import os import signal import sys import warnings from dataclasses import dataclass from typing import Any from collections....
640
18,609
ipython
IPython/terminal/shortcuts/auto_suggest.py
.py
import re import asyncio import tokenize from io import StringIO from typing import ClassVar, Any from collections.abc import Callable, Generator import warnings import prompt_toolkit from prompt_toolkit.buffer import Buffer from prompt_toolkit.key_binding import KeyPressEvent from prompt_toolkit.key_binding.bindings ...
663
23,945
ipython
IPython/terminal/shortcuts/auto_match.py
.py
""" Utilities function for keybinding with prompt toolkit. This will be bound to specific key press and filter modes, like whether we are in edit mode, and whether the completer is open. """ import re from prompt_toolkit.key_binding import KeyPressEvent def parenthesis(event: KeyPressEvent): """Auto-close paren...
106
3,066
ipython
IPython/terminal/tests/test_ptutils.py
.py
"""Tests for IPython.terminal.ptutils elision helpers.""" import os import pytest from IPython.terminal.ptutils import _elide_point, _elide_typed ELLIPSIS = "\N{HORIZONTAL ELLIPSIS}" # --------------------------------------------------------------------------- # _elide_point # ---------------------------------------...
87
3,139
ipython
IPython/terminal/pt_inputhooks/gtk4.py
.py
""" prompt_toolkit input hook for GTK 4. """ from gi.repository import GLib class _InputHook: def __init__(self, context): self._quit = False GLib.io_add_watch( context.fileno(), GLib.PRIORITY_DEFAULT, GLib.IO_IN, self.quit ) def quit(self, *args, **kwargs): self....
28
557
ipython
IPython/terminal/pt_inputhooks/asyncio.py
.py
""" Inputhook for running the original asyncio event loop while we're waiting for input. By default, in IPython, we run the prompt with a different asyncio event loop, because otherwise we risk that people are freezing the prompt by scheduling bad coroutines. E.g., a coroutine that does a while/true and never yield ba...
41
1,271
ipython
IPython/terminal/pt_inputhooks/__init__.py
.py
import importlib import os from collections.abc import Callable aliases = { 'qt4': 'qt', 'gtk2': 'gtk', } backends = [ "qt", "qt5", "qt6", "gtk", "gtk2", "gtk3", "gtk4", "tk", "wx", "pyglet", "glut", "osx", "asyncio", ] registered = {} def register(name, i...
140
3,608
ipython
IPython/terminal/pt_inputhooks/qt.py
.py
import sys import os from IPython.external.qt_for_kernel import QtCore, QtGui, enum_helper from IPython.core.getipython import get_ipython # If we create a QApplication, QEventLoop, or a QTimer, keep a reference to them # so that they don't get garbage collected or leak memory when created multiple times. _appref = No...
91
3,495
ipython
IPython/terminal/pt_inputhooks/glut.py
.py
"""GLUT Input hook for interactive use with prompt_toolkit """ # GLUT is quite an old library and it is difficult to ensure proper # integration within IPython since original GLUT does not allow to handle # events one by one. Instead, it requires for the mainloop to be entered # and never returned (there is not even ...
141
4,999
ipython
IPython/terminal/pt_inputhooks/osx.py
.py
"""Inputhook for OS X Calls NSApp / CoreFoundation APIs via ctypes. """ # obj-c boilerplate from appnope, used under BSD 2-clause import ctypes import ctypes.util objc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("objc")) # type: ignore void_p = ctypes.c_void_p objc.objc_getClass.restype = void_p objc.sel_...
147
4,420
ipython
IPython/terminal/pt_inputhooks/wx.py
.py
"""Enable wxPython to be used interactively in prompt_toolkit """ import sys import signal import time from timeit import default_timer as clock import wx def ignore_keyboardinterrupts(func): """Decorator which causes KeyboardInterrupt exceptions to be ignored during execution of the decorated function. ...
220
7,126
ipython
IPython/terminal/pt_inputhooks/tk.py
.py
# Code borrowed from ptpython # https://github.com/jonathanslenders/ptpython/blob/86b71a89626114b18898a0af463978bdb32eeb70/ptpython/eventloop.py # Copyright (c) 2015, Jonathan Slenders # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided t...
94
3,651
ipython
IPython/terminal/pt_inputhooks/gtk.py
.py
# Code borrowed from python-prompt-toolkit examples # https://github.com/jonathanslenders/python-prompt-toolkit/blob/77cdcfbc7f4b4c34a9d2f9a34d422d7152f16209/examples/inputhook.py # Copyright (c) 2014, Jonathan Slenders # All rights reserved. # # Redistribution and use in source and binary forms, with or without modif...
61
2,427
ipython
IPython/terminal/pt_inputhooks/pyglet.py
.py
"""Enable pyglet to be used interactively with prompt_toolkit""" import sys import time from timeit import default_timer as clock import pyglet # On linux only, window.flip() has a bug that causes an AttributeError on # window close. For details, see: # http://groups.google.com/group/pyglet-users/browse_thread/threa...
68
2,371
ipython
IPython/terminal/pt_inputhooks/gtk3.py
.py
"""prompt_toolkit input hook for GTK 3""" from gi.repository import Gtk, GLib def _main_quit(*args, **kwargs): Gtk.main_quit() return False def inputhook(context): GLib.io_add_watch(context.fileno(), GLib.PRIORITY_DEFAULT, GLib.IO_IN, _main_quit) Gtk.main()
14
279
ipython
IPython/sphinxext/ipython_console_highlighting.py
.py
""" reST directive for syntax-highlighting ipython interactive sessions. """ from sphinx import highlighting from ipython_pygments_lexers import IPyLexer def setup(app): """Setup as a sphinx extension.""" # This is only a lexer, so adding it below to pygments appears sufficient. # But if somebody knows...
29
895
ipython
IPython/sphinxext/custom_doctests.py
.py
""" Handlers for IPythonDirective's @doctest pseudo-decorator. The Sphinx extension that provides support for embedded IPython code provides a pseudo-decorator @doctest, which treats the input/output block as a doctest, raising a RuntimeError during doc generation if the actual output (after running the input) does no...
156
4,631
ipython
IPython/sphinxext/ipython_directive.py
.py
""" Sphinx directive to support embedded IPython code. IPython provides an extension for `Sphinx <http://www.sphinx-doc.org/>`_ to highlight and run code. This directive allows pasting of entire interactive IPython sessions, prompts and all, and their code will actually get re-executed at doc build time, with all pro...
1,301
45,961
ipython
IPython/sphinxext/tests/test_ansi_stripping.py
.py
"""Test that ANSI escape sequences are stripped from directive output.""" import re _ANSI_RE = re.compile(r"\x1b\[[0-9;]*m") def test_strip_ansi_basic(): """ANSI color codes should be removed from output.""" raw = "\x1b[31mred text\x1b[0m" assert _ANSI_RE.sub("", raw) == "red text" def test_strip_ansi...
29
845
ipython
IPython/lib/editorhooks.py
.py
""" 'editor' hooks for common editors that work well with ipython They should honor the line number argument, at least. Contributions are *very* welcome. """ import os import shlex import subprocess import sys from IPython.core.getipython import get_ipython from IPython.core.error import TryNext def install_edito...
127
3,925
ipython
IPython/lib/latextools.py
.py
"""Tools for handling LaTeX.""" # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. from io import BytesIO import os import tempfile import shutil import subprocess from base64 import encodebytes import textwrap from pathlib import Path from IPython.utils.process imp...
255
8,040
ipython
IPython/lib/clipboard.py
.py
""" Utilities for accessing the platform's clipboard. """ from __future__ import annotations import os import subprocess from IPython.core.error import TryNext from IPython.utils.encoding import DEFAULT_ENCODING class ClipboardEmpty(ValueError): pass def win32_clipboard_get(): """ Get the current clipboar...
104
3,159
ipython
IPython/lib/display.py
.py
"""Various display related classes. Authors : MinRK, gregcaporaso, dannystaple """ from os.path import exists, isfile, splitext, abspath, join, isdir from os import walk, sep, fsdecode from IPython.core.display import DisplayObject, TextDisplayObject from collections.abc import Iterable __all__ = ['Audio', 'IFrame'...
702
24,982
ipython
IPython/lib/lexers.py
.py
""" The IPython lexers are now a separate package, ipython-pygments-lexers. Importing from here is deprecated and may break in the future. """ # ----------------------------------------------------------------------------- # Copyright (c) 2013, the IPython Development Team. # # Distributed under the terms of the Modif...
32
841
ipython
IPython/lib/backgroundjobs.py
.py
"""Manage background (threaded) jobs conveniently from an interactive shell. This module provides a BackgroundJobManager class. This is the main class meant for public usage, it implements an object which can create and manage new background jobs. It also provides the actual job classes managed by these BackgroundJo...
491
17,574
ipython
IPython/lib/__init__.py
.py
""" Extra capabilities for IPython """ # ----------------------------------------------------------------------------- # Copyright (C) 2008-2011 The IPython Development Team # # Distributed under the terms of the BSD License. The full license is in # the file COPYING, distributed as part of this software. # -----...
11
393
ipython
IPython/lib/demo.py
.py
"""Module for interactive demos using IPython. This module implements a few classes for running Python scripts interactively in IPython for demonstrations. With very simple markup (a few tags in comments), you can control points where the script stops executing and returns control to IPython. Provided classes -----...
672
24,451
ipython
IPython/lib/pretty.py
.py
""" Python advanced pretty printer. This pretty printer is intended to replace the old `pprint` python module which does not allow developers to provide their own pretty print callbacks. This module is based on ruby's `prettyprint.rb` library by `Tanaka Akira`. Example Usage ------------- To directly print the rep...
959
30,884
ipython
IPython/lib/deepreload.py
.py
""" Provides a reload() function that acts recursively. Python's normal :func:`python:reload` function only reloads the module that it's passed. The :func:`reload` function in this module also reloads everything imported from that module, which is useful when you're changing files deep inside a package. To use this a...
310
9,436
ipython
IPython/lib/guisupport.py
.py
""" Support for creating GUI apps and starting event loops. IPython's GUI integration allows interactive plotting and GUI usage in IPython session. IPython has two different types of GUI integration: 1. The terminal based IPython supports GUI event loops through Python's PyOS_InputHook. PyOS_InputHook is a hook th...
155
6,284
ipython
IPython/core/error.py
.py
""" Global exception classes for IPython.core. Authors: * Brian Granger * Fernando Perez * Min Ragan-Kelley Notes ----- """ #----------------------------------------------------------------------------- # Copyright (C) 2008 The IPython Development Team # # Distributed under the terms of the BSD License. The full...
60
1,716
ipython
IPython/core/doctb.py
.py
from __future__ import annotations import linecache import sys from collections.abc import Sequence from types import TracebackType from typing import TYPE_CHECKING, Any from collections.abc import Callable from pygments.token import Token from IPython.utils.terminal import get_terminal_size from .tbtools import ( ...
472
16,333
ipython
IPython/core/logger.py
.py
"""Logger class for IPython's logging facilities. """ #***************************************************************************** # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu> # # Distributed under the terms of the BSD License. ...
231
8,523
ipython
IPython/core/display.py
.py
"""Top-level display functions for displaying object in different formats.""" # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. from __future__ import annotations from enum import Enum from dataclasses import dataclass, KW_ONLY from binascii import b2a_base64, hexli...
1,263
40,834
ipython
IPython/core/magic_arguments.py
.py
'''A decorator-based method of constructing IPython magics with `argparse` option handling. New magic functions can be defined like so:: from IPython.core.magic_arguments import (argument, magic_arguments, parse_argstring) @magic_arguments() @argument('-o', '--option', help='An optional argument....
312
9,749
ipython
IPython/core/debugger.py
.py
""" Pdb debugger class. This is an extension to PDB which adds a number of new features. Note that there is also the `IPython.terminal.debugger` class which provides UI improvements. We also strongly recommend to use this via the `ipdb` package, which provides extra configuration options. Among other things, this s...
1,473
50,999
ipython
IPython/core/splitinput.py
.py
""" Simple utility for splitting user input. This is used by both inputsplitter and prefilter. """ # ----------------------------------------------------------------------------- # Imports # ----------------------------------------------------------------------------- import re import warnings from typing import TYPE...
157
5,048
ipython
IPython/core/completer.py
.py
"""Completion for IPython. This module started as fork of the rlcompleter module in the Python standard library. The original enhancements made to rlcompleter have been sent upstream and were accepted as of Python 2.3, This module now support a wide variety of completion mechanism both available for normal classic P...
3,884
137,969
ipython
IPython/core/macro.py
.py
"""Support for interactive macros in IPython""" from __future__ import annotations #***************************************************************************** # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu> # # Distributed under the terms of the BSD License. The full license is in # the file...
49
1,632
ipython
IPython/core/alias.py
.py
""" System command aliases. Authors: * Fernando Perez * Brian Granger """ from __future__ import annotations #----------------------------------------------------------------------------- # Copyright (C) 2008-2011 The IPython Development Team # # Distributed under the terms of the BSD License. # # The full licen...
267
10,209
ipython
IPython/core/crashhandler.py
.py
"""sys.excepthook for IPython itself, leaves a detailed report on disk. Authors: * Fernando Perez * Brian E. Granger """ #----------------------------------------------------------------------------- # Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu> # Copyright (C) 2008-2011 The IPython Development ...
249
8,877
ipython
IPython/core/autocall.py
.py
""" Autocall capabilities for IPython.core. Authors: * Brian Granger * Fernando Perez * Thomas Kluyver Notes ----- """ #----------------------------------------------------------------------------- # Copyright (C) 2008-2011 The IPython Development Team # # Distributed under the terms of the BSD License. The ful...
71
1,941
ipython
IPython/core/payloadpage.py
.py
"""A payload based version of page.""" # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. import warnings from IPython.core.getipython import get_ipython # see https://github.com/ipython/ipykernel/issues/1304 # this should be moved to ipykernel and removed in the lon...
42
1,177
ipython
IPython/core/debugger_backport.py
.py
""" The code in this module is a backport of cPython changes in Pdb that were introduced in Python 3.13 by gh-83151: Make closure work on pdb https://github.com/python/cpython/pull/111094. This file should be removed once IPython drops supports for Python 3.12. The only changes are: - reformatting by darker (black) fo...
207
8,226
ipython
IPython/core/tbtools.py
.py
from __future__ import annotations import functools import sys import types import warnings from types import TracebackType from typing import TYPE_CHECKING, Any from collections.abc import Callable from pygments.token import Token from IPython.core.getipython import get_ipython from IPython.utils.PyColorize import ...
584
18,241