|
5 | 5 | import os |
6 | 6 | import platform |
7 | 7 | import sys |
| 8 | +import subprocess |
8 | 9 |
|
9 | 10 | from distutils.command.build import build |
10 | 11 | from setuptools import setup |
11 | 12 | from setuptools.command.install import install as _install |
12 | 13 |
|
13 | | -from bpython import __version__, package_dir |
| 14 | +from bpython import package_dir |
14 | 15 |
|
15 | 16 | try: |
16 | 17 | from babel.messages.frontend import compile_catalog as _compile_catalog |
|
33 | 34 | except ImportError: |
34 | 35 | using_sphinx = False |
35 | 36 |
|
| 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 | + |
36 | 56 | class install(_install): |
37 | 57 | """Force install to run build target.""" |
38 | 58 |
|
39 | 59 | def run(self): |
40 | 60 | self.run_command('build') |
41 | 61 | _install.run(self) |
42 | 62 |
|
43 | | -cmdclass = dict(build=build, install=install) |
| 63 | +cmdclass = { |
| 64 | + 'build': build, |
| 65 | + 'install': install |
| 66 | +} |
| 67 | + |
44 | 68 | translations_dir = os.path.join(package_dir, 'translations') |
45 | 69 |
|
46 | 70 | # localization options |
@@ -172,7 +196,7 @@ def initialize_options(self): |
172 | 196 |
|
173 | 197 | setup( |
174 | 198 | name="bpython", |
175 | | - version = __version__, |
| 199 | + version = version, |
176 | 200 | author = "Bob Farrell, Andreas Stuehrk et al.", |
177 | 201 | author_email = "robertanthonyfarrell@gmail.com", |
178 | 202 | description = "Fancy Interface to the Python Interpreter", |
|
0 commit comments