diff --git a/logpyle/__init__.py b/logpyle/__init__.py index 78b0b85..810dfc8 100644 --- a/logpyle/__init__.py +++ b/logpyle/__init__.py @@ -1701,6 +1701,12 @@ def add_simulation_quantities(mgr: LogManager) -> None: mgr.add_quantity(Timestep()) +def _get_env_vars() -> str: + """Return a string containing all environment variables.""" + from os import environ + return "\n".join(f"{key}={value}" for key, value in environ.items()) + + def add_run_info(mgr: LogManager) -> None: """Add generic run metadata, such as command line, host, and time.""" @@ -1717,6 +1723,7 @@ def add_run_info(mgr: LogManager) -> None: from time import localtime, strftime, time mgr.set_constant("date", strftime("%a, %d %b %Y %H:%M:%S %Z", localtime())) mgr.set_constant("unixtime", time()) + mgr.set_constant("env", _get_env_vars()) class MemoryHwm(PostLogQuantity): diff --git a/test/test_gather.py b/test/test_gather.py index 4acb998..211c1e9 100644 --- a/test/test_gather.py +++ b/test/test_gather.py @@ -11,7 +11,7 @@ def __call__(self) -> int: return 15 -def create_log(filename: str): +def create_log(filename: str) -> None: logmgr = LogManager(filename, "wo") # Generic run metadata, such as command line, host, and time @@ -40,7 +40,7 @@ def create_log(filename: str): logmgr.close() -def test_auto_gather_single(): +def test_auto_gather_single() -> None: # run example create_log("log.sqlite") assert os.path.exists("log.sqlite"), "The logging file was not generated." @@ -77,7 +77,7 @@ def test_auto_gather_single(): print("Constant data:") result = [row[0] for row in cur.description] print(result) - assert len(result) == 11 + assert len(result) == 12 db = make_wrapped_db(["log.sqlite"], mangle=True, interactive=False) cur = db.q("select $fifteen") @@ -91,7 +91,7 @@ def test_auto_gather_single(): os.remove("log.sqlite") -def test_auto_gather_multi(): +def test_auto_gather_multi() -> None: # run example def is_unique_filename(str: str): return str.startswith("multi-log") @@ -142,7 +142,7 @@ def is_unique_filename(str: str): print("Constant data:") result = [row[0] for row in cur.description] print(result) - assert len(result) == 11 + assert len(result) == 12 # teardown test for f in filenames: