ScriptCollection 4.2.112__py3-none-any.whl → 4.2.113__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")
@@ -5,6 +5,7 @@ import binascii
5
5
  import filecmp
6
6
  import hashlib
7
7
  import multiprocessing
8
+ import socket
8
9
  import time
9
10
  from io import BytesIO
10
11
  import itertools
@@ -38,7 +39,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
38
39
  from .ProgramRunnerPopen import ProgramRunnerPopen
39
40
  from .SCLog import SCLog, LogLevel
40
41
 
41
- version = "4.2.112"
42
+ version = "4.2.113"
42
43
  __version__ = version
43
44
 
44
45
  class VSCodeWorkspaceShellTask:
@@ -1814,8 +1815,8 @@ class ScriptCollectionCore:
1814
1815
  # <run programs>
1815
1816
 
1816
1817
  @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)
1818
+ 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:
1819
+ popen: Popen = self.program_runner.run_program_argsasarray_async_helper(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars)
1819
1820
  return popen
1820
1821
 
1821
1822
  @staticmethod
@@ -1898,9 +1899,9 @@ class ScriptCollectionCore:
1898
1899
  return (stdout_result, stderr_result)
1899
1900
 
1900
1901
  @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]:
1902
+ 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
1903
  if self.call_program_runner_directly:
1903
- return self.program_runner.run_program_argsasarray(program, arguments_as_array, working_directory, custom_argument, interactive)
1904
+ return self.program_runner.run_program_argsasarray(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars)
1904
1905
  try:
1905
1906
  GeneralUtilities.assert_not_null(arguments_as_array,"arguments_as_array must not be null")
1906
1907
  arguments_as_str = ' '.join(arguments_as_array)
@@ -1931,7 +1932,7 @@ class ScriptCollectionCore:
1931
1932
  stderr: str = GeneralUtilities.empty_string
1932
1933
  pid: int = None
1933
1934
 
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:
1935
+ 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
1936
 
1936
1937
  if log_file is not None:
1937
1938
  GeneralUtilities.ensure_file_exists(log_file)
@@ -1993,39 +1994,39 @@ class ScriptCollectionCore:
1993
1994
 
1994
1995
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
1995
1996
  @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)
1997
+ 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]:
1998
+ 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
1999
 
1999
2000
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
2000
2001
  @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]:
2002
+ 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
2003
  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)
2004
+ return self.program_runner.run_program(program, arguments, working_directory, custom_argument, interactive, env_vars)
2005
+ 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
2006
 
2006
2007
  # Return-values program_runner: Exitcode, StdOut, StdErr, Pid
2007
2008
  @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)
2009
+ 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]:
2010
+ 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
2011
 
2011
2012
 
2012
2013
  # Return-values program_runner: Pid
2013
2014
  @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:
2015
+ 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
2016
  if self.call_program_runner_directly:
2016
- return self.program_runner.run_program_argsasarray_async(program, arguments_as_array, working_directory, custom_argument, interactive)
2017
+ return self.program_runner.run_program_argsasarray_async(program, arguments_as_array, working_directory, custom_argument, interactive, env_vars)
2017
2018
  mock_loader_result = self.__try_load_mock(program, ' '.join(arguments_as_array), working_directory)
2018
2019
  if mock_loader_result[0]:
2019
2020
  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)
2021
+ 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
2022
  return process.pid
2022
2023
 
2023
2024
  # Return-values program_runner: Pid
2024
2025
  @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:
2026
+ 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
2027
  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)
2028
+ return self.program_runner.run_program_argsasarray_async(program, arguments, working_directory, custom_argument, interactive, env_vars)
2029
+ 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
2030
 
2030
2031
  @GeneralUtilities.check_arguments
2031
2032
  def __try_load_mock(self, program: str, arguments: str, working_directory: str) -> tuple[bool, tuple[int, str, str, int]]:
@@ -2996,11 +2997,69 @@ OCR-content:
2996
2997
  self.kill_docker_container(service)
2997
2998
  example_name = os.path.basename(example_folder)
2998
2999
  title = f"Test{example_name}"
2999
- argument=f"compose -p {title.lower()}"
3000
+ in_build_container = self.is_running_in_build_container()
3001
+ generated_ports_override_file = GeneralUtilities.empty_string
3002
+ argument = "compose"
3003
+ if not in_build_container:
3004
+ # Locally the test-process runs directly on the host (not inside the docker-network), so the container-ports (declared as "expose" in the
3005
+ # 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
3006
+ # temporary file. In the build-container nothing is published at all (see below) to avoid host-port-conflicts.
3007
+ generated_ports_override_file = self.__generate_localhost_ports_override_file(docker_compose_file)
3008
+ if generated_ports_override_file != GeneralUtilities.empty_string:
3009
+ argument = argument+f" -f docker-compose.yml -f {generated_ports_override_file}"
3010
+ argument = argument+f" -p {title.lower()}"
3000
3011
  if os.path.isfile(os.path.join(example_folder,"Parameters.env")):
3001
3012
  argument=argument+" --env-file Parameters.env"
3002
3013
  argument=argument+" up --detach"
3003
- self.run_program("docker", argument, example_folder, title=title,print_live_output=True)
3014
+ try:
3015
+ self.run_program("docker", argument, example_folder, title=title,print_live_output=True)
3016
+ finally:
3017
+ if generated_ports_override_file != GeneralUtilities.empty_string:
3018
+ GeneralUtilities.ensure_file_does_not_exist(generated_ports_override_file)
3019
+ if in_build_container:
3020
+ # Inside the build-container the test-process itself runs in a container. Instead of publishing the container-ports to the host it is
3021
+ # attached to the docker-network(s) of the test-services so it can reach them directly by their container-name. This way no ports have
3022
+ # to be opened on the host at all and concurrent pipelines can not conflict on the same host-port anymore.
3023
+ self.__connect_self_to_compose_networks(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 get_external_networks_from_yaml_file(self, yaml_file: str) -> list[str]:
3045
+ with open(yaml_file, encoding="utf-8") as stream:
3046
+ loaded = yaml.safe_load(stream)
3047
+ result: list[str] = []
3048
+ networks = loaded.get("networks", None)
3049
+ if networks is None:
3050
+ return result
3051
+ for network_key, network_definition in networks.items():
3052
+ if isinstance(network_definition, dict) and network_definition.get("external", False):
3053
+ # For external networks the actual docker-network-name is the explicit "name" if given, otherwise the key itself.
3054
+ result.append(network_definition.get("name", network_key))
3055
+ return result
3056
+
3057
+ @GeneralUtilities.check_arguments
3058
+ def __connect_self_to_compose_networks(self, docker_compose_file: str) -> None:
3059
+ own_container = socket.gethostname() # Inside a container the hostname equals the container-id, which "docker network connect" accepts.
3060
+ for network_name in self.get_external_networks_from_yaml_file(docker_compose_file):
3061
+ # Connecting an already-connected container returns a non-zero exitcode; this is ignored on purpose to keep this operation idempotent.
3062
+ self.run_program("docker", f"network connect {network_name} {own_container}", throw_exception_if_exitcode_is_not_zero=False)
3004
3063
 
3005
3064
  @GeneralUtilities.check_arguments
3006
3065
  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.113
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=_KX3pp5W8h25IqccC4LViEM6a_OglAqA7e4MeQ7Hj3w,193204
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.113.dist-info/METADATA,sha256=w4GginBlfMBrxZ6JL2KfvnHN7je22MQ0kvJwhKWGRZI,7697
295
+ scriptcollection-4.2.113.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
296
+ scriptcollection-4.2.113.dist-info/entry_points.txt,sha256=_vnVTrGJc_z-DTPLvaYyyOpDEQLz0bdO2OLN3_ZmeR8,4978
297
+ scriptcollection-4.2.113.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
298
+ scriptcollection-4.2.113.dist-info/RECORD,,