|
13 | 13 | # |
14 | 14 | ############################################################################## |
15 | 15 |
|
16 | | -""" |
17 | | -Definition of __version__, __date__, __timestamp__, __git_commit__. |
| 16 | +"""Definition of __version__ and __date__.""" |
18 | 17 |
|
19 | | -Notes |
20 | | ------ |
21 | | -Variable `__gitsha__` is deprecated as of version 1.2. |
22 | | -Use `__git_commit__` instead. |
23 | | -""" |
| 18 | +import os |
| 19 | +import time |
| 20 | +from importlib.metadata import distribution, version |
24 | 21 |
|
25 | | -__all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"] |
26 | | - |
27 | | -import os.path |
28 | | -from importlib.resources import files |
29 | | - |
30 | | -# obtain version information from the version.cfg file |
31 | | -cp = dict(version="", date="", commit="", timestamp="0") |
32 | | -fcfg = str(files(__name__).joinpath("version.cfg")) |
33 | | -if not os.path.isfile(fcfg): # pragma: no cover |
34 | | - from warnings import warn |
35 | | - |
36 | | - warn("Package metadata not found.") |
37 | | - fcfg = os.devnull |
38 | | -with open(fcfg) as fp: |
39 | | - kwords = [[w.strip() for w in line.split(" = ", 1)] for line in fp if line[:1].isalpha() and " = " in line] |
40 | | -assert all(w[0] in cp for w in kwords), "received unrecognized keyword" |
41 | | -cp.update(kwords) |
42 | | - |
43 | | -__version__ = cp["version"] |
44 | | -__date__ = cp["date"] |
45 | | -__git_commit__ = cp["commit"] |
46 | | -__timestamp__ = int(cp["timestamp"]) |
47 | | - |
48 | | -# TODO remove deprecated __gitsha__ in version 1.3. |
49 | | -__gitsha__ = __git_commit__ |
50 | | - |
51 | | -del cp, fcfg, fp, kwords |
| 22 | +__date__ = time.ctime(os.path.getctime(distribution("diffpy.pdfgui")._path)) |
| 23 | +__version__ = version("diffpy.pdfgui") |
52 | 24 |
|
53 | 25 | # End of file |
0 commit comments