From 8b0f51137ef1a0688c810d68ebde7a73d9a06566 Mon Sep 17 00:00:00 2001 From: Joseph Coombe Date: Fri, 4 Oct 2019 00:54:41 -0500 Subject: [PATCH 1/2] Add --ignore-python-env-variables argument and logic --- testbenchexecutor/__init__.py | 6 ++++-- testbenchexecutor/__main__.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/testbenchexecutor/__init__.py b/testbenchexecutor/__init__.py index 3e5e609..f7df470 100644 --- a/testbenchexecutor/__init__.py +++ b/testbenchexecutor/__init__.py @@ -70,7 +70,7 @@ class TestBenchExecutor(object): _dict_manifest = dict() _steps = list() - def __init__(self, manifest_path, detailed=False): + def __init__(self, manifest_path, detailed=False, ignore_env_vars=True): """ @param manifest_path: The path to the test bench manifest @type manifest_path: str @@ -81,6 +81,7 @@ def __init__(self, manifest_path, detailed=False): self._path_manifest = manifest_path self._detailed = detailed + self._ignore_env_vars = ignore_env_vars self._load_tb_manifest() # TODO: command-line option to skip this with self._update_manifest() as manifest: @@ -261,7 +262,8 @@ def _execute_step(self, step): with open(os.devnull, "r") as null_file: invocation = step["Invocation"] if invocation.lower().startswith("python.exe "): - invocation = "\"" + sys.executable + "\" " + step["Invocation"][len("python.exe "):] + ignore_env_vars_opt = "\"-E\" " if self._ignore_env_vars else "" + invocation = "\"" + sys.executable + "\" " + ignore_env_vars_opt + step["Invocation"][len("python.exe "):] invocation = parse(invocation) if os.path.splitext(invocation[0])[1].lower() in ('.cmd', '.bat'): # special-case, since cmd.exe doesn't directly support UNC paths (e.g. shared folders). Scripts should also include "pushd %~dp0" diff --git a/testbenchexecutor/__main__.py b/testbenchexecutor/__main__.py index 2d5d594..cd8bacb 100644 --- a/testbenchexecutor/__main__.py +++ b/testbenchexecutor/__main__.py @@ -10,12 +10,15 @@ def main(): help='run only the first unexecuted step (default: run all unexecuted steps)') parser.add_argument('--detailed-errors', '-d', action='store_true', help='On step failure, output last few lines of log') + parser.add_argument('--ignore-python-env-variables', action='store_true', + help='Ignore Python* Environment Variables, e.g. PYTHONPATH and PYTHONHOME') parser.add_argument('manifest', type=str, nargs=1, help='the path of the manifest to be executed') args = parser.parse_args() - executor = TestBenchExecutor(args.manifest[0], detailed=args.detailed_errors) + executor = TestBenchExecutor(args.manifest[0], detailed=args.detailed_errors, + ignore_env_vars=args.ignore_python_env_variables) if args.run_one: sys.exit(executor.run_next_step()) From e592ebb35a09dd5438dad16a34f01250715e084d Mon Sep 17 00:00:00 2001 From: Joseph Coombe Date: Fri, 4 Oct 2019 01:06:18 -0500 Subject: [PATCH 2/2] Make default behavior to ignore Python Environment Variables --- testbenchexecutor/__init__.py | 6 +++--- testbenchexecutor/__main__.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/testbenchexecutor/__init__.py b/testbenchexecutor/__init__.py index f7df470..5ca7ef4 100644 --- a/testbenchexecutor/__init__.py +++ b/testbenchexecutor/__init__.py @@ -70,7 +70,7 @@ class TestBenchExecutor(object): _dict_manifest = dict() _steps = list() - def __init__(self, manifest_path, detailed=False, ignore_env_vars=True): + def __init__(self, manifest_path, detailed=False, read_env_vars=False): """ @param manifest_path: The path to the test bench manifest @type manifest_path: str @@ -81,7 +81,7 @@ def __init__(self, manifest_path, detailed=False, ignore_env_vars=True): self._path_manifest = manifest_path self._detailed = detailed - self._ignore_env_vars = ignore_env_vars + self._read_env_vars = read_env_vars self._load_tb_manifest() # TODO: command-line option to skip this with self._update_manifest() as manifest: @@ -262,7 +262,7 @@ def _execute_step(self, step): with open(os.devnull, "r") as null_file: invocation = step["Invocation"] if invocation.lower().startswith("python.exe "): - ignore_env_vars_opt = "\"-E\" " if self._ignore_env_vars else "" + ignore_env_vars_opt = "" if self._read_env_vars else "\"-E\" " invocation = "\"" + sys.executable + "\" " + ignore_env_vars_opt + step["Invocation"][len("python.exe "):] invocation = parse(invocation) if os.path.splitext(invocation[0])[1].lower() in ('.cmd', '.bat'): diff --git a/testbenchexecutor/__main__.py b/testbenchexecutor/__main__.py index cd8bacb..2d19a91 100644 --- a/testbenchexecutor/__main__.py +++ b/testbenchexecutor/__main__.py @@ -10,15 +10,15 @@ def main(): help='run only the first unexecuted step (default: run all unexecuted steps)') parser.add_argument('--detailed-errors', '-d', action='store_true', help='On step failure, output last few lines of log') - parser.add_argument('--ignore-python-env-variables', action='store_true', - help='Ignore Python* Environment Variables, e.g. PYTHONPATH and PYTHONHOME') + parser.add_argument('--read-python-env-variables', action='store_true', + help='Read Python* Environment Variables, e.g. PYTHONPATH and PYTHONHOME') parser.add_argument('manifest', type=str, nargs=1, help='the path of the manifest to be executed') args = parser.parse_args() executor = TestBenchExecutor(args.manifest[0], detailed=args.detailed_errors, - ignore_env_vars=args.ignore_python_env_variables) + read_env_vars=args.read_python_env_variables) if args.run_one: sys.exit(executor.run_next_step())