From 99f306378fe9ae016a78a765b565ab60685b1b66 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Wed, 10 Apr 2024 13:05:19 -0500 Subject: [PATCH 1/3] store env vars as constant --- logpyle/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) 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): From 651c99da1e4aefefa45df6b23ed2dea9f50e0f17 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Wed, 10 Apr 2024 13:24:18 -0500 Subject: [PATCH 2/3] fix test --- test/test_gather.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_gather.py b/test/test_gather.py index 4acb998..3d61bcc 100644 --- a/test/test_gather.py +++ b/test/test_gather.py @@ -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") @@ -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: From c3b20008c1fc9043cffee7839531395e73a1f1e4 Mon Sep 17 00:00:00 2001 From: Matthias Diener Date: Wed, 10 Apr 2024 15:08:13 -0500 Subject: [PATCH 3/3] add type annotations --- test/test_gather.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_gather.py b/test/test_gather.py index 3d61bcc..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." @@ -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")