From 86e31dbe7ef9d07a852f331a728ab565e2b3b168 Mon Sep 17 00:00:00 2001 From: tmcguinness Date: Tue, 11 Jun 2024 19:51:27 +0000 Subject: [PATCH] added dynamic regex with export --- src/wxflow/configuration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wxflow/configuration.py b/src/wxflow/configuration.py index 2a527d1..d2b6c81 100644 --- a/src/wxflow/configuration.py +++ b/src/wxflow/configuration.py @@ -1,5 +1,6 @@ import glob import os +import re import random import shutil import subprocess @@ -98,8 +99,9 @@ def _get_script_env(cls, scripts: List) -> Dict[str, Any]: default_env = cls._get_shell_env([]) and_script_env = cls._get_shell_env(scripts) keys_in_scripts = set() + regex_pattern = 'export\\s+\\b(' + '|'.join(map(re.escape, default_env.keys())) + ')(?==)' for script in scripts: - result = subprocess.run(['grep', '-o', '-P', '\\b(' + '|'.join(default_env.keys()) + ')(?==)', script], stdout=subprocess.PIPE) + result = subprocess.run(['grep', '-o', '-P', regex_pattern, script], stdout=subprocess.PIPE) keys_in_scripts.update(result.stdout.decode().split()) vars_just_in_script = set(and_script_env) - set(default_env) | keys_in_scripts union_env = dict(default_env)