:license: GPL-2, see LICENSE for more details.
# CHANGE ME BEFORE THE RELEASE!
+# when this file got installed from a mercurial repository, the hash of the
+# current changeset is appended to the 'version' variable.
-# code snippet from sphinx
-if '+' in version or 'pre' in version:
- # try to find out the changeset hash if checked out from hg, and append
- # it to version (since we use this value from setup.py, it gets
- # automatically propagated to an installed copy as well)
- cwd = os.path.dirname(os.path.abspath(__file__))
- ['hg', 'id', '-i', '-R', os.path.join(cwd, '..')],
- out, err = p.communicate()
- version += '/' + out.strip()
+# the file isn't installed but this isn't a stable release, then we may be
+# running from a mercurial repository. let's verify.
+if re.match(r'^[0-9.]+\+$', version):
+ # we don't need to care about use mercurial from command-line, because we
+ # are GPL already anyway :)
+ from mercurial import hg, ui as hgui
+ from mercurial.commands import identify
+ # root dir is where the parent dir of the dir where this file is.
+ root_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')
+ # if we are inside a mercurial repository...
+ if os.path.isdir(os.path.join(root_dir, '.hg')):
+ # create the repo object
+ repo = hg.repository(ui, root_dir)
+ # use the ui stack to get the return value from the 'hg identify'
+ # command, and run the command itself.
+ identify(ui, repo, id=True)
+ # append the changeset hash to the version.
+ version += '/' + rv.strip()