|
13 | 13 | # |
14 | 14 | ############################################################################## |
15 | 15 |
|
| 16 | +""" |
| 17 | +Definition of __version__, __date__, __timestamp__, __git_commit__, |
| 18 | +libobjcryst_version_info. |
16 | 19 |
|
17 | | -"""Definition of __version__, __date__, __gitsha__, libobjcryst_version_info. |
| 20 | +Notes |
| 21 | +----- |
| 22 | +Variable `__gitsha__` is deprecated as of version 2.1. |
| 23 | +Use `__git_commit__` instead. |
18 | 24 | """ |
19 | 25 |
|
| 26 | +__all__ = ['__date__', '__git_commit__', '__timestamp__', '__version__', |
| 27 | + 'libobjcryst_version_info'] |
| 28 | + |
| 29 | +import os.path |
| 30 | + |
20 | 31 | from pkg_resources import resource_filename |
21 | 32 |
|
22 | | -import sys |
23 | | -if sys.version_info[0] >= 3: |
24 | | - from configparser import RawConfigParser |
25 | | -else: |
26 | | - from ConfigParser import RawConfigParser |
27 | | -del sys |
28 | 33 |
|
29 | 34 | # obtain version information from the version.cfg file |
30 | | -cp = RawConfigParser(dict(version='', date='', commit='', timestamp=0)) |
31 | | -if not cp.read(resource_filename(__name__, 'version.cfg')): |
| 35 | +cp = dict(version='', date='', commit='', timestamp='0') |
| 36 | +fcfg = resource_filename(__name__, 'version.cfg') |
| 37 | +if not os.path.isfile(fcfg): # pragma: no cover |
32 | 38 | from warnings import warn |
33 | 39 | warn('Package metadata not found, execute "./setup.py egg_info".') |
| 40 | + fcfg = os.devnull |
| 41 | +with open(fcfg) as fp: |
| 42 | + kwords = [[w.strip() for w in line.split(' = ', 1)] |
| 43 | + for line in fp if line[:1].isalpha() and ' = ' in line] |
| 44 | +assert all(w[0] in cp for w in kwords), "received unrecognized keyword" |
| 45 | +cp.update(kwords) |
| 46 | + |
| 47 | +__version__ = cp['version'] |
| 48 | +__date__ = cp['date'] |
| 49 | +__git_commit__ = cp['commit'] |
| 50 | +__timestamp__ = int(cp['timestamp']) |
34 | 51 |
|
35 | | -__version__ = cp.get('DEFAULT', 'version') |
36 | | -__date__ = cp.get('DEFAULT', 'date') |
37 | | -__gitsha__ = cp.get('DEFAULT', 'commit') |
38 | | -__timestamp__ = cp.getint('DEFAULT', 'timestamp') |
| 52 | +# TODO remove deprecated __gitsha__ in version 2.2. |
| 53 | +__gitsha__ = __git_commit__ |
39 | 54 |
|
40 | | -del cp |
| 55 | +del cp, fcfg, fp, kwords |
41 | 56 |
|
42 | 57 | # version information on the active libObjCryst library ---------------------- |
43 | 58 |
|
|
0 commit comments