Commit 2186613
committed
Keep the pygments plugin machinery off the startup path
Resolving a theme's base style went through `pygments.styles`, whose module
body imports `pygments.plugin` and with it `importlib.metadata`, `email` and
`zipfile` -- about 10ms and 36 modules on every `ipython` start, all of it so
that third party *style plugins* can be found by name. No theme IPython ships
needs that.
Both call sites only ever want the base style's `styles` mapping, so add
`PyColorize._pygments_base_styles`, which for the handful of builtin styles
IPython's own themes are based on executes the single `pygments/styles/*.py`
module that defines them and reads the mapping out of it. Anything else --
an unknown name, or a style that has moved within pygments -- still goes
through `pygments.styles.get_style_by_name`, plugins included, so this is a
shortcut and never the source of truth.
The style module is deliberately not registered in `sys.modules`: it is pure
data, and registering a submodule of a package that is not itself imported
breaks later `import pygments.styles.<mod>` statements.1 parent dd41c52 commit 2186613
2 files changed
Lines changed: 78 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
844 | | - | |
845 | | - | |
846 | | - | |
847 | | - | |
848 | | - | |
849 | 844 | | |
850 | 845 | | |
851 | | - | |
| 846 | + | |
852 | 847 | | |
853 | 848 | | |
854 | 849 | | |
855 | | - | |
| 850 | + | |
856 | 851 | | |
857 | | - | |
| 852 | + | |
858 | 853 | | |
859 | 854 | | |
860 | 855 | | |
861 | | - | |
| 856 | + | |
862 | 857 | | |
863 | 858 | | |
864 | 859 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
30 | 101 | | |
31 | 102 | | |
32 | 103 | | |
| |||
63 | 134 | | |
64 | 135 | | |
65 | 136 | | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
| 137 | + | |
72 | 138 | | |
73 | 139 | | |
74 | 140 | | |
| |||
0 commit comments