forked from diffpy/diffpy.utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.py
58 lines (47 loc) · 1.73 KB
/
version.py
1
2
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
##############################################################################
#
# diffpy.utils by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2011 The Trustees of Columbia University
# in the City of New York. All rights reserved.
#
# File coded by: Pavol Juhas
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE_DANSE.txt for license information.
#
##############################################################################
"""
Definition of __version__, __date__, __timestamp__, __git_commit__.
Notes
-----
Variable `__gitsha__` is deprecated as of version 3.0.
Use `__git_commit__` instead.
"""
__all__ = ['__date__', '__git_commit__', '__timestamp__', '__version__']
import os.path
from importlib.resources import files, as_file
# obtain version information from the version.cfg file
cp = dict(version='', date='', commit='', timestamp='0')
if __package__ is not None:
ref = files(__package__) / 'version.cfg'
with as_file(ref) as fcfg:
if not os.path.isfile(fcfg): # pragma: no cover
from warnings import warn
warn('Package metadata not found.')
fcfg = os.devnull
with open(fcfg) as fp:
kwords = [[w.strip() for w in line.split(' = ', 1)]
for line in fp if line[:1].isalpha() and ' = ' in line]
assert all(w[0] in cp for w in kwords), "received unrecognized keyword"
cp.update(kwords)
del kwords
__version__ = cp['version']
__date__ = cp['date']
__git_commit__ = cp['commit']
__timestamp__ = int(cp['timestamp'])
# TODO remove deprecated __gitsha__ in version 3.1.
__gitsha__ = __git_commit__
del cp
# End of file