Home > documentation, Mercurial, Sage, symbolic computation > Adding Mercurial patches before building Sage

Adding Mercurial patches before building Sage

The following problem and accompanying solution were posted to sage-devel. I have polished them up a bit and put them here so they won’t be buried in the huge sage-devel mailing list.


You have a number of Mercurial patches that you want to apply to a Sage source distribution. However, you don’t want to go through the following work flow:

  1. Build a Sage source distribution.
  2. Apply your patches to the Sage library.
  3. Produce a new source tarball based on your patched Sage source distribution.
  4. Compile your newly wrapped up modified Sage source tarball.

The key problem is that you don’t want to run through two separate compilation processes.


The following solution uses the queues extension of Mercurial. In a Sage source tarball, the Sage library is wrapped up as the package


Uncompress that bzip2 compressed tarball to get a directory named


If you want, you could delete


Now patch the Sage library as if it had been built and found under SAGE_ROOT/devel:

$ cd SAGE_ROOT/spkg/standard/sage-x.y.z/
$ hg qimport /URL/or/path/to/patch.patch
$ hg qpush
$ <repeat-previous-two-commands-as-often-as-required>

The command

$ hg qapplied

should return a list of patches you have applied using “hg qpush“. Once you are happy that you have applied all necessary patches, wrap up the patched Sage library:

$ pwd
$ hg qfinish -a
$ cd ..

And see this section of the Developer’s Guide to find out how to package the newly patched Sage library, i.e. the directory


Now you should have


so you could delete


Finally, proceed to build Sage from source.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: