__init__.py 3.7 KB
Newer Older
Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
1
2
# coding=utf-8
"""
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
.. .......................................................................... ..
..          ARIA -- Ambiguous Restraints for Iterative Assignment             ..
..                                                                            ..
..                A software for automated NOE assignment                     ..
..                                                                            ..
..                               Version 2.3                                  ..
..                                                                            ..
..                                                                            ..
.. Copyright (C) Benjamin Bardiaux, Michael Habeck, Therese Malliavin,        ..
..              Wolfgang Rieping, and Michael Nilges                          ..
..                                                                            ..
.. All rights reserved.                                                       ..
..                                                                            ..
.. NO WARRANTY. This software package is provided 'as is' without warranty of ..
.. any kind, expressed or implied, including, but not limited to the implied  ..
.. warranties of merchantability and fitness for a particular purpose or      ..
.. a warranty of non-infringement.                                            ..
..                                                                            ..
.. Distribution of substantively modified versions of this module is          ..
.. prohibited without the explicit permission of the copyright holders.       ..
..                                                                            ..
.. $Author: bardiaux $                                                        ..
.. $Revision: 1.1.1.1 $                                                       ..
.. $Date: 2010/03/23 15:27:24 $                                               ..
.. .......................................................................... ..
Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
28
29
"""

Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
30
31
32
33
import re
import os
import sys
import subprocess
Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
34
from aria.core import *
35
from os.path import dirname, isdir, join
Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
36
37
38
39
40
41
42
43
44
45
46
47


VERSION_RE = re.compile('^Version: (.+)$', re.M)


def get_version(full=True):
    """

    Returns
    -------

    """
48
    d = dirname(dirname(__file__))
Fabrice  ALLAIN's avatar
Fabrice ALLAIN committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    # TODO: actually no warning when git command is not available !!
    if isdir(join(d, '.git')):
        # Get the version using "git describe".
        cmd = 'git describe --tags'.split()
        try:
            version = subprocess.check_output(cmd).decode().strip()
        except subprocess.CalledProcessError:
            print('Unable to get version number from git tags')
            sys.exit(1)

        # PEP 386 compatibility

        if '-' in version and full:
            version = '.post'.join(version.split('-')[:2])
        else:
            version = version.split('-')[0]

        # Don't declare a version "dirty" merely because a time stamp has
        # changed. If it is dirty, append a ".dev1" suffix to indicate a
        # development revision after the release.
        with open(os.devnull, 'w') as fd_devnull:
            subprocess.call(['git', 'status'],
                            stdout=fd_devnull, stderr=fd_devnull)

        cmd = 'git diff-index --name-only HEAD'.split()
        try:
            dirty = subprocess.check_output(cmd).decode().strip()
        except subprocess.CalledProcessError:
            print('Unable to get git index status')
            sys.exit(1)

        if dirty != '' and full:
            version += '.dev1'

    else:
        # Extract the version from the PKG-INFO file.
        with open(join(d, 'PKG-INFO')) as foo:
            version = VERSION_RE.search(foo.read()).group(1)

    return version