ScriptCollection 4.3.2__py3-none-any.whl → 4.3.4__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.
@@ -65,7 +65,7 @@ class AnionBuildPlatform:
65
65
  self.__sc.git_commit(build_repo_folder,"Updated changes")
66
66
  self.__sc.git_fetch(build_repo_folder)
67
67
  for remote in self.__sc.git_get_all_remote_names(build_repo_folder):
68
- self.__sc.git_merge(build_repo_folder,remote+"/"+self.__configuration.source_branch,self.__configuration.source_branch)
68
+ self.__sc.git_merge(build_repo_folder,remote+"/main","main")
69
69
 
70
70
  # Pull changes from remote
71
71
  self.__sc.git_fetch(repository)
@@ -813,9 +813,12 @@ class GeneralUtilities:
813
813
  @staticmethod
814
814
  @check_arguments
815
815
  def read_binary_from_file(file: str) -> bytes:
816
- file=GeneralUtilities.normalize_path(file)
817
- with open(file, "rb") as file_object:
818
- return file_object.read()
816
+ try:
817
+ file=GeneralUtilities.normalize_path(file)
818
+ with open(file, "rb") as file_object:
819
+ return file_object.read()
820
+ except Exception as e:
821
+ raise ValueError(f"Could not read file '{file}'.") from e
819
822
 
820
823
  @staticmethod
821
824
  @check_arguments
@@ -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.2"
40
+ version = "4.3.4"
41
41
  __version__ = version
42
42
 
43
43
  class VSCodeWorkspaceShellTask:
@@ -497,7 +497,8 @@ class ScriptCollectionCore:
497
497
  @GeneralUtilities.check_arguments
498
498
  def git_get_commit_id(self, repository_folder: str, rev: str = "HEAD") -> str:
499
499
  self.is_git_or_bare_git_repository(repository_folder)
500
- result: tuple[int, str, str, int] = self.run_program_argsasarray("git", ["rev-parse", "--verify", rev], repository_folder, throw_exception_if_exitcode_is_not_zero=True)
500
+ # Append "^{commit}" so that annotated tags are dereferenced to the commit they point to instead of returning the SHA of the tag-object itself.
501
+ result: tuple[int, str, str, int] = self.run_program_argsasarray("git", ["rev-parse", "--verify", f"{rev}^{{commit}}"], repository_folder, throw_exception_if_exitcode_is_not_zero=True)
501
502
  return result[1].replace('\n', '')
502
503
 
503
504
  @GeneralUtilities.check_arguments
@@ -644,7 +645,7 @@ class ScriptCollectionCore:
644
645
  def git_unstage_all_changes(self, directory: str) -> None:
645
646
  self.assert_is_git_repository(directory)
646
647
  self.run_program_argsasarray("git", ["reset"], directory, throw_exception_if_exitcode_is_not_zero=True)
647
- # TODO check if this will also be done for submodules
648
+ # TODO ensure this will also be done for submodules
648
649
 
649
650
  @GeneralUtilities.check_arguments
650
651
  def git_stage_file(self, directory: str, file: str) -> None:
@@ -668,7 +669,7 @@ class ScriptCollectionCore:
668
669
  self.assert_is_git_repository(directory)
669
670
  self.run_program_argsasarray("git", ['clean', '-df'], directory, throw_exception_if_exitcode_is_not_zero=True)
670
671
  self.run_program_argsasarray("git", ['checkout', '.'], directory, throw_exception_if_exitcode_is_not_zero=True)
671
- # TODO check if this will also be done for submodules
672
+ # TODO ensure this will also be done for submodules
672
673
 
673
674
  @GeneralUtilities.check_arguments
674
675
  def git_commit(self, directory: str, message: str = "Saved changes.", author_name: str = None, author_email: str = None, stage_all_changes: bool = True, no_changes_behavior: int = 0,commit_message_body:str=None) -> str:
@@ -2332,6 +2333,26 @@ class ScriptCollectionCore:
2332
2333
  result = "0.1.0"
2333
2334
  return result
2334
2335
 
2336
+ @GeneralUtilities.check_arguments
2337
+ def get_real_git_folder(self,repository_folder:str) -> str:
2338
+ git_folder = os.path.join(repository_folder, ".git")
2339
+ if os.path.isfile(git_folder):
2340
+ with open(git_folder, "r", encoding="utf-8") as f:
2341
+ line = f.readline().strip()
2342
+ prefix = "gitdir:"
2343
+ if not line.startswith(prefix):
2344
+ raise ValueError(f"Invalid .git file: '{git_folder}'")
2345
+ git_dir = line[len(prefix):].strip()
2346
+ if not os.path.isabs(git_dir):
2347
+ git_dir = os.path.normpath(os.path.join(repository_folder, git_dir))
2348
+ if not os.path.isdir(git_dir):
2349
+ raise ValueError(f"Resolved git directory '{git_dir}' does not exist.")
2350
+ return git_dir
2351
+ elif os.path.isdir(git_folder):
2352
+ return git_folder
2353
+ else:
2354
+ raise ValueError(f"Folder '{repository_folder}' is not a git-repository (no .git-folder found).")
2355
+
2335
2356
  @staticmethod
2336
2357
  @GeneralUtilities.check_arguments
2337
2358
  def is_patch_version(version_string: str) -> bool:
@@ -2339,6 +2360,9 @@ class ScriptCollectionCore:
2339
2360
 
2340
2361
  @GeneralUtilities.check_arguments
2341
2362
  def get_version_from_gitversion(self, folder: str, variable: str) -> str:
2363
+ git_folder:str=self.get_real_git_folder(folder)
2364
+ cache_folder:str=os.path.join(git_folder,"gitversion_cache")
2365
+ GeneralUtilities.ensure_directory_does_not_exist(cache_folder)
2342
2366
  # /nofetch and /nonormalize: avoid network calls / branch normalization (no auth, no DNS, deterministic in containers and offline).
2343
2367
  # called twice as workaround for issue 1877 in gitversion ( https://github.com/GitTools/GitVersion/issues/1877 )
2344
2368
  result = self.run_program_argsasarray("gitversion", ["/nofetch", "/nonormalize", "/showVariable", variable], folder)
@@ -1,6 +1,8 @@
1
1
  import os
2
2
  import re
3
+ import sys
3
4
  import json
5
+ import platform
4
6
  from pathlib import Path
5
7
  import xml.etree.ElementTree as ET
6
8
  from lxml import etree
@@ -49,10 +51,74 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
49
51
  def do_common_tasks(self,current_codeunit_version:str)-> None:
50
52
  codeunit_version = current_codeunit_version
51
53
  codeunit_folder = self.get_codeunit_folder()
54
+ self.__remove_foreign_platform_node_modules_packages(codeunit_folder)
52
55
  self.do_common_tasks_base(current_codeunit_version)
53
56
  self.tfcps_Tools_General.replace_version_in_packagejson_file(GeneralUtilities.resolve_relative_path("./package.json", codeunit_folder), codeunit_version)
54
57
  self.tfcps_Tools_General.do_npm_install(codeunit_folder, True,self.use_cache())
55
58
 
59
+ @GeneralUtilities.check_arguments
60
+ def __remove_foreign_platform_node_modules_packages(self, codeunit_folder: str) -> None:
61
+ # Native packages (esbuild, rollup, lightningcss, swc, ...) ship platform-specific binaries via
62
+ # optional dependencies whose package.json declares 'os'/'cpu'. When node_modules is shared between
63
+ # build-hosts (e.g. Windows-native vs. a mounted Linux-Docker-container) the binary for the foreign
64
+ # platform stays present and breaks the build. Remove every installed package whose declared 'os'/'cpu'
65
+ # does not match the current host so the subsequent npm-install fetches the matching one.
66
+ node_modules_folder = os.path.join(codeunit_folder, "node_modules")
67
+ if not os.path.isdir(node_modules_folder):
68
+ return
69
+ current_os = sys.platform # matches npm's 'os'-values ('win32', 'linux', 'darwin')
70
+ current_cpu = {
71
+ "amd64": "x64", "x86_64": "x64",
72
+ "aarch64": "arm64", "arm64": "arm64",
73
+ "i386": "ia32", "i686": "ia32", "x86": "ia32",
74
+ }.get(platform.machine().lower(), platform.machine().lower())
75
+ for package_folder in self.__get_node_modules_package_folders(node_modules_folder):
76
+ package_json_file = os.path.join(package_folder, "package.json")
77
+ if not os.path.isfile(package_json_file):
78
+ continue
79
+ try:
80
+ with open(package_json_file, encoding="utf-8") as f:
81
+ package_json = json.load(f)
82
+ except (ValueError, OSError):
83
+ continue
84
+ os_allowed = self.__node_platform_value_allowed(package_json.get("os"), current_os)
85
+ cpu_allowed = self.__node_platform_value_allowed(package_json.get("cpu"), current_cpu)
86
+ if not (os_allowed and cpu_allowed):
87
+ self._protected_sc.log.log(f"Remove foreign-platform node_modules-package '{os.path.basename(package_folder)}' (os={package_json.get('os')}, cpu={package_json.get('cpu')}; host={current_os}/{current_cpu}).", LogLevel.Debug)
88
+ GeneralUtilities.ensure_directory_does_not_exist(package_folder)
89
+
90
+ @GeneralUtilities.check_arguments
91
+ def __get_node_modules_package_folders(self, node_modules_folder: str) -> list[str]:
92
+ # Yields the package-folders inside node_modules. Packages live either directly in node_modules
93
+ # or, for scoped packages, one level below a '@scope'-folder.
94
+ result: list[str] = []
95
+ for entry in os.listdir(node_modules_folder):
96
+ entry_path = os.path.join(node_modules_folder, entry)
97
+ if not os.path.isdir(entry_path):
98
+ continue
99
+ if entry.startswith("@"):
100
+ for scoped_entry in os.listdir(entry_path):
101
+ scoped_path = os.path.join(entry_path, scoped_entry)
102
+ if os.path.isdir(scoped_path):
103
+ result.append(scoped_path)
104
+ else:
105
+ result.append(entry_path)
106
+ return result
107
+
108
+ @GeneralUtilities.check_arguments
109
+ def __node_platform_value_allowed(self, values, current: str) -> bool:
110
+ # Implements npm's 'os'/'cpu'-matching: a missing constraint allows everything; a negated entry
111
+ # ('!win32') blocks the value; if positive entries exist the current value must be one of them.
112
+ if not values:
113
+ return True
114
+ positives = [v for v in values if not v.startswith("!")]
115
+ negatives = [v[1:] for v in values if v.startswith("!")]
116
+ if current in negatives:
117
+ return False
118
+ if positives and current not in positives:
119
+ return False
120
+ return True
121
+
56
122
  @GeneralUtilities.check_arguments
57
123
  def generate_reference(self) -> None:
58
124
  self.generate_reference_using_docfx()
@@ -49,12 +49,12 @@ class TFCPS_CodeUnit_BuildCodeUnits:
49
49
  except Exception as exception:
50
50
  self.sc.log.log_exception(f"'{product_information_file}' could not be validated against the XSD:", exception, LogLevel.Warning)
51
51
 
52
+ #run prepare-script
53
+ self.run_prepare_script()
54
+
52
55
  #check if changelog exists
53
56
  changelog_file=os.path.join(self.repository,"Other","Resources","Changelog",f"v{self.tfcps_tools_general.get_version_of_project(self.repository)}.md")
54
57
  GeneralUtilities.assert_file_exists(changelog_file,f"Changelogfile \"{changelog_file}\" does not exist. Try to create it for example using \"sccreatechangelogentry -m ...\".")
55
-
56
- #run prepare-script
57
- self.run_prepare_script()
58
58
 
59
59
  #mark current version as supported
60
60
  now = GeneralUtilities.get_now()
@@ -126,15 +126,15 @@ class TFCPS_CodeUnit_BuildCodeUnits:
126
126
  image = self.tfcps_tools_general.oci_image_manager.get_registry_address_for_image_with_default_tag(self.repository, "SCBuilder")
127
127
 
128
128
  #build the scbuildcodeunits-arguments based on the current state (analogous to the arguments accepted by the scbuildcodeunits-executable)
129
- scbuildcodeunits_arguments = ["-r", container_repository_folder, "-v", str(int(self.sc.log.loglevel)), "-e", self.target_environment_type]
129
+ scbuildcodeunits_arguments = "scbuildcodeunits -r /Workspace/Repository -v 4"
130
130
  if not self.__use_cache:
131
- scbuildcodeunits_arguments.append("-c")
131
+ scbuildcodeunits_arguments+="-c"
132
132
  if self.__is_pre_merge:
133
- scbuildcodeunits_arguments.append("-p")
133
+ scbuildcodeunits_arguments+="-p"
134
134
  if self.__assert_no_new_changes:
135
- scbuildcodeunits_arguments.append("-u")
135
+ scbuildcodeunits_arguments+="-u"
136
136
  if GeneralUtilities.string_has_content(self.additionalargumentsfile):
137
- scbuildcodeunits_arguments = scbuildcodeunits_arguments + ["-a", self.__translate_path_into_container(self.additionalargumentsfile, container_repository_folder)]
137
+ scbuildcodeunits_arguments += f" -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,11 +143,15 @@ 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",
147
- ] + scbuildcodeunits_arguments
146
+ scbuildcodeunits_arguments,
147
+ ]
148
148
  self.sc.log.log(f"Build codeunits in container using image \"{image}\"...")
149
- self.sc.run_program_argsasarray("docker", docker_arguments, print_live_output=True)
150
-
149
+ result=self.sc.run_program_argsasarray("docker", docker_arguments, print_live_output=True)
150
+ exit_code:int=result[0]
151
+ stdout:str=result[1] or GeneralUtilities.empty_string
152
+ stderr:str=result[2] or GeneralUtilities.empty_string
153
+ return (exit_code==0,f"{stdout}\n{stderr}")
154
+
151
155
  @GeneralUtilities.check_arguments
152
156
  def __translate_path_into_container(self, host_path: str, container_repository_folder: str) -> str:
153
157
  normalized_repository = os.path.normpath(self.repository)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.3.2
3
+ Version: 4.3.4
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,7 +1,7 @@
1
- ScriptCollection/AnionBuildPlatform.py,sha256=FDf254o-2eoM5jEenIwtaF6CazLhGCup58zWcysVAU8,12116
1
+ ScriptCollection/AnionBuildPlatform.py,sha256=T1tkh4pzQyUb8r5acWiv95TvmkNnDhiNaQAP2dJJvoA,12057
2
2
  ScriptCollection/CertificateUpdater.py,sha256=dR5JpJDlZdjD4_pgMz7zCrt1IM7VfatmK6pULSczxQw,9693
3
3
  ScriptCollection/Executables.py,sha256=Ha0DRqeqxhOM9V-MPd1rozSEWVSRHji6XwysWf7JS8k,66378
4
- ScriptCollection/GeneralUtilities.py,sha256=9-hL-qbbCW42XOz6kMtZyTQA4MsLeCbvqXtuB-Ab_r4,69161
4
+ ScriptCollection/GeneralUtilities.py,sha256=C7QwbcaFWbx2Mchj5yiREzr6m2WZT6Vb7dunZ8KnEvo,69290
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
@@ -9,7 +9,7 @@ ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrR
9
9
  ScriptCollection/ProgramRunnerPopen.py,sha256=8tP0xWKeRYoGlaNB3iUh4o61O-tKtcxrS7IUqtU85C4,4091
10
10
  ScriptCollection/ProgramRunnerSudo.py,sha256=RXsiceQ8W6a8YDk_2BPscVbIAmDIpIxqe9WHBy2r4CM,5233
11
11
  ScriptCollection/SCLog.py,sha256=Z-HhC_CRtU3HdQflNsabFh9IJOucHcXmxMDcf58fli0,4671
12
- ScriptCollection/ScriptCollectionCore.py,sha256=QC7FiZfkdHptd9KBrX-G4j8K1DP4XeqR_v8vbetgS94,223576
12
+ ScriptCollection/ScriptCollectionCore.py,sha256=Coz09hz6yVGIlH8JMp6kglwiZgQom7OY0uW0Tw0Og5s,224945
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
@@ -35,7 +35,7 @@ ScriptCollection/Resources/MaintenanceSite/MaintenanceSite.html,sha256=CX9S1bdOz
35
35
  ScriptCollection/TFCPS/SCTaskRunnerServer.py,sha256=rpuwSsQ6YQfZS2LGnvOH5ql8zs_-cHU4LQttS7XNT60,11272
36
36
  ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py,sha256=oICRtl85n2puWvchcJIkmLZL1BAylMbzH7ltBGWfqgY,31973
37
37
  ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnit.py,sha256=ulxU6CykkqyE6QWeX8PEyW0rntuK3qfBEbPSIplekfI,9677
38
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=cScWO7n89Gbs3au8U_EczJO53jZx6NFzpm7c46IqO_Q,23733
38
+ ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=bZ7kn9m0X8-tfjIxNCrCtUwi5I726P2Tks4a55C1VpE,23819
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
@@ -57,14 +57,14 @@ ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py,sha256=kyx26AnT1-LySFA46w
57
57
  ScriptCollection/TFCPS/Go/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py,sha256=WcWWtCV3GkAk53RIN_6rjXNvkKZ5i5hBEMCmPQo6j30,1685
59
59
  ScriptCollection/TFCPS/Maven/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
- ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=i2msd3tmXaB8EWF3tIR5jwveIFlZcmeYXMde4UP32P4,14310
60
+ ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=TBYMO1U5wbbSy35VFn4fOh0IwZMLQwsMsP5LAWqGq1E,18175
61
61
  ScriptCollection/TFCPS/NodeJS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
62
  ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py,sha256=Bd1gxCk9Fb6JO4XFk-sUWdn4bOvMJp1xpvN6wTKMh0Y,15890
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.2.dist-info/METADATA,sha256=40TZIz7gN4WJw2kD7Jo_Xq94TdkeDYx9g_QPlfeeDaY,7815
67
- scriptcollection-4.3.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
68
- scriptcollection-4.3.2.dist-info/entry_points.txt,sha256=MwiP9P29EeSfjS19JOZmqbx8OzpZrUWpgMza3EffBs8,5812
69
- scriptcollection-4.3.2.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
70
- scriptcollection-4.3.2.dist-info/RECORD,,
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,,