ScriptCollection 4.2.112__py3-none-any.whl → 4.2.114__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ class ProgramRunnerBase:
8
8
  # Return-values program_runner: Pid
9
9
  @abstractmethod
10
10
  @GeneralUtilities.check_arguments
11
- def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> Popen:
11
+ def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> Popen:
12
12
  raise NotImplementedError
13
13
 
14
14
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
@@ -20,25 +20,25 @@ class ProgramRunnerBase:
20
20
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
21
21
  @abstractmethod
22
22
  @GeneralUtilities.check_arguments
23
- def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
23
+ def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
24
24
  raise NotImplementedError
25
25
 
26
26
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
27
27
  @abstractmethod
28
28
  @GeneralUtilities.check_arguments
29
- def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
29
+ def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
30
30
  raise NotImplementedError
31
31
 
32
32
  # Return-values program_runner: Pid
33
33
  @abstractmethod
34
34
  @GeneralUtilities.check_arguments
35
- def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> int:
35
+ def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> int:
36
36
  raise NotImplementedError
37
37
 
38
38
  # Return-values program_runner: Pid
39
39
  @abstractmethod
40
40
  @GeneralUtilities.check_arguments
41
- def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive: bool = False) -> int:
41
+ def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive: bool = False, env_vars: dict = None) -> int:
42
42
  raise NotImplementedError
43
43
 
44
44
  @abstractmethod
@@ -1,3 +1,4 @@
1
+ import os
1
2
  import sys
2
3
  from subprocess import PIPE, Popen
3
4
  from .GeneralUtilities import GeneralUtilities
@@ -7,17 +8,18 @@ from .ProgramRunnerBase import ProgramRunnerBase
7
8
  class ProgramRunnerPopen(ProgramRunnerBase):
8
9
 
9
10
  @GeneralUtilities.check_arguments
10
- def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> Popen:
11
+ def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> Popen:
11
12
  arguments_for_process = [program]
12
13
  arguments_for_process.extend(arguments_as_array)
13
14
  # "shell=True" is not allowed because it is not recommended and also something like
14
15
  # "ScriptCollectionCore().run_program('curl', 'https://example.com/dataset?id=1&format=json')"
15
16
  # would not be possible anymore because the ampersand will be treated as shell-command.
17
+ env = {**os.environ, **env_vars} if env_vars is not None else None
16
18
  try:
17
19
  if interactive:
18
- result = Popen(arguments_for_process, cwd=working_directory, stdout=PIPE, stderr=PIPE, shell=False, text=True, stdin=sys.stdin) # pylint: disable=consider-using-with
20
+ result = Popen(arguments_for_process, cwd=working_directory, stdout=PIPE, stderr=PIPE, shell=False, text=True, stdin=sys.stdin, env=env) # pylint: disable=consider-using-with
19
21
  else:
20
- result = Popen(arguments_for_process, cwd=working_directory, stdout=PIPE, stderr=PIPE, shell=False, text=True) # pylint: disable=consider-using-with
22
+ result = Popen(arguments_for_process, cwd=working_directory, stdout=PIPE, stderr=PIPE, shell=False, text=True, env=env) # pylint: disable=consider-using-with
21
23
  except FileNotFoundError as fileNotFoundError:
22
24
  raise FileNotFoundError(f"Starting '{program}' in '{working_directory}' resulted in a FileNotFoundError: '{str(fileNotFoundError)}'")
23
25
  except NotADirectoryError as notADirectoryError:
@@ -36,21 +38,21 @@ class ProgramRunnerPopen(ProgramRunnerBase):
36
38
  return result
37
39
 
38
40
  @GeneralUtilities.check_arguments
39
- def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
40
- process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive)
41
+ def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
42
+ process: Popen = self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars)
41
43
  return self.wait(process, custom_argument)
42
44
 
43
45
  @GeneralUtilities.check_arguments
44
- def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
45
- return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument)
46
+ def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
47
+ return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument, interactive, env_vars)
46
48
 
47
49
  @GeneralUtilities.check_arguments
48
- def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> int:
49
- return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive).pid
50
+ def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> int:
51
+ return self.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars).pid
50
52
 
51
53
  @GeneralUtilities.check_arguments
52
- def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> int:
53
- return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument, interactive)
54
+ def run_program_async(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> int:
55
+ return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, custom_argument, interactive, env_vars)
54
56
 
55
57
  @GeneralUtilities.check_arguments
56
58
  def will_be_executed_locally(self) -> bool:
@@ -64,17 +64,19 @@ class ProgramRunnerSudo(ProgramRunnerBase):
64
64
  return True
65
65
 
66
66
  @GeneralUtilities.check_arguments
67
- def run_program_internal(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None) -> tuple[int, str, str, int]:
67
+ def run_program_internal(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, env_vars: dict = None) -> tuple[int, str, str, int]:
68
+ if env_vars is not None:
69
+ raise ValueError("env_vars is not supported in Sudo-runner")
68
70
  argument = program+" " + ' '.join(GeneralUtilities.args_array_surround_with_quotes_if_required(arguments_as_array))
69
71
  argument = f"echo {self.__password} | sudo -k -S {argument}" # TODO maybe add "exit" somewhere before argument or before sudo to correctly return the exit-code"
70
72
  result = self.__sc.run_program_argsasarray("sh", ["-c", argument], working_directory)
71
73
  return result
72
74
 
73
75
  @GeneralUtilities.check_arguments
74
- def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> Popen:
76
+ def run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> Popen:
75
77
  if interactive:
76
78
  raise ValueError("Interactive execution is not supported in Sudo-runner")
77
- r: tuple[int, str, str, int] = self.run_program_internal(program, arguments_as_array, working_directory, custom_argument)
79
+ r: tuple[int, str, str, int] = self.run_program_internal(program, arguments_as_array, working_directory, custom_argument, env_vars)
78
80
  popen: SudoPopen = SudoPopen(r[0], r[1], r[2], r[3])
79
81
  return popen
80
82
 
@@ -85,24 +87,24 @@ class ProgramRunnerSudo(ProgramRunnerBase):
85
87
 
86
88
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
87
89
  @GeneralUtilities.check_arguments
88
- def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
90
+ def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
89
91
  if interactive:
90
92
  raise ValueError("Interactive execution is not supported in Sudo-runner")
91
- return self.run_program_internal(program, arguments_as_array, working_directory, custom_argument)
93
+ return self.run_program_internal(program, arguments_as_array, working_directory, custom_argument, env_vars)
92
94
 
93
95
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
94
96
  @GeneralUtilities.check_arguments
95
- def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> tuple[int, str, str, int]:
97
+ def run_program(self, program: str, arguments: str = "", working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
96
98
  if interactive:
97
99
  raise ValueError("Interactive execution is not supported in Sudo-runner")
98
- return self.run_program_internal(program, arguments.split(" "), working_directory, custom_argument)
100
+ return self.run_program_internal(program, arguments.split(" "), working_directory, custom_argument, env_vars)
99
101
 
100
102
  # Return-values program_runner: Pid
101
103
  @GeneralUtilities.check_arguments
102
- def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False) -> int:
104
+ def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> int:
103
105
  raise ValueError("Async execution is not supported in Sudo-runner")
104
106
 
105
107
  # Return-values program_runner: Pid
106
108
  @GeneralUtilities.check_arguments
107
- def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive: bool = False) -> int:
109
+ def run_program_async(self, program: str, arguments: str, working_directory: str, custom_argument: object, interactive: bool = False, env_vars: dict = None) -> int:
108
110
  raise ValueError("Async execution is not supported in Sudo-runner")
@@ -38,7 +38,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
38
38
  from .ProgramRunnerPopen import ProgramRunnerPopen
39
39
  from .SCLog import SCLog, LogLevel
40
40
 
41
- version = "4.2.112"
41
+ version = "4.2.114"
42
42
  __version__ = version
43
43
 
44
44
  class VSCodeWorkspaceShellTask:
@@ -1814,8 +1814,8 @@ class ScriptCollectionCore:
1814
1814
  # <run programs>
1815
1815
 
1816
1816
  @GeneralUtilities.check_arguments
1817
- def __run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, custom_argument: object = None, interactive: bool = False) -> Popen:
1818
- popen: Popen = self.program_runner.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive)
1817
+ def __run_program_argsasarray_async_helper(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> Popen:
1818
+ popen: Popen = self.program_runner.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars)
1819
1819
  return popen
1820
1820
 
1821
1821
  @staticmethod
@@ -1898,9 +1898,9 @@ class ScriptCollectionCore:
1898
1898
  return (stdout_result, stderr_result)
1899
1899
 
1900
1900
  @GeneralUtilities.check_arguments
1901
- def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False) -> tuple[int, str, str, int]:
1901
+ def run_program_argsasarray(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
1902
1902
  if self.call_program_runner_directly:
1903
- return self.program_runner.run_program_argsasarray(program, arguments_as_array, working_directory, custom_argument, interactive)
1903
+ return self.program_runner.run_program_argsasarray(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars)
1904
1904
  try:
1905
1905
  GeneralUtilities.assert_not_null(arguments_as_array,"arguments_as_array must not be null")
1906
1906
  arguments_as_str = ' '.join(arguments_as_array)
@@ -1931,7 +1931,7 @@ class ScriptCollectionCore:
1931
1931
  stderr: str = GeneralUtilities.empty_string
1932
1932
  pid: int = None
1933
1933
 
1934
- with self.__run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, arguments_for_log, custom_argument, interactive) as process:
1934
+ with self.__run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, arguments_for_log, custom_argument, interactive, env_vars) as process:
1935
1935
 
1936
1936
  if log_file is not None:
1937
1937
  GeneralUtilities.ensure_file_exists(log_file)
@@ -1993,39 +1993,39 @@ class ScriptCollectionCore:
1993
1993
 
1994
1994
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
1995
1995
  @GeneralUtilities.check_arguments
1996
- def run_program_with_retry(self, program: str, arguments: str = "", working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: str = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False, amount_of_attempts: int = 5, delay_in_seconds: int = 2) -> tuple[int, str, str, int]:
1997
- return GeneralUtilities.retry_action(lambda: self.run_program(program, arguments, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace,arguments_for_log, throw_exception_if_exitcode_is_not_zero, custom_argument, interactive, print_live_output), amount_of_attempts, delay_in_seconds=delay_in_seconds)
1996
+ def run_program_with_retry(self, program: str, arguments: str = "", working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: str = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False, amount_of_attempts: int = 5, delay_in_seconds: int = 2, env_vars: dict = None) -> tuple[int, str, str, int]:
1997
+ return GeneralUtilities.retry_action(lambda: self.run_program(program, arguments, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace,arguments_for_log, throw_exception_if_exitcode_is_not_zero, custom_argument, interactive, print_live_output, env_vars), amount_of_attempts, delay_in_seconds=delay_in_seconds)
1998
1998
 
1999
1999
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
2000
2000
  @GeneralUtilities.check_arguments
2001
- def run_program(self, program: str, arguments: str = "", working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: str = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False) -> tuple[int, str, str, int]:
2001
+ def run_program(self, program: str, arguments: str = "", working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: str = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False, env_vars: dict = None) -> tuple[int, str, str, int]:
2002
2002
  if self.call_program_runner_directly:
2003
- return self.program_runner.run_program(program, arguments, working_directory, custom_argument, interactive)
2004
- return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, GeneralUtilities.arguments_to_array(arguments_for_log), throw_exception_if_exitcode_is_not_zero, custom_argument, interactive, print_live_output)
2003
+ return self.program_runner.run_program(program, arguments, working_directory, custom_argument, interactive, env_vars)
2004
+ return self.run_program_argsasarray(program, GeneralUtilities.arguments_to_array(arguments), working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, GeneralUtilities.arguments_to_array(arguments_for_log), throw_exception_if_exitcode_is_not_zero, custom_argument, interactive, print_live_output, env_vars)
2005
2005
 
2006
2006
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
2007
2007
  @GeneralUtilities.check_arguments
2008
- def run_program_argsasarray_with_retry(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False, amount_of_attempts: int = 5, delay_in_seconds: int = 2) -> tuple[int, str, str, int]:
2009
- return GeneralUtilities.retry_action(lambda: self.run_program_argsasarray(program, arguments_as_array, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace,arguments_for_log, throw_exception_if_exitcode_is_not_zero, custom_argument, interactive, print_live_output), amount_of_attempts, delay_in_seconds=delay_in_seconds)
2008
+ def run_program_argsasarray_with_retry(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False, print_live_output: bool = False, amount_of_attempts: int = 5, delay_in_seconds: int = 2, env_vars: dict = None) -> tuple[int, str, str, int]:
2009
+ return GeneralUtilities.retry_action(lambda: self.run_program_argsasarray(program, arguments_as_array, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace,arguments_for_log, throw_exception_if_exitcode_is_not_zero, custom_argument, interactive, print_live_output, env_vars), amount_of_attempts, delay_in_seconds=delay_in_seconds)
2010
2010
 
2011
2011
 
2012
2012
  # Return-values program_runner: Pid
2013
2013
  @GeneralUtilities.check_arguments
2014
- def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, custom_argument: object = None, interactive: bool = False) -> int:
2014
+ def run_program_argsasarray_async(self, program: str, arguments_as_array: list[str] = [], working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> int:
2015
2015
  if self.call_program_runner_directly:
2016
- return self.program_runner.run_program_argsasarray_async(program, arguments_as_array, working_directory, custom_argument, interactive)
2016
+ return self.program_runner.run_program_argsasarray_async(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars)
2017
2017
  mock_loader_result = self.__try_load_mock(program, ' '.join(arguments_as_array), working_directory)
2018
2018
  if mock_loader_result[0]:
2019
2019
  return mock_loader_result[1]
2020
- process: Popen = self.__run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, arguments_for_log, custom_argument, interactive)
2020
+ process: Popen = self.__run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, arguments_for_log, custom_argument, interactive, env_vars)
2021
2021
  return process.pid
2022
2022
 
2023
2023
  # Return-values program_runner: Pid
2024
2024
  @GeneralUtilities.check_arguments
2025
- def run_program_async(self, program: str, arguments: str = "", working_directory: str = None,print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, custom_argument: object = None, interactive: bool = False) -> int:
2025
+ def run_program_async(self, program: str, arguments: str = "", working_directory: str = None,print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = 600, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: list[str] = None, custom_argument: object = None, interactive: bool = False, env_vars: dict = None) -> int:
2026
2026
  if self.call_program_runner_directly:
2027
- return self.program_runner.run_program_argsasarray_async(program, arguments, working_directory, custom_argument, interactive)
2028
- return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, arguments_for_log, custom_argument, interactive)
2027
+ return self.program_runner.run_program_argsasarray_async(program, arguments, working_directory, custom_argument, interactive, env_vars)
2028
+ return self.run_program_argsasarray_async(program, GeneralUtilities.arguments_to_array(arguments), working_directory, print_errors_as_information, log_file, timeoutInSeconds, addLogOverhead, title, log_namespace, arguments_for_log, custom_argument, interactive, env_vars)
2029
2029
 
2030
2030
  @GeneralUtilities.check_arguments
2031
2031
  def __try_load_mock(self, program: str, arguments: str, working_directory: str) -> tuple[bool, tuple[int, str, str, int]]:
@@ -2996,11 +2996,80 @@ OCR-content:
2996
2996
  self.kill_docker_container(service)
2997
2997
  example_name = os.path.basename(example_folder)
2998
2998
  title = f"Test{example_name}"
2999
- argument=f"compose -p {title.lower()}"
2999
+ in_build_container = self.is_running_in_build_container()
3000
+ generated_ports_override_file = GeneralUtilities.empty_string
3001
+ argument = "compose"
3002
+ if not in_build_container:
3003
+ # Locally the test-process runs directly on the host (not inside the docker-network), so the container-ports (declared as "expose" in the
3004
+ # compose-file) have to be published to the host. To avoid a committed override-file this publish-mapping is generated on the fly into a
3005
+ # temporary file. In the build-container nothing is published at all (see below) to avoid host-port-conflicts.
3006
+ generated_ports_override_file = self.__generate_localhost_ports_override_file(docker_compose_file)
3007
+ if generated_ports_override_file != GeneralUtilities.empty_string:
3008
+ argument = argument+f" -f docker-compose.yml -f {generated_ports_override_file}"
3009
+ argument = argument+f" -p {title.lower()}"
3000
3010
  if os.path.isfile(os.path.join(example_folder,"Parameters.env")):
3001
3011
  argument=argument+" --env-file Parameters.env"
3002
3012
  argument=argument+" up --detach"
3003
- self.run_program("docker", argument, example_folder, title=title,print_live_output=True)
3013
+ try:
3014
+ self.run_program("docker", argument, example_folder, title=title,print_live_output=True)
3015
+ finally:
3016
+ if generated_ports_override_file != GeneralUtilities.empty_string:
3017
+ GeneralUtilities.ensure_file_does_not_exist(generated_ports_override_file)
3018
+ if in_build_container:
3019
+ # Inside the build-container the docker-daemon runs in the same (ephemeral) container, so the test-process can reach the test-service-
3020
+ # containers via their container-IP but there is no docker-DNS available for it. To still be able to use the container-name in the
3021
+ # connection-strings (and to avoid publishing any port to the host, which would let concurrent pipelines conflict on the same host-port),
3022
+ # the container-names are mapped to their current container-IPs in the /etc/hosts of this build-container.
3023
+ self.__register_test_service_containers_in_etc_hosts(docker_compose_file)
3024
+
3025
+ @GeneralUtilities.check_arguments
3026
+ def __generate_localhost_ports_override_file(self, docker_compose_file: str) -> str:
3027
+ with open(docker_compose_file, encoding="utf-8") as stream:
3028
+ loaded = yaml.safe_load(stream)
3029
+ services = loaded.get("services", dict())
3030
+ override_services = dict()
3031
+ for service_name, service_definition in services.items():
3032
+ exposed_ports = service_definition.get("expose", list())
3033
+ if 0 < len(exposed_ports):
3034
+ # Each exposed container-port is published to the same port on the host (e.g. "5432" -> "5432:5432").
3035
+ override_services[service_name] = {"ports": [f"{exposed_port}:{exposed_port}" for exposed_port in exposed_ports]}
3036
+ if 0 == len(override_services):
3037
+ return GeneralUtilities.empty_string
3038
+ override_file = os.path.join(tempfile.gettempdir(), f"docker-compose.localhost.{str(uuid.uuid4())}.yml")
3039
+ with open(override_file, "w", encoding="utf-8") as stream:
3040
+ yaml.safe_dump({"services": override_services}, stream)
3041
+ return override_file
3042
+
3043
+ @GeneralUtilities.check_arguments
3044
+ def __register_test_service_containers_in_etc_hosts(self, docker_compose_file: str) -> None:
3045
+ # Maps the container-names of the test-services to their current container-IPs in the /etc/hosts of THIS build-container (neither the runner-host
3046
+ # nor the test-service-containers are touched). The managed block is rewritten on each start because the containers get a new IP every time.
3047
+ hosts_file = "/etc/hosts"
3048
+ if not os.path.isfile(hosts_file):
3049
+ return
3050
+ with open(docker_compose_file, encoding="utf-8") as stream:
3051
+ loaded = yaml.safe_load(stream)
3052
+ services = loaded.get("services", dict())
3053
+ entries: list[str] = []
3054
+ for service_name, service_definition in services.items():
3055
+ container_name = service_definition.get("container_name", service_name)
3056
+ inspect_result = self.run_program_argsasarray("docker", ["inspect", "-f", "{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}", container_name], throw_exception_if_exitcode_is_not_zero=False)
3057
+ if inspect_result[0] != 0:
3058
+ continue
3059
+ ip_addresses = [ip_address for ip_address in inspect_result[1].split() if GeneralUtilities.string_has_content(ip_address)]
3060
+ if 0 < len(ip_addresses):
3061
+ entries.append(f"{ip_addresses[0]}\t{container_name}")
3062
+ start_marker = "# >>> scriptcollection-test-service-hosts (managed automatically; do not edit)"
3063
+ end_marker = "# <<< scriptcollection-test-service-hosts"
3064
+ with open(hosts_file, "r", encoding="utf-8") as stream:
3065
+ content = stream.read()
3066
+ # Remove a previously written block first so stale IPs of already-recreated containers do not shadow the current ones.
3067
+ content = re.sub(re.escape(start_marker)+".*?"+re.escape(end_marker)+r"\n?", GeneralUtilities.empty_string, content, flags=re.DOTALL)
3068
+ content = content.rstrip("\n")+"\n"
3069
+ if 0 < len(entries):
3070
+ content = content+start_marker+"\n"+"\n".join(entries)+"\n"+end_marker+"\n"
3071
+ with open(hosts_file, "w", encoding="utf-8") as stream:
3072
+ stream.write(content)
3004
3073
 
3005
3074
  @GeneralUtilities.check_arguments
3006
3075
  def stop_local_test_service(self, file: str):
@@ -280,7 +280,7 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
280
280
  temp_output_folder = os.path.join(tempfile.gettempdir(), str(uuid.uuid4()))
281
281
  GeneralUtilities.ensure_directory_exists(temp_output_folder)
282
282
  try:
283
- run_result = self._protected_sc.run_program("dotnet", f"build \"{sln_file}\" -nologo -v minimal -o \"{temp_output_folder}\"", codeunit_folder, throw_exception_if_exitcode_is_not_zero=False)
283
+ run_result = self._protected_sc.run_program("dotnet", f"build \"{sln_file}\" -nologo -v minimal -o \"{temp_output_folder}\"", codeunit_folder, throw_exception_if_exitcode_is_not_zero=False, env_vars={"DOTNET_CLI_UI_LANGUAGE": "en-US"})
284
284
  finally:
285
285
  GeneralUtilities.ensure_directory_does_not_exist(temp_output_folder)
286
286
  diagnostics: list[tuple[LogLevel, str, str | None, int | None]] = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.2.112
3
+ Version: 4.2.114
4
4
  Summary: The ScriptCollection is the place for reusable scripts.
5
5
  Author-email: Marius Göcke <marius.goecke@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/anionDev/ScriptCollection
@@ -10,12 +10,12 @@ ScriptCollection/Executables.py,sha256=3-i1P60XxxoSl1meTdh-9cu9P6QuxOqa6rD7XoEI-
10
10
  ScriptCollection/GeneralUtilities.py,sha256=4BmzJhTPAZmKQd5YlMuX0E5Dl6fhuVkmVaCpST0WzRk,67654
11
11
  ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
12
12
  ScriptCollection/ProcessesRunner.py,sha256=o5raxIt3lknNPoPrjNzJ2bprRPJ3SnL0rrR7crraD7E,1523
13
- ScriptCollection/ProgramRunnerBase.py,sha256=4A2eQgSg_rRgQcgSi-LYtUlM-uSQEpS7qFWn0tWt4uo,2171
13
+ ScriptCollection/ProgramRunnerBase.py,sha256=eZenpiIFW1dhvSVCG7cfBs5hO4_KLlOxR7oXoSxUDmk,2286
14
14
  ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrRjAPIwT5Y,37
15
- ScriptCollection/ProgramRunnerPopen.py,sha256=BPY7-ZMIlqT7JOKz8qlB5c0laF2Js-ijzqk09GxZC48,3821
16
- ScriptCollection/ProgramRunnerSudo.py,sha256=_khC3xuTdrPoLluBJZWfldltmmuKltABJPcbjZSFW-4,4835
15
+ ScriptCollection/ProgramRunnerPopen.py,sha256=8tP0xWKeRYoGlaNB3iUh4o61O-tKtcxrS7IUqtU85C4,4091
16
+ ScriptCollection/ProgramRunnerSudo.py,sha256=4lxbUFMIWMbthM5Q_QaFjvZfAsNpKlXeqfEbiofg_DI,5109
17
17
  ScriptCollection/SCLog.py,sha256=8TRy1LeYMsPOIuWUcnUNNbO5pd-cNBS-3cn-kdzP8FU,4768
18
- ScriptCollection/ScriptCollectionCore.py,sha256=2vnqwPZhXGbIALmKv4PIyPmp2LtmyYwX4gjhfljZ6iU,188782
18
+ ScriptCollection/ScriptCollectionCore.py,sha256=vDB6Ffo6phDV--4DGqftzqR7U5DiczY3YaHJOiPrG_o,194154
19
19
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=o129UYDtLymCRjMZBP9Puaj19ueMHoNt6UTLspfnaRc,1758
21
21
  ScriptCollection/OCIImages/OCIImageManager.py,sha256=2muW4hJ_a7EfavY3WVnafqZ0HC87RcZsoTuNvA3c0To,11175
@@ -45,7 +45,7 @@ ScriptCollection/TFCPS/Docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
45
45
  ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py,sha256=bT6Gd5pQpZCw4OQz6HWkPCSn5z__eUUEisABLDSxd0o,200
46
46
  ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py,sha256=QyjOfMY22JWCvKjMelHiDWbJiWqotOfebpJpgDUaoO4,237
47
47
  ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationNoGenerate.py,sha256=i0zEGehj0sttxjjZtoq2KFSKp_ulxVyWp_ZgAhIY_So,241
48
- ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py,sha256=np81FkrwBSIfQmSnFhMmDqY6QgJL6BsYK7GKB9v-F8w,40718
48
+ ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py,sha256=et3d2_w-00uJuRlmmqWa7VDlAOnJEt_vE2FEtGfQez4,40764
49
49
  ScriptCollection/TFCPS/DotNet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
50
  ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py,sha256=KAjyFyEjpkghsVPskfsHD68k4Z92gRCT_q6BXfikRwE,7660
51
51
  ScriptCollection/TFCPS/Flutter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -291,8 +291,8 @@ build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Python/TFCPS_Code
291
291
  build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
292
292
  build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=WhOsMpJxNGqnQGA3nJ99ruyqymxBeJxCcpK98zJduTo,1680
293
293
  build/lib/build/lib/build/lib/build/lib/ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
294
- scriptcollection-4.2.112.dist-info/METADATA,sha256=RXbRh94Hefh_gtYutiBd4V4YDPPnYVBGOHUr7sLEauo,7697
295
- scriptcollection-4.2.112.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
- scriptcollection-4.2.112.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
- scriptcollection-4.2.112.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
- scriptcollection-4.2.112.dist-info/RECORD,,
294
+ scriptcollection-4.2.114.dist-info/METADATA,sha256=AezFFqUlfDVB6_SUko5K8JHmSdghDSZjKddU1fnm0gU,7697
295
+ scriptcollection-4.2.114.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
+ scriptcollection-4.2.114.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
+ scriptcollection-4.2.114.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
+ scriptcollection-4.2.114.dist-info/RECORD,,