python: Have setup.py read the version number without importing

Importing the notmuch module in setup.py is a no-no, and we want
to auto-generate the version number in the release process.

Outsource __VERSION__ to the new version.py which contains nothing else
and which can therefor easily be autogenerated. Have setup.py read in
the file via execfile and test if importing the version number actually
worked.

This should make all happy.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2011-08-24 09:13:34 +02:00
parent 2fceb738c7
commit 5dc189c82d
3 changed files with 8 additions and 13 deletions

View file

@ -57,6 +57,6 @@ from notmuch.message import Messages, Message
from notmuch.thread import Threads, Thread from notmuch.thread import Threads, Thread
from notmuch.tag import Tags from notmuch.tag import Tags
from notmuch.globals import nmlib, STATUS, NotmuchError from notmuch.globals import nmlib, STATUS, NotmuchError
from notmuch.version import __VERSION__
__LICENSE__ = "GPL v3+" __LICENSE__ = "GPL v3+"
__VERSION__ = '0.6'
__AUTHOR__ = 'Sebastian Spaeth <Sebastian@SSpaeth.de>' __AUTHOR__ = 'Sebastian Spaeth <Sebastian@SSpaeth.de>'

View file

@ -0,0 +1,2 @@
# This file is potentially auto-generated. Do not modify
__VERSION__ = '0.6'

View file

@ -4,18 +4,11 @@ import os
import re import re
from distutils.core import setup from distutils.core import setup
def get_version(): # get the notmuch version number without importing the notmuch module
file = open('notmuch/__init__.py') version_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
try: 'notmuch', 'version.py')
for line in file: execfile(version_file)
if re.match('__VERSION__\s*=\s*',line) != None: assert __VERSION__, 'Failed to read the notmuch binding version number'
version = line.split('=', 1)[1]
return eval(version, {}, {})
finally:
file.close()
raise IOError('Unexpected end-of-file')
__VERSION__=get_version()
setup(name='notmuch', setup(name='notmuch',
version=__VERSION__, version=__VERSION__,