Repository navigation
Conversation
|
@xh123637 Tests don't pass. |
| @staticmethod | ||
| def _from_builtin(filename: str) -> Theme: | ||
| """Read a theme IPython ships, from the package rather than the disk. | ||
|
|
||
| `importlib.resources` reads the JSON whether the package is a plain | ||
| directory or inside a zip file, so this also works for zipapp installs. | ||
| """ | ||
| from importlib.resources import files | ||
|
|
||
| data = json.loads( | ||
| (files("IPython.utils") / "themes" / filename).read_text(encoding="utf-8") | ||
| ) | ||
| return Theme.from_dict(data) |
There was a problem hiding this comment.
You probably don't need a function if you only use it once.
There was a problem hiding this comment.
Done in da2ad5b — inlined _from_builtin into __getitem__, keeping the importlib.resources read and the zipapp explanation as a comment. Re-ran tests/test_themes.py and tests/test_pycolorize.py locally: 96 passed; ruff format --check and ruff check are clean on the file.
|
@gpotter2 On the failing check: I re-checked the CI on the previous head (2daed4a). The only failing check was the All 16 test-matrix jobs (ubuntu/macos/windows × Python 3.11–3.15, The latest push (da2ad5b, inlining |
Fixes #15477 🤖🤖
Bundled themes were read with
open()on a path under the package directory, which fails withNotADirectoryErrorwhen IPython is imported from a zip file (for example a zipapp), since the theme JSON files have no real directory there.ThemeTablenow reads shipped themes throughimportlib.resources, the same approach already used for entry-point themes. Themes from the IPython directory andTheme.from_fileare unchanged.Adds a regression test that zips the package, imports IPython from the zip, and loads and formats with the
linuxtheme.AI usage
Made with Muse (Muse Spark). I do not know the effort (reasoning) level it ran at. Human review: No — no human has reviewed this change.