Skip to content

Commit 089850b

Browse files
mention also git commit id in environment info
1 parent d1134bf commit 089850b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

smodels/base/runtime.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ def checkForIncompatibleModuleVersions():
3333

3434
checkForIncompatibleModuleVersions()
3535

36+
def returnGitCommitId():
37+
""" if we are in a git-managed repository, return the git commit id """
38+
try:
39+
import subprocess
40+
# Check if we're inside a Git repository
41+
subprocess.run(
42+
['git', 'rev-parse', '--is-inside-work-tree'],
43+
stdout=subprocess.DEVNULL,
44+
stderr=subprocess.DEVNULL,
45+
check=True
46+
)
47+
48+
# Get the current commit hash
49+
commit = subprocess.check_output(
50+
['git', 'rev-parse', 'HEAD'],
51+
stderr=subprocess.DEVNULL
52+
).decode('utf-8').strip()
53+
54+
return commit
55+
56+
except subprocess.CalledProcessError:
57+
# Not a Git repo, or git command failed—do nothing
58+
return None
59+
3660
def printEnvironmentInfo( args : Dict ):
3761
""" very simple method that prints out info relevant to debugging
3862
machine-dependent problems
@@ -63,6 +87,9 @@ def printEnvironmentInfo( args : Dict ):
6387
except ImportError:
6488
print(f"{module_name:<12}: Not installed")
6589
depsMet = False
90+
gitId = returnGitCommitId()
91+
if gitId != None:
92+
print ( f"\ngit commit: {gitId}" )
6693
return depsMet
6794

6895
def filetype ( filename : os.PathLike ) -> Union[Text,None]:

0 commit comments

Comments
 (0)