Move version code into setup.py
getversion() is only needed by setup.py,
as there is no interface to query the version of an hg extension.
--- a/.hgignore Sun Sep 02 15:46:18 2007 +0200
+++ b/.hgignore Sun Sep 02 17:04:22 2007 +0200
@@ -9,4 +9,3 @@
build/*
MANIFEST
-hgkw/__version__.py
--- a/MANIFEST.in Sun Sep 02 15:46:18 2007 +0200
+++ b/MANIFEST.in Sun Sep 02 17:04:22 2007 +0200
@@ -1,7 +1,5 @@
# $Id$
-exclude hgkw/__version__.py
-
include tests/test-keyword tests/test-keyword.out
include MANIFEST.in
--- a/hgkw/version.py Sun Sep 02 15:46:18 2007 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,46 +0,0 @@
-# $Id$
-
-'''version.py - hgkw version.
-Code stolen from Mercurial, and simplified for my needs.
-'''
-
-import os, time
-
-unknown_version = 'unknown'
-
-def getversion(doreload=False):
- try:
- import hgkw.__version__
- if doreload:
- reload(hgkw.__version__)
- version = hgkw.__version__.version
- except ImportError:
- version = unknown_version
- return version
-
-def rememberversion(version=None):
- if not version and os.path.isdir('.hg'):
- # get version from Mercurial
- p = os.popen('hg --quiet identify 2> %s' % os.devnull)
- ident = p.read()[:-1]
- if not p.close() and ident:
- if ident[-1] != '+':
- version = ident
- else:
- version = ident[:-1]
- version += time.strftime('+%Y%m%d')
- if version and version != getversion(): # write version
- directory = os.path.dirname(__file__)
- for suff in ['py', 'pyc', 'pyo']:
- try:
- os.unlink(os.path.join(directory, '__version__.%s' % suff))
- except OSError:
- pass
- f = open(os.path.join(directory, '__version__.py'), 'w')
- try:
- f.write('# this file is auto-generated\n')
- f.write('version = %r\n' % version)
- finally:
- f.close()
- # reload file
- getversion(doreload=True)
--- a/setup.py Sun Sep 02 15:46:18 2007 +0200
+++ b/setup.py Sun Sep 02 17:04:22 2007 +0200
@@ -2,15 +2,28 @@
# $Id$
from distutils.core import setup
-import hgkw.version
+import os, time
# specify version, Mercurial version otherwise
version = ''
-hgkw.version.rememberversion(version)
+unknown_version = 'unknown'
+
+def getversion():
+ global version, unknown_version
+ if not version and os.path.isdir('.hg'):
+ p = os.popen('hg --quiet identify 2> %s' % os.devnull)
+ ident = p.read()[:-1]
+ if not p.close() and ident:
+ if ident[-1] != '+':
+ version = ident
+ else:
+ version = ident[:-1]
+ version += time.strftime('+%Y%m%d')
+ return version or unknown_version
setup(name='hgkw',
- version=hgkw.version.getversion(),
+ version=getversion(),
description='Mercurial keyword extension (standalone)',
author='Christian Ebert',
author_email='blacktrash@gmx.net',