Skip to content

Commit bdcdf7f

Browse files
committed
Only store version string in one place
This requires a bit of a hack for setup.py, but it should be safe.
1 parent ccdb29d commit bdcdf7f

4 files changed

Lines changed: 20 additions & 21 deletions

File tree

bin/bugzilla

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import xmlrpclib
2525
import bugzilla
2626
import bugzilla.util
2727

28-
version = '0.7.0'
2928
default_bz = 'https://bugzilla.redhat.com/xmlrpc.cgi'
3029

3130
_is_unittest = bool(os.getenv("__BUGZILLA_UNITTEST"))
@@ -80,7 +79,7 @@ def open_without_clobber(name, *args):
8079
def setup_parser():
8180
u = ("%%prog [global options] COMMAND [command-options]"
8281
"\nCommands: %s" % ','.join(cmdlist))
83-
p = optparse.OptionParser(usage=u, version=version)
82+
p = optparse.OptionParser(usage=u, version=bugzilla.__version__)
8483
p.disable_interspersed_args()
8584
p.epilog = 'Try "bugzilla COMMAND --help" for command-specific help.'
8685

@@ -358,7 +357,7 @@ by Bugzilla.
358357
.I \\fR * attach - attach files to existing bugs, or get attachments
359358
.br
360359
.I \\fR * info - get info about the given bugzilla instance
361-
''' % (datestr, version)
360+
''' % (datestr, bugzilla.__version__)
362361

363362
manformatter = ManHelpFormatter()
364363
parser = setup_parser()

bugzilla/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@
99
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
1010
# the full text of the license.
1111

12+
__version__ = "0.7.0"
13+
version = __version__
14+
1215
import logging
1316
import xmlrpclib
1417

15-
from bugzilla.base import version
1618
from bugzilla.bugzilla3 import Bugzilla3, Bugzilla32, Bugzilla34, Bugzilla36
1719
from bugzilla.bugzilla4 import Bugzilla4
1820
from bugzilla.nvlbugzilla import NovellBugzilla
1921
from bugzilla.rhbugzilla import RHBugzilla, RHBugzilla3, RHBugzilla4
2022

21-
log = logging.getLogger("bugzilla")
22-
2323
# advertised class list
2424
classlist = ['Bugzilla3', 'Bugzilla32', 'Bugzilla34',
2525
'Bugzilla36', 'Bugzilla4', 'RHBugzilla3', 'RHBugzilla4',
2626
'NovellBugzilla']
2727

28+
log = logging.getLogger("bugzilla")
29+
30+
2831

2932
def getBugzillaClassForURL(url):
3033
log.debug("Choosing subclass for %s" % url)
@@ -76,7 +79,7 @@ class Bugzilla(object):
7679
to use and uses that. Requires 'url' parameter so we can check available
7780
XMLRPC methods to determine the Bugzilla version.'''
7881
def __init__(self, **kwargs):
79-
log.info("Bugzilla v%s initializing" % version)
82+
log.info("Bugzilla v%s initializing" % __version__)
8083
if 'url' not in kwargs:
8184
raise TypeError("You must pass a valid bugzilla xmlrpc.cgi URL")
8285

bugzilla/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
import urllib2
1919
import xmlrpclib
2020

21+
from bugzilla import __version__
22+
2123
log = logging.getLogger('bugzilla')
2224

23-
version = '0.7.0'
2425
user_agent = ('Python-urllib2/%s bugzilla.py/%s' %
25-
(urllib2.__version__, version))
26+
(urllib2.__version__, __version__))
2627

2728

2829
class BugzillaError(Exception):

setup.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55

66
from distutils.core import setup, Command
77

8-
# XXX: importing this here means any external requirements are
9-
# required at RPM build time. Should store canonical version in its
10-
# own file
11-
import bugzilla.base
8+
9+
def get_version():
10+
f = open("bugzilla/__init__.py")
11+
for line in f:
12+
if line.startswith('__version__'):
13+
return eval(line.split('=')[-1])
14+
1215

1316
class TestCommand(Command):
1417
user_options = [
@@ -38,13 +41,6 @@ def run(self):
3841
cov.erase()
3942
cov.start()
4043

41-
# Reload the library so we get accurate coverage data
42-
for name in dir(bugzilla):
43-
attr = getattr(bugzilla, name)
44-
if type(attr) is type(bugzilla):
45-
reload(attr)
46-
reload(bugzilla)
47-
4844
testfiles = []
4945
for t in glob.glob(os.path.join(os.getcwd(), 'tests', '*.py')):
5046
if t.endswith("__init__.py"):
@@ -135,7 +131,7 @@ def run(self):
135131

136132

137133
setup(name='python-bugzilla',
138-
version=str(bugzilla.base.version),
134+
version=get_version(),
139135
description='Bugzilla XMLRPC access module',
140136
author='Will Woods',
141137
author_email='[email protected]',

0 commit comments

Comments
 (0)