ScriptCollection 4.3.4__py3-none-any.whl → 4.3.6__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.
@@ -290,9 +290,9 @@ def BuildCodeUnitsC() -> int:
290
290
  GeneralUtilities.reconfigure_standard_input_and_outputs()
291
291
  repo:str=GeneralUtilities.resolve_relative_path(args.repositoryfolder,os.getcwd())
292
292
  verbosity=LogLevel(int(args.verbosity))
293
- t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,args.ispremerge,args.assertnonewchanges)
294
- t.build_codeunits_in_container()
295
- return 0
293
+ t:TFCPS_CodeUnit_BuildCodeUnits=TFCPS_CodeUnit_BuildCodeUnits(repo,verbosity,args.targetenvironment,args.additionalargumentsfile,not args.nocache,args.ispremerge,args.assertnonewchanges)
294
+ success, _ = t.build_codeunits_in_container()
295
+ return 0 if success else 1
296
296
 
297
297
  def UpdateDependencies() -> int:
298
298
  parser = argparse.ArgumentParser()
@@ -1184,6 +1184,22 @@ class GeneralUtilities:
1184
1184
  temp_folder = "/tmp"
1185
1185
  return temp_folder
1186
1186
 
1187
+ @staticmethod
1188
+ def _internal_with_absolute_temp_folder_environment_variables(environment: dict) -> dict:
1189
+ """Returns a copy of the given environment-dictionary in which the temp-folder-environment-variables (TMPDIR/TMP/TEMP)
1190
+ are replaced by the absolute system-temp-folder if they are set to a relative value. This is required because spawned
1191
+ child-processes resolve their temp-folder via these variables (e.g. .NET-tools like the coverlet-collector or CycloneDX
1192
+ via Path.GetTempPath()); a relative value (as set in some Linux-build-containers) would otherwise make them create
1193
+ temp-content relative to their current working-directory (e.g. a leftover 'tmp/<guid>'-folder inside a codeunit-folder)
1194
+ instead of in the system-temp-folder."""
1195
+ result = dict(environment)
1196
+ absolute_temp_folder = GeneralUtilities.get_temp_folder()
1197
+ for temp_environment_variable_name in ("TMPDIR", "TMP", "TEMP"):
1198
+ value = result.get(temp_environment_variable_name)
1199
+ if value is not None and not os.path.isabs(value):
1200
+ result[temp_environment_variable_name] = absolute_temp_folder
1201
+ return result
1202
+
1187
1203
  @staticmethod
1188
1204
  @check_arguments
1189
1205
  def get_line():
@@ -14,7 +14,12 @@ class ProgramRunnerPopen(ProgramRunnerBase):
14
14
  # "shell=True" is not allowed because it is not recommended and also something like
15
15
  # "ScriptCollectionCore().run_program('curl', 'https://example.com/dataset?id=1&format=json')"
16
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
17
+ # Always pass an explicit environment (instead of inheriting os.environ implicitly) so that relative
18
+ # temp-folder-environment-variables - which some Linux-build-containers set - are normalized to an absolute path.
19
+ # Otherwise spawned child-processes (e.g. .NET-tools resolving Path.GetTempPath()) would create temp-content
20
+ # relative to their working-directory (e.g. a leftover 'tmp/<guid>'-folder inside a codeunit-folder).
21
+ base_environment = GeneralUtilities._internal_with_absolute_temp_folder_environment_variables(os.environ)
22
+ env = {**base_environment, **env_vars} if env_vars is not None else base_environment
18
23
  try:
19
24
  if interactive:
20
25
  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
@@ -37,7 +37,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
37
37
  from .ProgramRunnerPopen import ProgramRunnerPopen
38
38
  from .SCLog import SCLog, LogLevel
39
39
 
40
- version = "4.3.4"
40
+ version = "4.3.6"
41
41
  __version__ = version
42
42
 
43
43
  class VSCodeWorkspaceShellTask:
@@ -569,9 +569,25 @@ class ScriptCollectionCore:
569
569
  def git_pull_with_retry(self, folder: str, remote: str, localbranchname: str, remotebranchname: str, force: bool = False, amount_of_attempts: int = 5) -> None:
570
570
  GeneralUtilities.retry_action(lambda: self.git_pull(folder, remote, localbranchname, remotebranchname), amount_of_attempts)
571
571
 
572
+ @GeneralUtilities.check_arguments
573
+ def git_branch_is_pullable(self, folder: str, remote: str, localbranchname: str, remotebranchname: str) -> bool:
574
+ """Fetches remote and returns whether pulling remotebranchname into localbranchname would advance (fast-forward) the local-branch.
575
+ Returns True if the local-branch is behind the remote-branch (or equal to it).
576
+ Returns False if the local-branch is ahead of the remote-branch (or diverged from it), in which case a pull would do nothing useful and a normal pull would even fail with a non-fast-forward-error."""
577
+ self.is_git_or_bare_git_repository(folder)
578
+ self.git_fetch(folder, remote)
579
+ return self.git_commit_is_ancestor(folder, localbranchname, f"{remote}/{remotebranchname}")
580
+
572
581
  @GeneralUtilities.check_arguments
573
582
  def git_pull(self, folder: str, remote: str, localbranchname: str, remotebranchname: str, force: bool = False) -> None:
574
583
  self.is_git_or_bare_git_repository(folder)
584
+ if not force and not self.is_bare_git_repository(folder):
585
+ # If the local-branch is already up-to-date with or ahead of the remote-branch there is nothing to pull and a normal
586
+ # pull would fail with a non-fast-forward-error. In that case do nothing. (Skipped for bare-repositories because
587
+ # those have no working-tree to update and git_fetch does not support them.)
588
+ if not self.git_branch_is_pullable(folder, remote, localbranchname, remotebranchname):
589
+ self.log.log(f"Skip pulling '{remotebranchname}' from '{remote}' into '{localbranchname}' in '{folder}' because the local-branch is not behind the remote-branch.", LogLevel.Debug)
590
+ return
575
591
  argument = f"pull {remote} {remotebranchname}:{localbranchname}"
576
592
  if force:
577
593
  argument = f"{argument} --force"
@@ -749,8 +765,7 @@ class ScriptCollectionCore:
749
765
  @GeneralUtilities.check_arguments
750
766
  def merge_repository(self, repository_folder: str, remote: str, branch: str):
751
767
  GeneralUtilities.assert_condition(not self.git_repository_has_uncommitted_changes(repository_folder),f"Can not merge. There are uncommitted changes in \"{repository_folder}\".")
752
- self.git_fetch(repository_folder, remote)
753
- is_pullable: bool = self.git_commit_is_ancestor(repository_folder, branch, f"{remote}/{branch}")
768
+ is_pullable: bool = self.git_branch_is_pullable(repository_folder, remote, branch, branch)
754
769
  if is_pullable:
755
770
  self.git_pull(repository_folder, remote, branch, branch)
756
771
  uncommitted_changes = self.git_repository_has_uncommitted_changes(repository_folder)
@@ -101,6 +101,7 @@ class TFCPS_CodeUnit_BuildCodeUnit:
101
101
  artifacts_list.append(f" <cps:artifact>{artifact_name}<cps:artifact>")
102
102
  artifacts = '\n'.join(artifacts_list)
103
103
  moment = GeneralUtilities.datetime_to_string(GeneralUtilities.get_now())
104
+ commit_id = self.sc.git_get_commit_id(self.repository_folder) # the actual commit-id (not the branch-name) which was checked-out while building this codeunit
104
105
  # TODO implement usage of reference_latest_version_of_xsd_when_generating_xml
105
106
  GeneralUtilities.write_text_to_file(artifactsinformation_file, f"""<?xml version="1.0" encoding="UTF-8" ?>
106
107
  <cps:artifactsinformation xmlns:cps="https://projects.aniondev.de/PublicProjects/Common/ProjectTemplates/-/tree/main/Conventions/RepositoryStructure/CommonProjectStructure" artifactsinformationspecificationversion="1.0.0"
@@ -109,6 +110,7 @@ class TFCPS_CodeUnit_BuildCodeUnit:
109
110
  <cps:version>{codeunit_version}</cps:version>
110
111
  <cps:timestamp>{moment}</cps:timestamp>
111
112
  <cps:targetenvironmenttype>{self.target_environment_type}</cps:targetenvironmenttype>
113
+ <cps:commitid>{commit_id}</cps:commitid>
112
114
  <cps:artifacts>
113
115
  {artifacts}
114
116
  </cps:artifacts>
@@ -121,20 +121,20 @@ class TFCPS_CodeUnit_BuildCodeUnits:
121
121
  self.sc.run_program_argsasarray(GeneralUtilities.get_python_executable(),["PrepareBuildCodeunits.py"]+args, os.path.join(self.repository,"Other","Scripts"),print_live_output=True)
122
122
 
123
123
  @GeneralUtilities.check_arguments
124
- def build_codeunits_in_container(self) -> None:
124
+ def build_codeunits_in_container(self) -> tuple[bool, str]:
125
125
  container_repository_folder = "/Workspace/Repository"
126
126
  image = self.tfcps_tools_general.oci_image_manager.get_registry_address_for_image_with_default_tag(self.repository, "SCBuilder")
127
127
 
128
- #build the scbuildcodeunits-arguments based on the current state (analogous to the arguments accepted by the scbuildcodeunits-executable)
129
- scbuildcodeunits_arguments = "scbuildcodeunits -r /Workspace/Repository -v 4"
128
+ #build the scbuildcodeunits-arguments based on the current state (analogous to the arguments accepted by the scbuildcodeunits-executable). each token must be a separate argument because run_program_argsasarray passes every list-element verbatim and does not split on spaces.
129
+ scbuildcodeunits_arguments = ["scbuildcodeunits", "-r", container_repository_folder, "-v", "4"]
130
130
  if not self.__use_cache:
131
- scbuildcodeunits_arguments+="-c"
131
+ scbuildcodeunits_arguments.append("-c")
132
132
  if self.__is_pre_merge:
133
- scbuildcodeunits_arguments+="-p"
133
+ scbuildcodeunits_arguments.append("-p")
134
134
  if self.__assert_no_new_changes:
135
- scbuildcodeunits_arguments+="-u"
135
+ scbuildcodeunits_arguments.append("-u")
136
136
  if GeneralUtilities.string_has_content(self.additionalargumentsfile):
137
- scbuildcodeunits_arguments += f" -a {self.__translate_path_into_container(self.additionalargumentsfile, container_repository_folder)}"
137
+ scbuildcodeunits_arguments += ["-a", self.__translate_path_into_container(self.additionalargumentsfile, container_repository_folder)]
138
138
 
139
139
  #run scbuildcodeunits inside the SCBuilder-image. the repository is mounted into the container and the docker-socket is forwarded because codeunit-builds often start containers (for example local test-services).
140
140
  docker_arguments = [
@@ -143,10 +143,10 @@ class TFCPS_CodeUnit_BuildCodeUnits:
143
143
  "-v", "/var/run/docker.sock:/var/run/docker.sock",
144
144
  "-w", container_repository_folder,
145
145
  image,
146
- scbuildcodeunits_arguments,
147
- ]
146
+ ] + scbuildcodeunits_arguments
148
147
  self.sc.log.log(f"Build codeunits in container using image \"{image}\"...")
149
- result=self.sc.run_program_argsasarray("docker", docker_arguments, print_live_output=True)
148
+ # the exitcode is evaluated by the caller (returned as part of the result-tuple), so the program-runner must not raise on a non-zero exitcode here.
149
+ result=self.sc.run_program_argsasarray("docker", docker_arguments, throw_exception_if_exitcode_is_not_zero=False, print_live_output=True)
150
150
  exit_code:int=result[0]
151
151
  stdout:str=result[1] or GeneralUtilities.empty_string
152
152
  stderr:str=result[2] or GeneralUtilities.empty_string
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.3.4
3
+ Version: 4.3.6
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
@@ -1,15 +1,15 @@
1
1
  ScriptCollection/AnionBuildPlatform.py,sha256=T1tkh4pzQyUb8r5acWiv95TvmkNnDhiNaQAP2dJJvoA,12057
2
2
  ScriptCollection/CertificateUpdater.py,sha256=dR5JpJDlZdjD4_pgMz7zCrt1IM7VfatmK6pULSczxQw,9693
3
- ScriptCollection/Executables.py,sha256=Ha0DRqeqxhOM9V-MPd1rozSEWVSRHji6XwysWf7JS8k,66378
4
- ScriptCollection/GeneralUtilities.py,sha256=C7QwbcaFWbx2Mchj5yiREzr6m2WZT6Vb7dunZ8KnEvo,69290
3
+ ScriptCollection/Executables.py,sha256=lw8K8TaU406TryWv8-upAaTi7v3ATmlszsbBBMshvSY,66408
4
+ ScriptCollection/GeneralUtilities.py,sha256=Qox4wQ2oWTahwXexC4qSUzXua5qr9PzRRrmOcJoM_IA,70500
5
5
  ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
6
6
  ScriptCollection/ProcessesRunner.py,sha256=yYaC95h40uszuZPggn2kK3qXIN2ZjGMCavo-NQ53ElQ,1537
7
7
  ScriptCollection/ProgramRunnerBase.py,sha256=eZenpiIFW1dhvSVCG7cfBs5hO4_KLlOxR7oXoSxUDmk,2286
8
8
  ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrRjAPIwT5Y,37
9
- ScriptCollection/ProgramRunnerPopen.py,sha256=8tP0xWKeRYoGlaNB3iUh4o61O-tKtcxrS7IUqtU85C4,4091
9
+ ScriptCollection/ProgramRunnerPopen.py,sha256=zVD-gZY85o8wiGFcpYAGNDl-tXaKzipl1Bkhqy2ois4,4681
10
10
  ScriptCollection/ProgramRunnerSudo.py,sha256=RXsiceQ8W6a8YDk_2BPscVbIAmDIpIxqe9WHBy2r4CM,5233
11
11
  ScriptCollection/SCLog.py,sha256=Z-HhC_CRtU3HdQflNsabFh9IJOucHcXmxMDcf58fli0,4671
12
- ScriptCollection/ScriptCollectionCore.py,sha256=Coz09hz6yVGIlH8JMp6kglwiZgQom7OY0uW0Tw0Og5s,224945
12
+ ScriptCollection/ScriptCollectionCore.py,sha256=jRD6vkxVAc8pu7ITdIBqggtcR1b-TagIy0EwxMFFws8,226411
13
13
  ScriptCollection/UnassignedVariablesCheck.py,sha256=v59qLQ5RRvx31ouuCW7NWZj3McWENvGBPkV5ZGBmqJE,4344
14
14
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=o129UYDtLymCRjMZBP9Puaj19ueMHoNt6UTLspfnaRc,1758
@@ -34,8 +34,8 @@ ScriptCollection/Resources/Fonts/LICENSE.txt,sha256=egg7E25k0GR5TDQZdR5cfdENL2TB
34
34
  ScriptCollection/Resources/MaintenanceSite/MaintenanceSite.html,sha256=CX9S1bdOz6xU2aGfr03tJRGczQrlpn-IeODc15d5kc0,232
35
35
  ScriptCollection/TFCPS/SCTaskRunnerServer.py,sha256=rpuwSsQ6YQfZS2LGnvOH5ql8zs_-cHU4LQttS7XNT60,11272
36
36
  ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py,sha256=oICRtl85n2puWvchcJIkmLZL1BAylMbzH7ltBGWfqgY,31973
37
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=ulxU6CykkqyE6QWeX8PEyW0rntuK3qfBEbPSIplekfI,9677
38
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=bZ7kn9m0X8-tfjIxNCrCtUwi5I726P2Tks4a55C1VpE,23819
37
+ ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=s4E20EkvFZpsg2c2Gu-D6kHXS0QIkpx_chawHNSnlnU,9891
38
+ ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=T5xW98EslPov-DBwd3R0tO8PhrA-ZsQUaHh2vVOJSlg,24197
39
39
  ScriptCollection/TFCPS/TFCPS_CreateRelease.py,sha256=X2NgZgbOkJsdZ6wMHB_RuS_rQCuz5oQCqzYrxyXBN9Q,6680
40
40
  ScriptCollection/TFCPS/TFCPS_Generic.py,sha256=5vCFfDiU8bvfcnoKNs2ATS8nsl6mYXcIuX7XfYE0tvg,2116
41
41
  ScriptCollection/TFCPS/TFCPS_MergeToMain.py,sha256=BsSV4a-NZY86MZ20d-_rYxNVAI4UzAfmEwXlRZ8qWQc,7685
@@ -63,8 +63,8 @@ ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py,sha256=Bd1gxCk9Fb
63
63
  ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
64
64
  ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=WhOsMpJxNGqnQGA3nJ99ruyqymxBeJxCcpK98zJduTo,1680
65
65
  ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
66
- scriptcollection-4.3.4.dist-info/METADATA,sha256=8u8ll41KCSraN-cOMuR6_6x2XwaO6MzlEjbr6y4QmUg,7815
67
- scriptcollection-4.3.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
68
- scriptcollection-4.3.4.dist-info/entry_points.txt,sha256=MwiP9P29EeSfjS19JOZmqbx8OzpZrUWpgMza3EffBs8,5812
69
- scriptcollection-4.3.4.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
70
- scriptcollection-4.3.4.dist-info/RECORD,,
66
+ scriptcollection-4.3.6.dist-info/METADATA,sha256=nqkAaRGz71mJ4ppFhXrOWApe3Qi8wVh7xDBCJUKNVs0,7815
67
+ scriptcollection-4.3.6.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
68
+ scriptcollection-4.3.6.dist-info/entry_points.txt,sha256=MwiP9P29EeSfjS19JOZmqbx8OzpZrUWpgMza3EffBs8,5812
69
+ scriptcollection-4.3.6.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
70
+ scriptcollection-4.3.6.dist-info/RECORD,,