Show More
@@ -190,22 +190,28 b' class Alias(object):' | |||
|
190 | 190 | #----------------------------------------------------------------------------- |
|
191 | 191 | |
|
192 | 192 | class AliasManager(Configurable): |
|
193 | ||
|
194 |
|
|
|
195 | user_aliases = List(default_value=[]).tag(config=True) | |
|
196 |
|
|
|
193 | default_aliases: List = List(default_aliases()).tag(config=True) | |
|
194 | user_aliases: List = List(default_value=[]).tag(config=True) | |
|
195 | shell = Instance( | |
|
196 | "IPython.core.interactiveshell.InteractiveShellABC", allow_none=True | |
|
197 | ) | |
|
197 | 198 | |
|
198 | 199 | def __init__(self, shell=None, **kwargs): |
|
199 | 200 | super(AliasManager, self).__init__(shell=shell, **kwargs) |
|
200 | 201 | # For convenient access |
|
201 | self.linemagics = self.shell.magics_manager.magics['line'] | |
|
202 | if self.shell is not None: | |
|
203 | self.linemagics = self.shell.magics_manager.magics["line"] | |
|
202 | 204 | self.init_aliases() |
|
203 | 205 | |
|
204 | 206 | def init_aliases(self): |
|
205 | 207 | # Load default & user aliases |
|
206 | 208 | for name, cmd in self.default_aliases + self.user_aliases: |
|
207 | if cmd.startswith('ls ') and self.shell.colors == 'NoColor': | |
|
208 | cmd = cmd.replace(' --color', '') | |
|
209 | if ( | |
|
210 | cmd.startswith("ls ") | |
|
211 | and self.shell is not None | |
|
212 | and self.shell.colors == "NoColor" | |
|
213 | ): | |
|
214 | cmd = cmd.replace(" --color", "") | |
|
209 | 215 | self.soft_define_alias(name, cmd) |
|
210 | 216 | |
|
211 | 217 | @property |
@@ -246,7 +252,7 b' class AliasManager(Configurable):' | |||
|
246 | 252 | raise ValueError('%s is not an alias' % name) |
|
247 | 253 | |
|
248 | 254 | def clear_aliases(self): |
|
249 |
for name, |
|
|
255 | for name, _ in self.aliases: | |
|
250 | 256 | self.undefine_alias(name) |
|
251 | 257 | |
|
252 | 258 | def retrieve_alias(self, name): |
@@ -43,117 +43,127 b' def exception_colors():' | |||
|
43 | 43 | |
|
44 | 44 | # Populate it with color schemes |
|
45 | 45 | C = TermColors # shorthand and local lookup |
|
46 |
ex_colors.add_scheme( |
|
|
47 |
|
|
|
46 | ex_colors.add_scheme( | |
|
47 | ColorScheme( | |
|
48 | "NoColor", | |
|
49 | { | |
|
48 | 50 | # The color to be used for the top line |
|
49 |
topline |
|
|
51 | "topline": C.NoColor, | |
|
50 | 52 | |
|
51 | 53 | # The colors to be used in the traceback |
|
52 |
filename |
|
|
53 |
lineno |
|
|
54 |
name |
|
|
55 |
vName |
|
|
56 |
val |
|
|
57 |
em |
|
|
54 | "filename": C.NoColor, | |
|
55 | "lineno": C.NoColor, | |
|
56 | "name": C.NoColor, | |
|
57 | "vName": C.NoColor, | |
|
58 | "val": C.NoColor, | |
|
59 | "em": C.NoColor, | |
|
58 | 60 | |
|
59 | 61 | # Emphasized colors for the last frame of the traceback |
|
60 |
normalEm |
|
|
61 |
filenameEm |
|
|
62 |
linenoEm |
|
|
63 |
nameEm |
|
|
64 |
valEm |
|
|
62 | "normalEm": C.NoColor, | |
|
63 | "filenameEm": C.NoColor, | |
|
64 | "linenoEm": C.NoColor, | |
|
65 | "nameEm": C.NoColor, | |
|
66 | "valEm": C.NoColor, | |
|
65 | 67 | |
|
66 | 68 | # Colors for printing the exception |
|
67 |
excName |
|
|
68 |
line |
|
|
69 |
caret |
|
|
70 |
Normal |
|
|
71 |
|
|
|
69 | "excName": C.NoColor, | |
|
70 | "line": C.NoColor, | |
|
71 | "caret": C.NoColor, | |
|
72 | "Normal": C.NoColor, | |
|
73 | }, | |
|
74 | ) | |
|
75 | ) | |
|
72 | 76 | |
|
73 | 77 | # make some schemes as instances so we can copy them for modification easily |
|
74 |
ex_colors.add_scheme( |
|
|
75 | 'Linux', | |
|
78 | ex_colors.add_scheme( | |
|
79 | ColorScheme( | |
|
80 | "Linux", | |
|
81 | { | |
|
76 | 82 | # The color to be used for the top line |
|
77 |
topline |
|
|
78 | ||
|
83 | "topline": C.LightRed, | |
|
79 | 84 | # The colors to be used in the traceback |
|
80 |
filename |
|
|
81 |
lineno |
|
|
82 |
name |
|
|
83 |
vName |
|
|
84 |
val |
|
|
85 |
em |
|
|
86 | ||
|
85 | "filename": C.Green, | |
|
86 | "lineno": C.Green, | |
|
87 | "name": C.Purple, | |
|
88 | "vName": C.Cyan, | |
|
89 | "val": C.Green, | |
|
90 | "em": C.LightCyan, | |
|
87 | 91 | # Emphasized colors for the last frame of the traceback |
|
88 |
normalEm |
|
|
89 |
filenameEm |
|
|
90 |
linenoEm |
|
|
91 |
nameEm |
|
|
92 |
valEm |
|
|
93 | ||
|
92 | "normalEm": C.LightCyan, | |
|
93 | "filenameEm": C.LightGreen, | |
|
94 | "linenoEm": C.LightGreen, | |
|
95 | "nameEm": C.LightPurple, | |
|
96 | "valEm": C.LightBlue, | |
|
94 | 97 | # Colors for printing the exception |
|
95 |
excName |
|
|
96 |
line |
|
|
97 |
caret |
|
|
98 |
Normal |
|
|
99 |
|
|
|
98 | "excName": C.LightRed, | |
|
99 | "line": C.Yellow, | |
|
100 | "caret": C.White, | |
|
101 | "Normal": C.Normal, | |
|
102 | }, | |
|
103 | ) | |
|
104 | ) | |
|
100 | 105 | |
|
101 | 106 | # For light backgrounds, swap dark/light colors |
|
102 |
ex_colors.add_scheme( |
|
|
103 | 'LightBG', | |
|
107 | ex_colors.add_scheme( | |
|
108 | ColorScheme( | |
|
109 | "LightBG", | |
|
110 | { | |
|
104 | 111 | # The color to be used for the top line |
|
105 |
topline |
|
|
112 | "topline": C.Red, | |
|
106 | 113 | |
|
107 | 114 | # The colors to be used in the traceback |
|
108 |
filename |
|
|
109 |
lineno |
|
|
110 |
name |
|
|
111 |
vName |
|
|
112 |
val |
|
|
113 |
em |
|
|
115 | "filename": C.LightGreen, | |
|
116 | "lineno": C.LightGreen, | |
|
117 | "name": C.LightPurple, | |
|
118 | "vName": C.Cyan, | |
|
119 | "val": C.LightGreen, | |
|
120 | "em": C.Cyan, | |
|
114 | 121 | |
|
115 | 122 | # Emphasized colors for the last frame of the traceback |
|
116 |
normalEm |
|
|
117 |
filenameEm |
|
|
118 |
linenoEm |
|
|
119 |
nameEm |
|
|
120 |
valEm |
|
|
123 | "normalEm": C.Cyan, | |
|
124 | "filenameEm": C.Green, | |
|
125 | "linenoEm": C.Green, | |
|
126 | "nameEm": C.Purple, | |
|
127 | "valEm": C.Blue, | |
|
121 | 128 | |
|
122 | 129 | # Colors for printing the exception |
|
123 |
excName |
|
|
124 |
# |
|
|
125 |
line |
|
|
126 |
caret |
|
|
127 |
Normal |
|
|
128 |
|
|
|
129 | ||
|
130 | ex_colors.add_scheme(ColorScheme( | |
|
131 | 'Neutral', | |
|
130 | "excName": C.Red, | |
|
131 | # "line": C.Brown, # brown often is displayed as yellow | |
|
132 | "line": C.Red, | |
|
133 | "caret": C.Normal, | |
|
134 | "Normal": C.Normal, | |
|
135 | }, | |
|
136 | ) | |
|
137 | ) | |
|
138 | ||
|
139 | ex_colors.add_scheme( | |
|
140 | ColorScheme( | |
|
141 | "Neutral", | |
|
142 | { | |
|
132 | 143 | # The color to be used for the top line |
|
133 |
topline |
|
|
134 | ||
|
144 | "topline": C.Red, | |
|
135 | 145 | # The colors to be used in the traceback |
|
136 |
filename |
|
|
137 |
lineno |
|
|
138 |
name |
|
|
139 |
vName |
|
|
140 |
val |
|
|
141 |
em |
|
|
142 | ||
|
146 | "filename": C.LightGreen, | |
|
147 | "lineno": C.LightGreen, | |
|
148 | "name": C.LightPurple, | |
|
149 | "vName": C.Cyan, | |
|
150 | "val": C.LightGreen, | |
|
151 | "em": C.Cyan, | |
|
143 | 152 | # Emphasized colors for the last frame of the traceback |
|
144 |
normalEm |
|
|
145 |
filenameEm |
|
|
146 |
linenoEm |
|
|
147 |
nameEm |
|
|
148 |
valEm |
|
|
149 | ||
|
153 | "normalEm": C.Cyan, | |
|
154 | "filenameEm": C.Green, | |
|
155 | "linenoEm": C.Green, | |
|
156 | "nameEm": C.Purple, | |
|
157 | "valEm": C.Blue, | |
|
150 | 158 | # Colors for printing the exception |
|
151 |
excName |
|
|
159 | "excName": C.Red, | |
|
152 | 160 | #line = C.Brown, # brown often is displayed as yellow |
|
153 |
line |
|
|
154 |
caret |
|
|
155 |
Normal |
|
|
156 |
|
|
|
161 | "line": C.Red, | |
|
162 | "caret": C.Normal, | |
|
163 | "Normal": C.Normal, | |
|
164 | }, | |
|
165 | ) | |
|
166 | ) | |
|
157 | 167 | |
|
158 | 168 | # Hack: the 'neutral' colours are not very visible on a dark background on |
|
159 | 169 | # Windows. Since Windows command prompts have a dark background by default, and |
@@ -10,8 +10,7 b' import sys' | |||
|
10 | 10 | from importlib import import_module, reload |
|
11 | 11 | |
|
12 | 12 | from traitlets.config.configurable import Configurable |
|
13 |
from IPython.utils.path import ensure_dir_exists |
|
|
14 | from IPython.utils.decorators import undoc | |
|
13 | from IPython.utils.path import ensure_dir_exists | |
|
15 | 14 | from traitlets import Instance |
|
16 | 15 | |
|
17 | 16 | |
@@ -84,7 +83,7 b' class ExtensionManager(Configurable):' | |||
|
84 | 83 | if module_str in self.loaded: |
|
85 | 84 | return "already loaded" |
|
86 | 85 | |
|
87 | from IPython.utils.syspathcontext import prepended_to_syspath | |
|
86 | assert self.shell is not None | |
|
88 | 87 | |
|
89 | 88 | with self.shell.builtin_trap: |
|
90 | 89 | if module_str not in sys.modules: |
@@ -26,8 +26,7 b' from traitlets import List' | |||
|
26 | 26 | #----------------------------------------------------------------------------- |
|
27 | 27 | |
|
28 | 28 | class PayloadManager(Configurable): |
|
29 | ||
|
30 | _payload = List([]) | |
|
29 | _payload: List = List([]) | |
|
31 | 30 | |
|
32 | 31 | def write_payload(self, data, single=True): |
|
33 | 32 | """Include or update the specified `data` payload in the PayloadManager. |
@@ -103,8 +103,8 b' class RichPromptDisplayHook(DisplayHook):' | |||
|
103 | 103 | |
|
104 | 104 | if self.do_full_cache: |
|
105 | 105 | tokens = self.shell.prompts.out_prompt_tokens() |
|
106 |
prompt_txt = |
|
|
107 |
if prompt_txt and not prompt_txt.endswith( |
|
|
106 | prompt_txt = "".join(s for _, s in tokens) | |
|
107 | if prompt_txt and not prompt_txt.endswith("\n"): | |
|
108 | 108 | # Ask for a newline before multiline output |
|
109 | 109 | self.prompt_end_newline = False |
|
110 | 110 | |
@@ -116,6 +116,7 b' class RichPromptDisplayHook(DisplayHook):' | |||
|
116 | 116 | sys.stdout.write(prompt_txt) |
|
117 | 117 | |
|
118 | 118 | def write_format_data(self, format_dict, md_dict=None) -> None: |
|
119 | assert self.shell is not None | |
|
119 | 120 | if self.shell.mime_renderers: |
|
120 | 121 | |
|
121 | 122 | for mime, handler in self.shell.mime_renderers.items(): |
@@ -1,4 +1,3 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | 1 |
|
|
3 | 2 | """ |
|
4 | 3 | |
@@ -9,12 +8,13 b'' | |||
|
9 | 8 | # the file COPYING, distributed as part of this software. |
|
10 | 9 | #***************************************************************************** |
|
11 | 10 | |
|
12 | __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable'] | |
|
13 | 11 | |
|
14 | 12 | import os |
|
15 | 13 | |
|
16 | 14 | from IPython.utils.ipstruct import Struct |
|
17 | 15 | |
|
16 | __all__ = ["TermColors", "InputTermColors", "ColorScheme", "ColorSchemeTable"] | |
|
17 | ||
|
18 | 18 | color_templates = ( |
|
19 | 19 | # Dark colors |
|
20 | 20 | ("Black" , "0;30"), |
@@ -110,6 +110,10 b' for name, value in color_templates:' | |||
|
110 | 110 | |
|
111 | 111 | class ColorScheme: |
|
112 | 112 | """Generic color scheme class. Just a name and a Struct.""" |
|
113 | ||
|
114 | name: str | |
|
115 | colors: Struct | |
|
116 | ||
|
113 | 117 | def __init__(self,__scheme_name_,colordict=None,**colormap): |
|
114 | 118 | self.name = __scheme_name_ |
|
115 | 119 | if colordict is None: |
@@ -3,7 +3,7 b' requires = ["setuptools >= 51.0.0"]' | |||
|
3 | 3 | build-backend = "setuptools.build_meta" |
|
4 | 4 | |
|
5 | 5 | [tool.mypy] |
|
6 | python_version = 3.10 | |
|
6 | python_version = "3.10" | |
|
7 | 7 | ignore_missing_imports = true |
|
8 | 8 | follow_imports = 'silent' |
|
9 | 9 | exclude = [ |
@@ -79,3 +79,6 b' ipdoctest_optionflags = [' | |||
|
79 | 79 | "ELLIPSIS" |
|
80 | 80 | ] |
|
81 | 81 | asyncio_mode = "strict" |
|
82 | ||
|
83 | [tool.pyright] | |
|
84 | pythonPlatform="All" |
General Comments 0
You need to be logged in to leave comments.
Login now