Skip to content

Commit a36f902

Browse files
Merge pull request #2 from elenagonzalez870/commit_hash
Adding feature to extract commit hash
2 parents 63ac010 + d2c89cc commit a36f902

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ py3 = import('python').find_installation()
1616
numpy_include_dir = run_command(py3, ['-c', 'import numpy; print(numpy.get_include())'], check: true).stdout().strip()
1717
f2py_include_dir = run_command(py3, ['-c', 'import numpy.f2py; print(numpy.f2py.get_include())'], check: true).stdout().strip()
1818
inc_np = include_directories(numpy_include_dir, f2py_include_dir)
19-
19+
get_hash = run_command('python', './src/cosmic/get_commit_hash.py', check: true).stdout().strip()
2020
f2py_source = custom_target(
2121
'evolvebin-target',
2222
input : ['src/cosmic/src/evolv2.f', 'src/cosmic/src/comprad.f'],

src/cosmic/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
"""
2222

2323
from ._version import __version__
24+
from ._commit_hash import COMMIT_HASH
2425

2526
__version__ = __version__
27+
__commithash__ = COMMIT_HASH
2628
__author__ = "Katie Breivik <katie.breivik@gmail.com>"
2729
__credits__ = [
2830
"Scott Coughlin <scott.coughlin@ligo.org>",

src/cosmic/get_commit_hash.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import subprocess
2+
3+
def get_commit_hash():
4+
# Run git command to get the latest commit hash
5+
result = subprocess.run(['git', 'rev-parse', 'HEAD'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
6+
commit_hash = result.stdout.decode('utf-8').strip()
7+
return commit_hash
8+
9+
def write_commit_hash_to_file(commit_hash):
10+
with open('./src/cosmic/_commit_hash.py', 'w') as f:
11+
f.write(f'COMMIT_HASH = "{commit_hash}"\n')
12+
13+
if __name__ == "__main__":
14+
commit_hash = get_commit_hash()
15+
write_commit_hash_to_file(commit_hash)

0 commit comments

Comments
 (0)