Lazily load pygments styles
See original GitHub issueWe currently try to retrieve all pygments styles at once, but this operation is very slow due to the import of pkg_resources
on the pygments side.
https://github.com/httpie/httpie/blob/cfcd7413d1afbabc5ab3c88a892851335be4944a/httpie/output/formatters/colors.py#L31
We should load these styles lazily when a user specifies --style
explicitly.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Lazily load pygments styles · Issue #1211 · httpie ... - GitHub
We currently try to retrieve all pygments styles at once, but this operation is very slow due to the import of pkg_resources on...
Read more >Styles — Pygments
Pygments comes with some builtin styles that work for both the HTML and LaTeX formatter. The builtin styles can be looked up with...
Read more >Lazy Loading Resources – Jack Carey
Pygments - adds syntax to code blocks during the build, which are stylised ... There are some pages where the scripts or styles...
Read more >No module named Pygments - python - Stack Overflow
First, I'd put this command just before you do the pygments import: import sys; print(sys.executable). This will give you a good indication ...
Read more >Reference — prompt_toolkit 3.0.36 documentation
Load the history and yield all the entries in reverse order (latest, ... Shortcut to create a Style instance from a Pygments style...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Command:
hyperfine 'http --version'
Since the actual load we are removing is
pkg_resources
import, the speed-up factor is very dependant on how complex the current python environment you are within. TheEnvironment 1
is simply a fresh python docker image with onlyhttpie
installed. TheEnvironment 2
is my local environment with over 300+ python packages.We could introduce layers (e.g
check if this is a built-in httpie style > check if this is a built-in pygments style > check if this is coming from a pygments plugin
), but I think that would be a bit complicated.Another possibility is asking pygments maintainers whether they would accept a patch that migrates from
pkg_resources
toimportlib_metadata
(a much much faster version for iterating over entry points), if the use case where a--style
is also important to us.