From 4f39222ad693549cdc7b7f58c4818edee84a84cf Mon Sep 17 00:00:00 2001 From: Michael Bianco Date: Mon, 10 Mar 2025 14:56:30 -0600 Subject: [PATCH] fix: support for new ipython 9.x theme system --- src/ipython_autoimport.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ipython_autoimport.py b/src/ipython_autoimport.py index 88d2b8b..cfa45c9 100644 --- a/src/ipython_autoimport.py +++ b/src/ipython_autoimport.py @@ -12,7 +12,6 @@ import importlib import os import sys -import token from types import ModuleType import warnings @@ -23,6 +22,7 @@ argument, magic_arguments, parse_argstring) from IPython.core.magics.execution import ExecutionMagics from IPython.utils import PyColorize +from pygments import token # Import token from pygments instead try: import importlib.metadata as _im @@ -89,9 +89,12 @@ def _report(ipython, msg): sys.stdout._raw = True except AttributeError: pass - cs = PyColorize.Parser().color_table[ipython.colors].colors - # Token.NUMBER: bright blue (cyan), looks reasonable. - print("{}Autoimport:{} {}".format(cs[token.NUMBER], cs["normal"], msg)) + # Update to use the new theme_table and format method + print( + PyColorize.theme_table[ipython.colors].format( + [(token.Number, f"Autoimport: {msg}")] + ) + ) class _SubmoduleAutoImporterModule(ModuleType):