pygments-server
A simple server that provides HTTP access to pygmentize
We use phabricator, which calls out to pygmentize to
syntax-highlight code in diffs. Each block of code gets its own call
to pygmentize, which can add up; Python startup is fairly expensive.
Enter pygments-server, which is a long-running server that
pygmentizes. It takes source code via POST and returns highlighted
source code in the response body.
Using pygments-server with phabricator
You can use the pygments server as a drop-in replacement for the
"pygmentize" binary on your phabricator machine. This will let you
colorize Phabricator diffs using less CPU, with no other cost.
-
Clone the pygments-server repo somewhere on your Phabricator
server machine. For the below, I will assume you ran
git clone https://github.com/Khan/pygments-serverin$HOME. -
Run
cd ~/pygments-server && make depson your Phabricator server
machine. -
Start the pygments-server. The best way to do this is to
use an init script such as upstart. You can use
pygments-server/pygments-server.confas an example. If
you are on an upstart-based system (such as ubuntu) you can
dosudo install pygments-server/pygments-server.conf /etc/init/ sudo start pygments-serverYou may need to edit the init script if
$HOMEfor you is not
/home/ubuntu. And you will probably want to change the
location of the logs files. -
Replace the default
pygmentizebinary with our script that uses
the server:[ -L /usr/bin/pygmentize] || sudo mv /usr/bin/pygmentize /usr/bin/pygmentize.orig [ -L /usr/local/bin/pygmentize] || sudo mv /usr/local/bin/pygmentize /usr/local/bin/pygmentize.orig sudo ln -snf $HOME/pygments-server/pygmentize /usr/bin/ sudo ln -snf $HOME/pygments-server/pygmentize /usr/local/bin/ -
OPTIONAL: install a logrotate script for the pygments-server logs:
sudo install -m 644 $HOME/pygments-server/pygments-server.logrotate /etc/logrotate.d/pygments-server -
Make sure the pygments config option is turned on in your
Phabricator config:
https://secure.phabricator.com/book/phabricator/article/differential_faq/#how-can-i-enable-syntax -
Run
arc diffon your next change and admire all the pretty
colors!