From 5c16bcd77faebc1aa2e3fee9b8c5677e4a576157 2022-12-03 20:31:27 From: MichaƂ Krassowski <5832902+krassowski@users.noreply.github.com> Date: 2022-12-03 20:31:27 Subject: [PATCH] Merge branch 'main' into greedy-completions --- diff --git a/IPython/core/compilerop.py b/IPython/core/compilerop.py index 228f705..7799a4f 100644 --- a/IPython/core/compilerop.py +++ b/IPython/core/compilerop.py @@ -116,6 +116,21 @@ class CachingCompiler(codeop.Compile): """ return code_name(transformed_code, number) + def format_code_name(self, name): + """Return a user-friendly label and name for a code block. + + Parameters + ---------- + name : str + The name for the code block returned from get_code_name + + Returns + ------- + A (label, name) pair that can be used in tracebacks, or None if the default formatting should be used. + """ + if name in self._filename_map: + return "Cell", "In[%s]" % self._filename_map[name] + def cache(self, transformed_code, number=0, raw_code=None): """Make a name for a block of code, and cache the code. diff --git a/IPython/core/release.py b/IPython/core/release.py index d891c34..e2ce2ea 100644 --- a/IPython/core/release.py +++ b/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 = 7 +_version_minor = 8 _version_patch = 0 _version_extra = ".dev" # _version_extra = "rc1" diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index e83e2b4..18eff27 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -173,7 +173,7 @@ def _format_traceback_lines(lines, Colors, has_colors: bool, lvals): def _format_filename(file, ColorFilename, ColorNormal, *, lineno=None): """ - Format filename lines with `In [n]` if it's the nth code cell or `File *.py` if it's a module. + Format filename lines with custom formatting from caching compiler or `File *.py` by default Parameters ---------- @@ -184,23 +184,29 @@ def _format_filename(file, ColorFilename, ColorNormal, *, lineno=None): ColorScheme's normal coloring to be used. """ ipinst = get_ipython() - - if ipinst is not None and file in ipinst.compile._filename_map: - file = "[%s]" % ipinst.compile._filename_map[file] + if ( + ipinst is not None + and (data := ipinst.compile.format_code_name(file)) is not None + ): + label, name = data if lineno is None: - tpl_link = f"Cell {ColorFilename}In {{file}}{ColorNormal}" + tpl_link = f"{{label}} {ColorFilename}{{name}}{ColorNormal}" else: - tpl_link = f"Cell {ColorFilename}In {{file}}, line {{lineno}}{ColorNormal}" + tpl_link = ( + f"{{label}} {ColorFilename}{{name}}, line {{lineno}}{ColorNormal}" + ) else: - file = util_path.compress_user( + label = "File" + name = util_path.compress_user( py3compat.cast_unicode(file, util_path.fs_encoding) ) if lineno is None: - tpl_link = f"File {ColorFilename}{{file}}{ColorNormal}" + tpl_link = f"{{label}} {ColorFilename}{{name}}{ColorNormal}" else: - tpl_link = f"File {ColorFilename}{{file}}:{{lineno}}{ColorNormal}" + # can we make this the more friendly ", line {{lineno}}", or do we need to preserve the formatting with the colon? + tpl_link = f"{{label}} {ColorFilename}{{name}}:{{lineno}}{ColorNormal}" - return tpl_link.format(file=file, lineno=lineno) + return tpl_link.format(label=label, name=name, lineno=lineno) #--------------------------------------------------------------------------- # Module classes diff --git a/docs/source/whatsnew/version8.rst b/docs/source/whatsnew/version8.rst index eee7af0..d3c3370 100644 --- a/docs/source/whatsnew/version8.rst +++ b/docs/source/whatsnew/version8.rst @@ -2,6 +2,32 @@ 8.x Series ============ + +.. _version 8.7.0: + +IPython 8.7.0 +------------- + + +Small release of IPython with a couple of bug fixes and new features for this +month. Next month is end of year, it is unclear if there will be a release close +the new year's eve, or if the next release will be at end of January. + +Here are a few of the relevant fixes, +as usual you can find the full list of PRs on GitHub under `the 8.7 milestone +`__. + + + - :ghpull:`13834` bump the minimum prompt toolkit to 3.0.11. + - IPython shipped with the ``py.typed`` marker now, and we are progressively + adding more types. :ghpull:`13831` + - :ghpull:`13817` add configuration of code blacks formatting. + + +Thanks to the `D. E. Shaw group `__ for sponsoring +work on IPython and related libraries. + + .. _version 8.6.0: IPython 8.6.0 @@ -40,7 +66,7 @@ As we follow NEP 29, we removed support for numpy 1.19 :ghpull:`13760`. The ``open()`` function present in the user namespace by default will now refuse to open the file descriptors 0,1,2 (stdin, out, err), to avoid crashing IPython. -This mostly occurs in teaching context when incorrect values get passed around. +This mostly occurs in teaching context when incorrect values get passed around. The ``?``, ``??``, and corresponding ``pinfo``, ``pinfo2`` magics can now find diff --git a/setup.cfg b/setup.cfg index b3a2658..226506f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -37,7 +37,7 @@ install_requires = matplotlib-inline pexpect>4.3; sys_platform != "win32" pickleshare - prompt_toolkit>3.0.1,<3.1.0 + prompt_toolkit>=3.0.11,<3.1.0 pygments>=2.4.0 stack_data traitlets>=5 @@ -106,9 +106,6 @@ IPython.lib.tests = *.wav IPython.testing.plugin = *.txt [options.entry_points] -console_scripts = - ipython = IPython:start_ipython - ipython3 = IPython:start_ipython pygments.lexers = ipythonconsole = IPython.lib.lexers:IPythonConsoleLexer ipython = IPython.lib.lexers:IPythonLexer diff --git a/setup.py b/setup.py index bfdf5fb..4939ca5 100644 --- a/setup.py +++ b/setup.py @@ -66,7 +66,7 @@ from setuptools import setup # Our own imports sys.path.insert(0, ".") -from setupbase import target_update +from setupbase import target_update, find_entry_points from setupbase import ( setup_args, @@ -139,6 +139,7 @@ setup_args['cmdclass'] = { 'install_scripts_sym': install_scripts_for_symlink, 'unsymlink': unsymlink, } +setup_args["entry_points"] = {"console_scripts": find_entry_points()} #--------------------------------------------------------------------------- # Do the actual setup now