Skip to content

Commit

Permalink
merging upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillinge committed Jul 27, 2024
1 parent 6237ce2 commit 133666e
Showing 1 changed file with 41 additions and 29 deletions.
70 changes: 41 additions & 29 deletions src/regolith/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,49 @@
Use `__git_commit__` instead.
"""

__all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"]

import os.path
from importlib.resources import as_file, files

# 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"])
# __all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"]

# import os.path

# obtain version information
from importlib.metadata import version

# from importlib.resources import as_file, files
#
# # 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__
# __gitsha__ = __git_commit__
#
# del cp

# from cookiecutter in case we want to migrate later:
#
# # We do not use the other three variables, but can be added back if needed.
# # __all__ = ["__date__", "__git_commit__", "__timestamp__", "__version__"]


del cp
__version__ = version("regolith")

# End of file

0 comments on commit 133666e

Please sign in to comment.