[PATCH] Update setup.py to identify the version when not ran in a repository

Greg Ward greg-hg at gerg.ca
Fri Apr 3 08:40:56 CDT 2009


On Thu, Apr 2, 2009 at 5:57 PM, Jeremy Whitlock <jcscoobyrs at gmail.com> wrote:
> # HG changeset patch
> # User Jeremy Whitlock <jcscoobyrs at gmail.com>
> # Date 1238617555 21600
> # Node ID c6b51395244c050fff6b7e3623e34671c7c6bf60
> # Parent  67e59a9886d5902de5b94cd2552d854b6292ec63
> Update setup.py to identify the version when not ran in a repository.
>
> setup.py only identifies the correct version when ran within a repository.  For
> source tarballs, this results in an incorrect version being reported and used
> for creating release packages, like RPMs.
>
> To fix this, try to get the version from mercurial.util.version() when not in a
> repository before defaulting to "unknown".
>
> diff -r 67e59a9886d5 -r c6b51395244c setup.py
> --- a/setup.py  Thu Mar 26 19:01:06 2009 +0900
> +++ b/setup.py  Wed Apr 01 14:25:55 2009 -0600
> @@ -99,7 +99,8 @@
>
>  def getversion():
>     if not os.path.exists('.hg'):
> -        return None # not in a repository
> +        from mercurial import util
> +        return util.version()

That might be a tad risky: you never know which "mercurial" will come
first in sys.path.  Might be safer to execfile("mercurial/util.py")
and call the version() function that reads.

Greg



More information about the Mercurial-devel mailing list