diff --git a/setup.py b/setup.py --- a/setup.py +++ b/setup.py @@ -97,7 +97,10 @@ try: except ImportError: pass -try: +def getversion(): + if not os.path.exists('.hg'): + return None # not in a repository + # execute hg out of this directory with a custom environment which # includes the pure Python modules in mercurial/pure pypath = os.environ.get('PYTHONPATH', '') @@ -105,23 +108,31 @@ try: os.environ['PYTHONPATH'] = os.pathsep.join(['mercurial', purepath, pypath]) os.environ['HGRCPATH'] = '' # do not read any config file cmd = '%s hg id -it' % sys.executable - l = os.popen(cmd).read().split() + + try: + l = os.popen(cmd).read().split() + except OSError, e: + print "warning: could not establish Mercurial version: %s" % e + os.environ['PYTHONPATH'] = pypath + while len(l) > 1 and l[-1][0].isalpha(): # remove non-numbered tags l.pop() - version = l and l[-1] or 'unknown' # latest tag or revision number - if version.endswith('+'): - version += time.strftime('%Y%m%d') + if l: + version = l[-1] # latest tag or revision number + if version.endswith('+'): + version += time.strftime('%Y%m%d') + return version -except OSError, e: - print "warning: could not establish Mercurial version: %s" % e +version = getversion() +if version: + f = file("mercurial/__version__.py", "w") + f.write('# this file is autogenerated by setup.py\n') + f.write('version = "%s"\n' % version) + f.close() +else: version = "unknown" -f = file("mercurial/__version__.py", "w") -f.write('# this file is autogenerated by setup.py\n') -f.write('version = "%s"\n' % version) -f.close() - class install_package_data(install_data): def finalize_options(self): self.set_undefined_options('install',