|
| 1 | +import os.path |
| 2 | +import re |
| 3 | +import subprocess |
1 | 4 | from setuptools import setup, find_packages |
2 | 5 |
|
| 6 | +def get_version(): |
| 7 | + """Get version from git or file system. |
| 8 | +
|
| 9 | + If this is a git repository, try to get the version number by |
| 10 | + running ``git describe``, then store it in |
| 11 | + bioformats/_version.py. Otherwise, try to load the version number |
| 12 | + from that file. If both methods fail, quietly return None. |
| 13 | +
|
| 14 | + """ |
| 15 | + git_version = None |
| 16 | + if os.path.exists(os.path.join(os.path.dirname(__file__), '.git')): |
| 17 | + import subprocess |
| 18 | + try: |
| 19 | + git_version = subprocess.check_output(['git', 'describe']).strip() |
| 20 | + except: |
| 21 | + pass |
| 22 | + |
| 23 | + version_file = os.path.join(os.path.dirname(__file__), 'bioformats', |
| 24 | + '_version.py') |
| 25 | + if os.path.exists(version_file): |
| 26 | + with open(version_file) as f: |
| 27 | + cached_version_line = f.read().strip() |
| 28 | + try: |
| 29 | + # From http://stackoverflow.com/a/3619714/17498 |
| 30 | + cached_version = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", |
| 31 | + cached_version_line, re.M).group(1) |
| 32 | + except: |
| 33 | + raise RuntimeError("Unable to find version in %s" % version_file) |
| 34 | + else: |
| 35 | + cached_version = None |
| 36 | + |
| 37 | + if git_version and git_version != cached_version: |
| 38 | + with open(version_file, 'w') as f: |
| 39 | + print >>f, '__version__ = "%s"' % git_version |
| 40 | + |
| 41 | + return git_version or cached_version |
| 42 | + |
3 | 43 | setup( |
4 | 44 | name="python-bioformats", |
5 | | - version="1.0.0pr3", |
| 45 | + version=get_version(), |
6 | 46 | description="Read and write life sciences file formats", |
7 | 47 | long_description='''Python-bioformats is a Python wrapper for Bio-Formats, a standalone |
8 | 48 | Java library for reading and writing life sciences image file |
|
0 commit comments