X Tutup
Skip to content

Commit 25838bf

Browse files
committed
Automatic versioning (fixes #333)
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
1 parent 347c7c8 commit 25838bf

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ env
99
.DS_Store
1010
.idea/
1111
doc/sphinx/build/*
12+
bpython/_version.py

bpython/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
# THE SOFTWARE.
2222

2323
import os.path
24+
import bpython._version
2425

25-
__version__ = 'git'
26+
27+
__version__ = bpython._version.__version__
2628
package_dir = os.path.abspath(os.path.dirname(__file__))
2729

2830

setup.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import os
66
import platform
77
import sys
8+
import subprocess
89

910
from distutils.command.build import build
1011
from setuptools import setup
1112
from setuptools.command.install import install as _install
1213

13-
from bpython import __version__, package_dir
14+
from bpython import package_dir
1415

1516
try:
1617
from babel.messages.frontend import compile_catalog as _compile_catalog
@@ -33,14 +34,37 @@
3334
except ImportError:
3435
using_sphinx = False
3536

37+
38+
# version handling
39+
version_file = 'bpython/_version.py'
40+
41+
try:
42+
# get version from git describe
43+
version = subprocess.check_output(['git', 'describe', '--tags']).rstrip()
44+
except OSError:
45+
try:
46+
# get version from existing version file
47+
with open(version_file) as vf:
48+
version = vf.read().strip().split('=')[-1].replace('\'', '')
49+
except IOError:
50+
version = 'unknown'
51+
52+
with open(version_file, 'w') as vf:
53+
vf.write('# Auto-generated file, do not edit!\n')
54+
vf.write('__version__=\'%s\'\n' % (version, ))
55+
3656
class install(_install):
3757
"""Force install to run build target."""
3858

3959
def run(self):
4060
self.run_command('build')
4161
_install.run(self)
4262

43-
cmdclass = dict(build=build, install=install)
63+
cmdclass = {
64+
'build': build,
65+
'install': install
66+
}
67+
4468
translations_dir = os.path.join(package_dir, 'translations')
4569

4670
# localization options
@@ -172,7 +196,7 @@ def initialize_options(self):
172196

173197
setup(
174198
name="bpython",
175-
version = __version__,
199+
version = version,
176200
author = "Bob Farrell, Andreas Stuehrk et al.",
177201
author_email = "robertanthonyfarrell@gmail.com",
178202
description = "Fancy Interface to the Python Interpreter",

0 commit comments

Comments
 (0)
X Tutup