Patchwork highlight: put pygments import inside demandimport.deactivated

login
register
mail settings
Submitter Augie Fackler
Date June 19, 2017, 3:11 a.m.
Message ID <44dd362d5685815692ba.1497841901@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/21499/
State Accepted
Headers show

Comments

Augie Fackler - June 19, 2017, 3:11 a.m.
# HG changeset patch
# User Augie Fackler <raf@durin42.com>
# Date 1497841554 14400
#      Sun Jun 18 23:05:54 2017 -0400
# Node ID 44dd362d5685815692baed660a476eebfed8346e
# Parent  2851b24eecc483ce1546d63d155fa2e9250e3f44
highlight: put pygments import inside demandimport.deactivated

I tripped on some weirdness relating to _thread vs threading way down
in a dep of highlight recently. I'm not really sure why I'm only just
seeing this defect now, but experimentally this fixes the problem, and
shouldn't cause any load-time slowness for people until pygments is
actually about to be used since highlight.highlight is still lazily
loaded in the highlight/__init__.py file.
Yuya Nishihara - June 19, 2017, 2:02 p.m.
On Sun, 18 Jun 2017 23:11:41 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <raf@durin42.com>
> # Date 1497841554 14400
> #      Sun Jun 18 23:05:54 2017 -0400
> # Node ID 44dd362d5685815692baed660a476eebfed8346e
> # Parent  2851b24eecc483ce1546d63d155fa2e9250e3f44
> highlight: put pygments import inside demandimport.deactivated
> 
> I tripped on some weirdness relating to _thread vs threading way down
> in a dep of highlight recently. I'm not really sure why I'm only just
> seeing this defect now, but experimentally this fixes the problem, and
> shouldn't cause any load-time slowness for people until pygments is
> actually about to be used since highlight.highlight is still lazily
> loaded in the highlight/__init__.py file.

Seems fine. Queued, thanks.

Patch

diff --git a/hgext/highlight/highlight.py b/hgext/highlight/highlight.py
--- a/hgext/highlight/highlight.py
+++ b/hgext/highlight/highlight.py
@@ -10,11 +10,6 @@ 
 
 from __future__ import absolute_import
 
-import pygments
-import pygments.formatters
-import pygments.lexers
-import pygments.util
-
 from mercurial import demandimport
 demandimport.ignore.extend(['pkgutil', 'pkg_resources', '__main__'])
 
@@ -23,6 +18,12 @@  from mercurial import (
     util,
 )
 
+with demandimport.deactivated():
+    import pygments
+    import pygments.formatters
+    import pygments.lexers
+    import pygments.util
+
 highlight = pygments.highlight
 ClassNotFound = pygments.util.ClassNotFound
 guess_lexer = pygments.lexers.guess_lexer