question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazily load pygments styles

See original GitHub issue

We 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:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
isidenticalcommented, Nov 24, 2021

Command: hyperfine 'http --version'

normal lazy loading factor
Environment 1 238.2 ms 185.4 ms 1.30X (30%)
Environment 2 383.3 ms 240.4 ms 1.58X (58%)

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. The Environment 1 is simply a fresh python docker image with only httpie installed. The Environment 2 is my local environment with over 300+ python packages.

0reactions
isidenticalcommented, Dec 1, 2021

Couldn’t we use a different method for checking if it exists (e.g. checking if a module exists first, and only then loading the styles if not)?

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 to importlib_metadata (a much much faster version for iterating over entry points), if the use case where a --style is also important to us.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found