Skip to content

Commit

Permalink
simplfied version of _get_script_env classmethond in Configuration Class
Browse files Browse the repository at this point in the history
  • Loading branch information
TerryMcGuinness-NOAA committed Jun 26, 2024
1 parent 761bcdf commit 5382a0e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/wxflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,14 @@ def print_config(self, files: Union[str, bytes, list]) -> None:

@classmethod
def _get_script_env(cls, scripts: List) -> Dict[str, Any]:
varbles = dict()
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())) + ')(?==)'
regex_pattern = '\\b(' + '|'.join(map(re.escape, default_env.keys())) + ')(?==)'
for script in scripts:
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)
union_env.update(and_script_env)
return dict([(v, union_env[v]) for v in vars_just_in_script])

for key, value in and_script_env.items():
if key not in default_env or default_env[key] != value:
varbles[key] = value
return varbles

@staticmethod
def _get_shell_env(scripts: List) -> Dict[str, Any]:
Expand Down

0 comments on commit 5382a0e

Please sign in to comment.