forked from diffpy/diffpy.pdfgui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.py
53 lines (43 loc) · 1.56 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
#!/usr/bin/env python
##############################################################################
#
# PDFgui by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2008 trustees of the Michigan State University.
# All rights reserved.
#
# File coded by: Pavol Juhas
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE.txt for license information.
#
##############################################################################
"""
Definition of __version__, __date__, __timestamp__, __git_commit__.
Notes
-----
Variable `__gitsha__` is deprecated as of version 1.2.
Use `__git_commit__` instead.
"""
__all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"]
import os.path
from importlib.resources import files
# obtain version information from the version.cfg file
cp = dict(version="", date="", commit="", timestamp="0")
fcfg = str(files(__name__).joinpath("version.cfg"))
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)
__version__ = cp["version"]
__date__ = cp["date"]
__git_commit__ = cp["commit"]
__timestamp__ = int(cp["timestamp"])
# TODO remove deprecated __gitsha__ in version 1.3.
__gitsha__ = __git_commit__
del cp, fcfg, fp, kwords
# End of file