From e42ba37b63d1ca8b4d2a96e2d1b5f64316fb0b51 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 12 Aug 2023 08:39:17 +0300 Subject: feat: reduce repetitive logging of environment in Python runcmd Every time runcmd.py runs a command, it uses the same environment. We only need to log it once. Sponsored-by: author --- share/python/lib/runcmd.py | 1 - share/python/template/scenarios.py | 10 +++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'share') diff --git a/share/python/lib/runcmd.py b/share/python/lib/runcmd.py index c4a6a12..6a4965f 100644 --- a/share/python/lib/runcmd.py +++ b/share/python/lib/runcmd.py @@ -70,7 +70,6 @@ def runcmd_run(ctx, argv, **kwargs): logging.debug("runcmd_run: running command") log_value("argv", 1, dict(enumerate(argv))) - log_value("env", 1, env) log_value("kwargs:", 1, kwargs) p = subprocess.Popen(argv, env=env, **kwargs) diff --git a/share/python/template/scenarios.py b/share/python/template/scenarios.py index b215133..a6aa9f4 100644 --- a/share/python/template/scenarios.py +++ b/share/python/template/scenarios.py @@ -42,12 +42,14 @@ class Step: self._cleanup(ctx, **self._args) +_logged_env = False + + class Scenario: def __init__(self, ctx): self._title = None self._steps = [] self._ctx = ctx - self._logged_env = False def get_title(self): return self._title @@ -91,7 +93,9 @@ class Scenario: os.environ.update(overrides) os.environ.update(extra_env) - if not self._logged_env: - self._logged_env = True + global _logged_env + if not _logged_env: + _logged_env = True log_value("extra_env", 0, dict(extra_env)) + log_value("overrides", 0, dict(overrides)) log_value("os.environ", 0, dict(os.environ)) -- cgit v1.2.1