[PATCH STABLE] run-tests: pre instantiate pygments objects

Martin von Zweigbergk martinvonz at google.com
Fri Jul 21 12:03:53 EDT 2017


On Fri, Jul 21, 2017 at 8:44 AM, Jun Wu <quark at fb.com> wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1500651819 25200
> #      Fri Jul 21 08:43:39 2017 -0700
> # Branch stable
> # Node ID d0e9f607360bdfe9e39a7b9aff765265292b0eeb
> # Parent  637267114513d02072256219ad866565771f42e9
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r d0e9f607360b
> run-tests: pre instantiate pygments objects

Queued, thanks! The slowness had bothered me too.

>
> This speeds up run-tests.py diff output by 10x, which affects developer
> experience significantly. As demonstrated by the following test:
>
> ```
> #require pygments
>
>   $ for i in `seq 1 200`; do
>   >   echo '  $ echo '$i >> test-a.t
>   >   echo '  wrong' >> test-a.t
>   > done
>
>   $ cat > walltime.py <<EOF
>   > from __future__ import absolute_import, print_function
>   > import os, sys, time
>   > t1 = time.time()
>   > os.system(' '.join(sys.argv[1:]) + ' >/dev/null 2>/dev/null')
>   > t2 = time.time()
>   > print('%0.2f' % (t2 - t1))
>   > EOF
>
>   $ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=never $TESTTMP/test-a.t
>   0.24
>
> Before this patch:
>
>   $ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=always $TESTTMP/test-a.t
>   2.46
>
> After this patch:
>
>   $ $PYTHON walltime.py $TESTDIR/run-tests.py -l --color=always $TESTTMP/test-a.t
>   0.25
> ```
>
> diff --git a/tests/run-tests.py b/tests/run-tests.py
> --- a/tests/run-tests.py
> +++ b/tests/run-tests.py
> @@ -97,4 +97,6 @@ if os.name != 'nt':
>          import pygments.formatters as formatters
>          pygmentspresent = True
> +        difflexer = lexers.DiffLexer()
> +        terminal256formatteer = formatters.Terminal256Formatter()

I did s/eer/er/ in flight as you pointed out in #mercurial.

>      except ImportError:
>          pass
> @@ -1652,8 +1654,7 @@ class TestResult(unittest._TextTestResul
>                      for line in lines:
>                          if self.color:
> -                            line = pygments.highlight(
> -                                    line,
> -                                    lexers.DiffLexer(),
> -                                    formatters.Terminal256Formatter())
> +                            line = pygments.highlight(line,
> +                                                      difflexer,
> +                                                      terminal256formatteer)
>                          if PYTHON3:
>                              self.stream.flush()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


More information about the Mercurial-devel mailing list