This work is a part of the build identification task found in the PEP 385, Migrating from svn to Mercurial:
http://www.python.org/dev/peps/pep-0385/
It was done during the Mercurial sprint hosted at Logilab. If you would like to see the result, just follow
the steps:
hg clone http://hg.xavamedia.nl/cpython/pymigr/
cd pymigr/build-identification
The current Python development branch is first checkout:
svn co http://svn.python.org/projects/python/trunk
A patch will be applied for adding the 'sys.mercurial' attribute
and modifying the build informations:
cp add-hg-build-id.diff trunk/
cd trunk
svn up -r 78019
patch -p0 < add-hg-build-id.diff
The changed made to 'configure.in' need then to be propagated
to the configure script:
autoconf
The configuration is then done by:
./configure --enable-shared --prefix=/dev/null
You should now see changes propagated to the Makefile for finding
the revision, the tag and the branch:
grep MERCURIAL Makefile
Finally, Python can be built:
make
The sys.mercurial attribute should already be present:
LD_LIBRARY_PATH=. ./python
>>> import sys
>>> sys.mercurial
('CPython', '', '')
No tag nor revision have been found as there was no mercurial repository. A test
by the Py_GetBuildInfo() in the C API will also be built:
gcc -o show-build-info -I. -IInclude -L. -lpython2.7 ../show-build-info.c
You can test its result by:
LD_LIBRARY_PATH=. ./show-build-info
-> default, Feb 7 2010, 15:07:46
First a fake mercurial tree is built:
hg init
hg add README
hg ci -m "Initial repo"
hg id
-> 84a6de74e48f tip
Now Python needs to be built with the given mercurial information:
rm Modules/getbuildinfo.o
make
You should then see the current revision number:
LD_LIBRARY_PATH=. ./python
>>> import sys
>>> sys.mercurial
('CPython', 'default', '84a6de74e48f')
and the C API can be tested by:
LD_LIBRARY_PATH=. ./show-build-info
-> default:84a6de74e48f, Feb 7 2010, 15:10:13
The fake mercurial repository can now be cleaned:
rm -rf .hg
Automatic tests for checking the behavior for every cases will now work
build Python and clean afterward. Those tests work only when run from the
trunk svn directory of Python:
python ../test_build_identification.py
The current work is only an attempt to add the mercurial build identification to Python, it
still needs to be checked on production cases. Moreover the build identification on Windows has
not been started yet, it will need to be integrated to the Microsoft Visual Studio building process.