Skip to content

Commit 5f39b8b

Browse files
method to print out runtime info
1 parent a59c105 commit 5f39b8b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

smodels/base/runtime.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,30 @@
2020

2121
_deltas_rel_default = .2 ## the default relative error on the signal strength
2222

23+
def printEnvironmentInfo( args ):
24+
""" very simple method that prints out info relevant to debugging
25+
machine-dependent problems """
26+
print ( args )
27+
import importlib, platform
28+
29+
modules = [ "scipy", "sympy", "numpy",
30+
"pyslha", "unum", "pyhf" ]
31+
32+
print("Environment Information:")
33+
print(f"Operating System: {platform.system()} {platform.release()}")
34+
print(f"Python Version: {platform.python_version()}")
35+
print(f"Machine Architecture: {platform.machine()}")
36+
print(f"Processor: {platform.processor()}")
37+
print("\nModule Versions:")
38+
39+
for module_name in modules:
40+
try:
41+
module = importlib.import_module(module_name)
42+
version = getattr(module, '__version__', 'Unknown version attribute')
43+
print(f"{module_name:<12}: {version}")
44+
except ImportError:
45+
print(f"{module_name:<12}: Not installed")
46+
2347
def filetype ( filename ):
2448
""" obtain information about the filetype of an input file,
2549
currently only used to discriminate between slha and lhe
@@ -53,12 +77,11 @@ def filetype ( filename ):
5377
return None
5478
return None
5579

56-
5780
def experimentalFeature( feature : str ) -> Union[None,bool]:
5881
""" method to check if a certain experimental feature is enabled.
5982
can be turned on and off via options:experimental in parameters.ini.
6083
:param feature: ask for feature
61-
84+
6285
:returns: None if feature does not exist, else boolean
6386
"""
6487
if not feature in _experimental:
@@ -99,4 +122,5 @@ def nCPUs():
99122
return None
100123

101124
if __name__ == "__main__":
102-
print ( f"This machine has {nCPUs()} CPUs" )
125+
printEnvironmentInfo()
126+
# print ( f"This machine has {nCPUs()} CPUs" )

smodels/tools/smodelsTools.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ def main():
142142
action='store_true')
143143
toolbox.add_argument('-m', '--make', help='compile packages if needed',
144144
action='store_true')
145+
environ_info = subparsers.add_parser( 'environ-info', description=
146+
"Simple tool to print out environment info")
147+
environ_info.add_argument('-c', '--colors', help='turn on terminal colors',
148+
action='store_true')
145149
args = parser.parse_args()
146150

147151
from smodels.base import smodelsLogging
@@ -151,6 +155,10 @@ def main():
151155
if args.subparser_name == 'fixpermissions':
152156
installation.fixpermissions()
153157

158+
if args.subparser_name == "environ-info":
159+
from smodels.base.runtime import printEnvironmentInfo
160+
printEnvironmentInfo( args )
161+
154162
if args.subparser_name == 'installation':
155163
import sys, os
156164
print(installation.banner())

0 commit comments

Comments
 (0)