|
| 1 | +#!/usr/bin/env python |
| 2 | +from __future__ import division |
| 3 | + |
| 4 | +""" |
| 5 | +Version numbering for astropy. The `major`, `minor`, and `bugfix` varaibles hold |
| 6 | +the respective parts of the version number (bugfix is '0' if absent). The |
| 7 | +`release` variable is True if this is a release, and False if this is a |
| 8 | +development version of astropy. For the actual version string, use:: |
| 9 | +
|
| 10 | + from astropy.version import version |
| 11 | + |
| 12 | +or:: |
| 13 | +
|
| 14 | + from astropy import __version__ |
| 15 | + |
| 16 | +""" |
| 17 | + |
| 18 | +version = '0.0dev' |
| 19 | + |
| 20 | + |
| 21 | +_versplit = version.replace('dev','').split('.') |
| 22 | +major = int(_versplit[0]) |
| 23 | +minor = int(_versplit[1]) |
| 24 | +bugfix = 0 if len(_versplit)<3 else int(_versplit[2]) |
| 25 | +del _versplit |
| 26 | + |
| 27 | +release = not version.endswith('dev') |
| 28 | + |
| 29 | + |
| 30 | +def _get_git_devstr(sha=False): |
| 31 | + r"""Determines the number of revisions in this repository. |
| 32 | +
|
| 33 | + These |
| 34 | +
|
| 35 | + Parameters |
| 36 | + ---------- |
| 37 | + sha : bool |
| 38 | + If True, the full SHA1 hash will be at the end of the devstr. Otherwise, |
| 39 | + the total count of commits in the repository will be used as a "revision |
| 40 | + number". |
| 41 | +
|
| 42 | + Returns |
| 43 | + ------- |
| 44 | + devstr : str |
| 45 | + A string that begins with 'dev' to be appended to the astropy version |
| 46 | + number string. |
| 47 | + |
| 48 | + """ |
| 49 | + from os import path |
| 50 | + from subprocess import Popen,PIPE |
| 51 | + from warnings import warn |
| 52 | + |
| 53 | + if release: |
| 54 | + raise ValueError('revsion devstring should not be used in a release version') |
| 55 | + |
| 56 | + currdir = path.abspath(path.split(__file__)[0]) |
| 57 | + |
| 58 | + p = Popen(['git','rev-list','HEAD'],cwd=currdir, |
| 59 | + stdout=PIPE,stderr=PIPE,stdin=PIPE) |
| 60 | + stdout,stderr = p.communicate() |
| 61 | + |
| 62 | + if p.returncode == 128: |
| 63 | + warn('No git repository present! Using default dev version.') |
| 64 | + return '' |
| 65 | + elif p.returncode != 0: |
| 66 | + warn('Git failed while determining revision count: '+stderr) |
| 67 | + return '' |
| 68 | + |
| 69 | + if sha: |
| 70 | + return '-git-'+stdout[:40] |
| 71 | + else: |
| 72 | + nrev = stdout.count('\n') |
| 73 | + return '-r%i'%nrev |
| 74 | + |
| 75 | +if not release: |
| 76 | + version = version+_get_git_devstr(False) |
| 77 | + |
| 78 | +#This is used by setup.py to create a new version.py - see that file for details |
| 79 | +_frozen_version_py_template = """ |
| 80 | +#Autogenerated by astropy's setup.py on {timestamp} |
| 81 | +version = '{verstr}' |
| 82 | +
|
| 83 | +major = {maj} |
| 84 | +minor = {min} |
| 85 | +bugfix = {bugfix} |
| 86 | +
|
| 87 | +release = {rel} |
| 88 | +"""[1:] |
| 89 | + |
| 90 | +def _get_version_py_str(self): |
| 91 | + import datetime |
| 92 | + |
| 93 | + timestamp = str(datetime.datetime.now()) |
| 94 | + return _frozen_version_py_template.format(timestamp=timestamp, |
| 95 | + verstr=version, |
| 96 | + maj=major, |
| 97 | + minor=minor, |
| 98 | + bugfix=bugfix, |
| 99 | + rel=release) |
0 commit comments