ScriptCollection 4.3.20__py3-none-any.whl → 4.3.22__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.
@@ -423,6 +423,24 @@ def FileExists() -> int:
423
423
  return 2
424
424
 
425
425
 
426
+ def CheckPythonAst() -> int:
427
+ parser = argparse.ArgumentParser(description="Checks python-source-files for syntax-errors by parsing them with the ast-module (without executing them). The path can be a single file or a folder (checked recursively for '*.py'-files). Returns exit-code 0 if all checked files are syntactically valid, 2 if at least one file has a syntax-error and 1 on error (for example if the path does not exist).")
428
+ parser.add_argument('-p', '--path', required=True, help="File or folder to check.")
429
+ args = parser.parse_args()
430
+ sc = ScriptCollectionCore()
431
+ try:
432
+ errors = sc.check_python_ast(args.path)
433
+ except Exception as exception:
434
+ GeneralUtilities.write_message_to_stderr(str(exception))
435
+ return 1
436
+ if len(errors) == 0:
437
+ GeneralUtilities.write_message_to_stdout("All checked python-files are syntactically valid.")
438
+ return 0
439
+ for (file, line, column, message) in errors:
440
+ GeneralUtilities.write_message_to_stderr(f"{file}:{line}:{column}: {message}")
441
+ return 2
442
+
443
+
426
444
  def FolderExists() -> int:
427
445
  parser = argparse.ArgumentParser(description="This function returns 0 if the given folder exists. Otherwise this function returns 2. If an error occurrs the exitcode is 1.")
428
446
  parser.add_argument('-p', '--path', required=True)
@@ -36,3 +36,9 @@ class AbstractImageHandler(ABC):
36
36
  @abstractmethod
37
37
  def get_default_echolon_for_update(self,image_name:str)->VersionEcholon:
38
38
  raise NotImplementedError()#because it is abstract
39
+
40
+ def get_latest_version_custom(self,image_name:str,registry_address:str,current_version:Version)->Version:
41
+ """Determines the latest version of an image using an image-specific custom algorithm.
42
+ This is used when the echolon VersionEcholon.CustomAlgorithm is selected.
43
+ Image-handlers which want to support a custom algorithm must override this method."""
44
+ raise NotImplementedError(f"Image-handler \"{type(self).__name__}\" does not define a custom algorithm for determining the latest version of image \"{image_name}\".")
@@ -130,7 +130,7 @@ class OCIImageManager:
130
130
  newest_versions:set[Version]={default_tag}
131
131
  current_version=Version(default_tag)
132
132
  for address in addresses_to_check:
133
- newest_versions_for_address=self.get_available_versions_of_image_which_are_newer(image_name,address,current_version,VersionEcholon.LatestVersion)
133
+ newest_versions_for_address=self.get_latest_of_image(image_name,address,current_version,VersionEcholon.LatestVersion)
134
134
  if newest_versions_for_address is not None:
135
135
  newest_versions.update(newest_versions_for_address)
136
136
  GeneralUtilities.assert_condition(len(newest_versions)>0,f"Could not find any version for image {image_name} in registry {registry_address}.")
@@ -142,13 +142,66 @@ class OCIImageManager:
142
142
  GeneralUtilities.write_lines_to_file(file,new_lines)
143
143
 
144
144
  @GeneralUtilities.check_arguments
145
- def get_available_versions_of_image_which_are_newer(self,image_name:str,registry_address:str,current_version:Version,echolon: VersionEcholon)->Version:
146
- #image_handler=self.get_image_handler(image_name)
147
- result= None #TODO calculate result using get_available_tags_of_image.
148
- #TODO if echolon is not none, then use echolon instead of the default echolon of the image-handler.
149
- #TODO return the versions sorted.
150
- #TODO if result is empty: return None
145
+ def get_latest_of_image(self,image_name:str,registry_address:str,current_version:Version,echolon: VersionEcholon)->Version:
146
+ result= None
147
+ image_handler=self.get_image_handler(image_name)
148
+ if echolon not in (VersionEcholon.NoUpdate, VersionEcholon.CustomAlgorithm):
149
+ available_tags:list[str]=self.get_available_tags_of_image(image_name,registry_address)
150
+ available_versions:set[Version]={image_handler.tag_to_version(image_name,tag) for tag in available_tags}
151
+ #the current version must always be a candidate so that the result is never a downgrade
152
+ available_versions.add(current_version)
153
+ match echolon:
154
+ case VersionEcholon.LatestPatch:#caution: this never updates the minor or major version
155
+ #take the latest available patch-version for the current minor-version of the image.
156
+ result=self.__get_latest_patch(available_versions,current_version.major,current_version.minor)
157
+ case VersionEcholon.LatestPatchOrLatestMinor:#caution: this never updates the major version
158
+ #take the latest available patch-version for the current minor-version of the image if there is a newer patch version available.
159
+ #otherwise take the latest available patch-version of the next available minor-version within the current major-version.
160
+ result=self.__get_latest_patch_or_next_minor(available_versions,current_version)
161
+ case VersionEcholon.LatestPatchOrLatestMinorOrNextMajor:#usual case for images which have complex migrations sometimes, like GitLab or NextCloud
162
+ #like LatestPatchOrLatestMinor, but if there is neither a newer patch nor a newer minor-version available within the current major-version
163
+ #then take the latest available patch-version of the lowest minor-version of the next available major-version.
164
+ result=self.__get_latest_patch_or_next_minor(available_versions,current_version)
165
+ if result==current_version:
166
+ next_major=self.__get_next_higher_value({v.major for v in available_versions},current_version.major)
167
+ if next_major is not None:
168
+ lowest_minor=min({v.minor for v in available_versions if v.major==next_major})
169
+ result=self.__get_latest_patch(available_versions,next_major,lowest_minor)
170
+ case VersionEcholon.LatestVersion:#usual case for most images
171
+ #take the latest available version of the image.
172
+ result=max(available_versions)
173
+ case VersionEcholon.CustomAlgorithm:
174
+ #the image-handler decides which version to use for the given current version.
175
+ result=image_handler.get_latest_version_custom(image_name,registry_address,current_version)
176
+ case VersionEcholon.NoUpdate:
177
+ result = current_version
151
178
  return result
179
+
180
+ @GeneralUtilities.check_arguments
181
+ def __get_latest_patch(self,available_versions:set[Version],major:int,minor:int)->Version:
182
+ """Returns the latest available patch-version for the given major- and minor-version or None if no such version is available."""
183
+ matching_versions={v for v in available_versions if v.major==major and v.minor==minor}
184
+ if len(matching_versions)==0:
185
+ return None
186
+ return max(matching_versions)
187
+
188
+ @GeneralUtilities.check_arguments
189
+ def __get_latest_patch_or_next_minor(self,available_versions:set[Version],current_version:Version)->Version:
190
+ latest_patch=self.__get_latest_patch(available_versions,current_version.major,current_version.minor)
191
+ if latest_patch is not None and latest_patch>current_version:
192
+ return latest_patch
193
+ next_minor=self.__get_next_higher_value({v.minor for v in available_versions if v.major==current_version.major},current_version.minor)
194
+ if next_minor is not None:
195
+ return self.__get_latest_patch(available_versions,current_version.major,next_minor)
196
+ return current_version
197
+
198
+ @GeneralUtilities.check_arguments
199
+ def __get_next_higher_value(self,values:set[int],current_value:int)->int:
200
+ """Returns the smallest value in values which is greater than current_value or None if no such value exists."""
201
+ higher_values={v for v in values if v>current_value}
202
+ if len(higher_values)==0:
203
+ return None
204
+ return min(higher_values)
152
205
 
153
206
  @GeneralUtilities.check_arguments
154
207
  def get_available_tags_of_image(self,image_name:str,registry_address:str)->list[str]:
@@ -194,9 +247,11 @@ class OCIImageManager:
194
247
  return result
195
248
 
196
249
  @GeneralUtilities.check_arguments
197
- def update_image_in_docker_compose_file(self,docker_compose_file:str,default_echolon:VersionEcholon=None,per_image_echolons:dict[str,VersionEcholon]=None)->None:
250
+ def update_image_in_docker_compose_file(self,docker_compose_file:str,default_echolon:VersionEcholon=None,per_image_echolons:dict[str,VersionEcholon]=None,verbose:bool=False)->None:
198
251
  if per_image_echolons is None:
199
252
  per_image_echolons = {}
253
+ if verbose:
254
+ self.__sc.log.log(f"Checking images in docker-compose-file \"{docker_compose_file}\" for updates.",LogLevel.Information)
200
255
  for service,service_information in self.get_images_used_in_docker_compose_file(docker_compose_file).items():
201
256
  image_name=service_information[0]
202
257
  image_address=service_information[1]
@@ -205,12 +260,19 @@ class OCIImageManager:
205
260
  effective_echolon=per_image_echolons.get(image_name,default_echolon)
206
261
  if effective_echolon is None:
207
262
  effective_echolon=image_handler.get_default_echolon_for_update()
208
- new_versions_for_address=self.get_available_versions_of_image_which_are_newer(image_name,image_address,self.tag_to_version(image_name,current_tag),effective_echolon)
263
+ if verbose:
264
+ self.__sc.log.log(f"Service \"{service}\": checking image \"{image_address}:{current_tag}\" using echolon \"{effective_echolon.name}\".",LogLevel.Information)
265
+ new_versions_for_address=self.get_latest_of_image(image_name,image_address,self.tag_to_version(image_name,current_tag),effective_echolon)
209
266
  new_tag=self.version_to_tag(image_name,new_versions_for_address)
210
267
  if new_tag is not None and new_tag != current_tag:
211
268
  new_image_reference = f"{image_address}:{new_tag}"
269
+ if verbose:
270
+ self.__sc.log.log(f"Service \"{service}\": updating image \"{image_address}\" from tag \"{current_tag}\" to tag \"{new_tag}\".",LogLevel.Information)
212
271
  with open(docker_compose_file, "r", encoding="utf-8") as f:
213
272
  compose_data = yaml.safe_load(f)
214
273
  compose_data["services"][service]["image"] = new_image_reference
215
274
  with open(docker_compose_file, "w", encoding="utf-8") as f:
216
275
  yaml.safe_dump(compose_data, f, default_flow_style=False, sort_keys=False)
276
+ else:
277
+ if verbose:
278
+ self.__sc.log.log(f"Service \"{service}\": image \"{image_address}\" is already up-to-date at tag \"{current_tag}\".",LogLevel.Information)
@@ -1,5 +1,6 @@
1
1
  from datetime import timedelta, datetime
2
2
  from functools import cmp_to_key
3
+ import ast
3
4
  import json
4
5
  import binascii
5
6
  import filecmp
@@ -37,7 +38,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
37
38
  from .ProgramRunnerPopen import ProgramRunnerPopen
38
39
  from .SCLog import SCLog, LogLevel
39
40
 
40
- version = "4.3.20"
41
+ version = "4.3.22"
41
42
  __version__ = version
42
43
 
43
44
  class VSCodeWorkspaceShellTask:
@@ -171,6 +172,8 @@ class ScriptCollectionCore:
171
172
  self.call_program_runner_directly = None
172
173
  self.__mocked_program_calls = list[ScriptCollectionCore.__MockProgramCall]()
173
174
  self.log = SCLog(None, LogLevel.Warning, False)
175
+ # in-memory-cache (first level) for the result of __get_next_version_from_gitversion (which performs an expensive clone) keyed by (repository_folder, commit_id, branch_name); a persistent second-level cache-file below the repository is used additionally. the result only depends on the committed state and the branch-name, so this key invalidates itself as soon as a new commit is created or another branch/commit is checked out
176
+ self.__next_gitversion_cache = dict[tuple[str, str, str], str]()
174
177
 
175
178
  @staticmethod
176
179
  @GeneralUtilities.check_arguments
@@ -2401,12 +2404,126 @@ class ScriptCollectionCore:
2401
2404
  result = current_version
2402
2405
  else:
2403
2406
  result = self.get_version_from_gitversion(repository_folder, "MajorMinorPatch")
2407
+ if current_commit_is_on_tag and repo_has_uncommitted_changes:
2408
+ result = self.__get_next_version_from_gitversion(repository_folder, current_branch_name)
2404
2409
  else:
2405
2410
  result = "0.1.0"
2406
2411
  else:
2407
2412
  result = "0.1.0"
2408
2413
  return result
2409
2414
 
2415
+ @GeneralUtilities.check_arguments
2416
+ def __get_next_version_from_gitversion(self, repository_folder: str, branch_name: str) -> str:
2417
+ """
2418
+ Computes the version gitversion would assign to the next commit on the given branch.
2419
+ This is needed when the current commit is exactly on a tag but the repository has uncommitted changes:
2420
+ gitversion treats a tagged commit as a released version and therefore reports the tag-version itself,
2421
+ so its result does not reflect that the uncommitted changes will lead to a new (incremented) version.
2422
+ Instead of reimplementing gitversion's increment-logic (which is configured per project in GitVersion.yml
2423
+ and would inevitably drift from it), a disposable clone is created in which the branch is reproduced and an
2424
+ empty commit is added. Gitversion then computes the increment itself - based on the branch-name/-prefix and
2425
+ the repository's own GitVersion.yml - while the original working-directory stays untouched.
2426
+ Because the result only depends on the committed state and the branch-name, it is memoized per
2427
+ (repository_folder, commit_id, branch_name). The in-memory-cache avoids re-cloning within a single process
2428
+ (e. g. the many calls during one scbuildcodeunits-run); a persistent cache-file below the repository additionally
2429
+ avoids re-cloning across separate process-invocations.
2430
+ """
2431
+ commit_id = self.git_get_commit_id(repository_folder)
2432
+ cache_key = (repository_folder, commit_id, branch_name)
2433
+ if cache_key in self.__next_gitversion_cache:
2434
+ return self.__next_gitversion_cache[cache_key]
2435
+ persisted_result = self.__read_next_version_from_disk_cache(repository_folder, commit_id, branch_name)
2436
+ if persisted_result is not None:
2437
+ self.__next_gitversion_cache[cache_key] = persisted_result
2438
+ return persisted_result
2439
+ temp_folder = os.path.join(GeneralUtilities.get_temp_folder(), str(uuid.uuid4()))
2440
+ try:
2441
+ self.git_clone(temp_folder, repository_folder, include_submodules=False)
2442
+ # the local clone already checks out the source's current branch on the tagged commit; the explicit checkout only guarantees gitversion sees the correct branch-name (and thus the correct increment-rule)
2443
+ self.run_program_argsasarray("git", ["checkout", branch_name], temp_folder, throw_exception_if_exitcode_is_not_zero=True)
2444
+ self.git_commit(temp_folder, "Empty commit to let gitversion compute the next version", no_changes_behavior=1)
2445
+ result = self.get_version_from_gitversion(temp_folder, "MajorMinorPatch")
2446
+ self.__next_gitversion_cache[cache_key] = result
2447
+ self.__write_next_version_to_disk_cache(repository_folder, commit_id, branch_name, result)
2448
+ return result
2449
+ finally:
2450
+ GeneralUtilities.ensure_directory_does_not_exist(temp_folder)
2451
+
2452
+ @GeneralUtilities.check_arguments
2453
+ def get_scriptcollection_repository_cache_folder(self, repository_folder: str) -> str:
2454
+ return os.path.join(repository_folder, ".ScriptCollection", "Cache")
2455
+
2456
+ @GeneralUtilities.check_arguments
2457
+ def ensure_scriptcollection_gitignore_is_setup(self, repository_folder: str) -> None:
2458
+ """Ensures that "<repository>/.ScriptCollection/.gitignore" exists and contains the expected entries."""
2459
+ scriptcollection_folder = os.path.join(repository_folder, ".ScriptCollection")
2460
+ GeneralUtilities.ensure_directory_exists(scriptcollection_folder)
2461
+ gitignore_file = os.path.join(scriptcollection_folder, ".gitignore")
2462
+ lines = ["/Cache/"]
2463
+ GeneralUtilities.write_lines_to_file(gitignore_file, lines)
2464
+
2465
+ @GeneralUtilities.check_arguments
2466
+ def __get_next_version_disk_cache_file(self, repository_folder: str) -> str:
2467
+ return os.path.join(self.get_scriptcollection_repository_cache_folder(repository_folder), "GitVersionNextVersion.txt")
2468
+
2469
+ @GeneralUtilities.check_arguments
2470
+ def __read_next_version_from_disk_cache(self, repository_folder: str, commit_id: str, branch_name: str) -> str:
2471
+ # returns None if there is no cached entry for the given commit and branch. the entries use a tab as separator because git-ref-names can not contain tabs (or any other control-character), so the branch-name can never collide with the separator.
2472
+ cache_file = self.__get_next_version_disk_cache_file(repository_folder)
2473
+ if not os.path.isfile(cache_file):
2474
+ return None
2475
+ for line in GeneralUtilities.read_nonempty_lines_from_file(cache_file):
2476
+ parts = line.split("\t")
2477
+ if len(parts) == 3 and parts[0] == commit_id and parts[1] == branch_name:
2478
+ return parts[2]
2479
+ return None
2480
+
2481
+ @GeneralUtilities.check_arguments
2482
+ def __write_next_version_to_disk_cache(self, repository_folder: str, commit_id: str, branch_name: str, version_to_cache: str) -> None:
2483
+ # the cache-file lives below ".ScriptCollection/Cache"; ensure the .gitignore is set up first so writing the cache never introduces uncommitted changes.
2484
+ self.ensure_scriptcollection_gitignore_is_setup(repository_folder)
2485
+ cache_file = self.__get_next_version_disk_cache_file(repository_folder)
2486
+ GeneralUtilities.ensure_directory_exists(os.path.dirname(cache_file))
2487
+ lines = []
2488
+ if os.path.isfile(cache_file):
2489
+ for line in GeneralUtilities.read_nonempty_lines_from_file(cache_file):
2490
+ parts = line.split("\t")
2491
+ if not (len(parts) == 3 and parts[0] == commit_id and parts[1] == branch_name):
2492
+ lines.append(line)
2493
+ lines.append(f"{commit_id}\t{branch_name}\t{version_to_cache}")
2494
+ GeneralUtilities.write_lines_to_file(cache_file, lines)
2495
+
2496
+ @GeneralUtilities.check_arguments
2497
+ def check_python_ast(self, path: str) -> list[tuple[str, int, int, str]]:
2498
+ """
2499
+ Parses python-source-files with the ast-module to detect syntax-errors without executing them.
2500
+ 'path' can be a single file (which is checked regardless of its file-extension) or a folder (in which case
2501
+ all "*.py"-files below it are checked recursively). Returns one (file, line, column, message)-tuple for every
2502
+ file that could not be parsed; an empty list means all checked files are syntactically valid. Raises a
2503
+ ValueError if 'path' neither exists as file nor as folder.
2504
+ """
2505
+ files_to_check: list[str] = []
2506
+ if os.path.isfile(path):
2507
+ files_to_check.append(path)
2508
+ elif os.path.isdir(path):
2509
+ for root, _, files in os.walk(path):
2510
+ for file in files:
2511
+ if file.endswith(".py"):
2512
+ files_to_check.append(os.path.join(root, file))
2513
+ else:
2514
+ raise ValueError(f"Path '{path}' does not exist as file or folder.")
2515
+ result: list[tuple[str, int, int, str]] = []
2516
+ for file in sorted(files_to_check):
2517
+ try:
2518
+ with open(file, "r", encoding="utf-8") as file_handle:
2519
+ source = file_handle.read()
2520
+ ast.parse(source, filename=file)
2521
+ except SyntaxError as syntax_error:
2522
+ result.append((file, syntax_error.lineno or 0, syntax_error.offset or 0, syntax_error.msg or "Syntax-error"))
2523
+ except UnicodeDecodeError as decode_error:
2524
+ result.append((file, 0, 0, f"File could not be decoded as utf-8: {decode_error}"))
2525
+ return result
2526
+
2410
2527
  @GeneralUtilities.check_arguments
2411
2528
  def get_real_git_folder(self,repository_folder:str) -> str:
2412
2529
  git_folder = os.path.join(repository_folder, ".git")
@@ -1,8 +1,6 @@
1
1
  import os
2
2
  import re
3
- import sys
4
3
  import json
5
- import platform
6
4
  from pathlib import Path
7
5
  import xml.etree.ElementTree as ET
8
6
  from lxml import etree
@@ -51,74 +49,10 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
51
49
  def do_common_tasks(self,current_codeunit_version:str)-> None:
52
50
  codeunit_version = current_codeunit_version
53
51
  codeunit_folder = self.get_codeunit_folder()
54
- self.__remove_foreign_platform_node_modules_packages(codeunit_folder)
55
52
  self.do_common_tasks_base(current_codeunit_version)
56
53
  self.tfcps_Tools_General.replace_version_in_packagejson_file(GeneralUtilities.resolve_relative_path("./package.json", codeunit_folder), codeunit_version)
57
54
  self.tfcps_Tools_General.do_npm_install(codeunit_folder, True,self.use_cache())
58
55
 
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
-
122
56
  @GeneralUtilities.check_arguments
123
57
  def generate_reference(self) -> None:
124
58
  self.generate_reference_using_docfx()
@@ -7,6 +7,7 @@ import uuid
7
7
  from datetime import datetime, timedelta,timezone
8
8
  import xmlschema
9
9
  import yaml
10
+ from packaging.version import Version
10
11
  from ..GeneralUtilities import GeneralUtilities
11
12
  from ..ScriptCollectionCore import ScriptCollectionCore
12
13
  from ..SCLog import LogLevel
@@ -44,16 +45,32 @@ class TFCPS_CodeUnit_BuildCodeUnits:
44
45
  self.sc.log.log(GeneralUtilities.get_line())
45
46
  start_time:datetime=GeneralUtilities.get_now()
46
47
 
48
+ #assert that the product-information-file exists
49
+ product_information_file = os.path.join(self.repository, ".ScriptCollection", "ProductInformation.xml")
50
+ GeneralUtilities.assert_file_exists(product_information_file, f"The file '{product_information_file}' does not exist.")
51
+
52
+ #when the build runs inside a container, ensure the used SCBuilder-image is at least the version required by this repository (defined in .ScriptCollection/OCIImages/ImageDefinition.csv)
53
+ if self.sc.is_runnning_in_container():
54
+ scbuilder_version_environment_value = os.environ.get("SCBuilderVersion")
55
+ GeneralUtilities.assert_condition(GeneralUtilities.string_has_content(scbuilder_version_environment_value), "The environment-variable 'SCBuilderVersion' is not set although the build runs inside a container (environment-variable 'ISRUNNINGINCONTAINER' is 'true').")
56
+ required_scbuilder_version = Version(self.tfcps_tools_general.oci_image_manager.get_tag_for_image(self.repository, "SCBuilder"))
57
+ version_match = re.search(r"\d+(\.\d+)+", scbuilder_version_environment_value)
58
+ GeneralUtilities.assert_condition(version_match is not None, f"The environment-variable 'SCBuilderVersion' (value: '{scbuilder_version_environment_value}') does not contain a version-string.")
59
+ actual_scbuilder_version = Version(version_match.group(0))
60
+ GeneralUtilities.assert_condition(actual_scbuilder_version >= required_scbuilder_version, f"The used SCBuilder-version {actual_scbuilder_version} is older than the version {required_scbuilder_version} required by '{self.tfcps_tools_general.get_product_name(self.repository)}' (defined in .ScriptCollection/OCIImages/ImageDefinition.csv). Please update to a newer SCBuilder-image.")
61
+
47
62
  if self.is_pre_merge():
48
63
  GeneralUtilities.assert_condition(not self.__assert_no_new_changes,f"A pre-merge build can not be done with the assert-no-new-changes-option.")
49
64
  ready_to_merge_file=os.path.join(self.repository,".ScriptCollection",".IsReadyToMerge")
50
65
  GeneralUtilities.ensure_file_does_not_exist(ready_to_merge_file)
51
66
 
67
+ #ensure <repo>/.ScriptCollection/.gitignore is set up (ignores the cache-folder so cache-files never show up as uncommitted changes)
68
+ self.sc.ensure_scriptcollection_gitignore_is_setup(self.repository)
69
+
52
70
  self.sc.log.log(f"Start building codeunits at {GeneralUtilities.datetime_to_string_for_readable_entry(start_time,False)}. (Target environment-type: {self.target_environment_type})")
53
71
  if self.__assert_no_new_changes:
54
72
  self.sc.assert_no_uncommitted_changes(self.repository,"Can not build codeunit: There are uncommitted changes in the repository.")
55
73
 
56
- product_information_file = os.path.join(self.repository, ".ScriptCollection", "ProductInformation.xml")
57
74
  try:
58
75
  xmlschema.validate(product_information_file, "https://projects.aniondev.de/PublicProjects/Common/ProjectTemplates/-/raw/main/Conventions/RepositoryStructure/CommonProjectStructure/projectinformation.xsd")
59
76
  except Exception as exception:
@@ -9,6 +9,7 @@ import tarfile
9
9
  import time
10
10
  import re
11
11
  import sys
12
+ import platform
12
13
  import json
13
14
  import uuid
14
15
  import urllib.request
@@ -1070,7 +1071,20 @@ class TFCPS_Tools_General:
1070
1071
  @GeneralUtilities.check_arguments
1071
1072
  def do_npm_install(self, package_json_folder: str, npm_force: bool,use_cache:bool) -> None:
1072
1073
  target_folder:str=os.path.join(package_json_folder,"node_modules")
1073
- update:bool=not os.path.isdir(target_folder) or GeneralUtilities.folder_is_empty(target_folder) or not use_cache
1074
+ platform_marker_file:str=os.path.join(target_folder,".sc_installed_for_platform")
1075
+ current_platform:str=f"{sys.platform}-{platform.machine().lower()}"
1076
+ # node_modules holds platform-specific native binaries (esbuild, rollup, lightningcss, swc, ...) which
1077
+ # get installed only for the current host-platform. When node_modules is cached/shared between build-hosts
1078
+ # of different platforms (e.g. a Windows-native build via 'scbuildcodeunits' followed by a build inside a
1079
+ # mounted Linux-container via 'scbuildcodeunitsc') the cached node_modules contains the binaries for the
1080
+ # foreign platform and lacks the ones for the current platform, which breaks the build. Therefore the cache
1081
+ # is only reused when it was installed for exactly the current platform; otherwise a fresh install is forced
1082
+ # so 'npm clean-install' rebuilds node_modules with the binaries matching the current platform.
1083
+ cache_is_reusable:bool=os.path.isdir(target_folder) \
1084
+ and not GeneralUtilities.folder_is_empty(target_folder) \
1085
+ and os.path.isfile(platform_marker_file) \
1086
+ and GeneralUtilities.read_text_from_file(platform_marker_file).strip()==current_platform
1087
+ update:bool=not (use_cache and cache_is_reusable)
1074
1088
  if update:
1075
1089
  self.__sc.log.log("Do npm-install...")
1076
1090
  argument1 = "install"
@@ -1088,6 +1102,9 @@ class TFCPS_Tools_General:
1088
1102
  argument3 = f"{argument3} --force"
1089
1103
  self.__sc.run_with_epew("npm", argument3, package_json_folder)
1090
1104
 
1105
+ # 'npm clean-install' recreates node_modules, so the platform-marker must be written afterwards.
1106
+ GeneralUtilities.write_text_to_file(platform_marker_file, current_platform)
1107
+
1091
1108
  @staticmethod
1092
1109
  @GeneralUtilities.check_arguments
1093
1110
  def sort_reference_folder(folder1: str, folder2: str) -> int:
@@ -1864,13 +1881,13 @@ class TFCPS_Tools_General:
1864
1881
 
1865
1882
  @GeneralUtilities.check_arguments
1866
1883
  def try_update_basic_codeunitreference_from_examples_repository(self, codeunit_folder:str,example_codeunit_name: str):
1867
- source=f"https://raw.githubusercontent.com/anionDevelopment/CommonProjectStructureExamples/refs/heads/main/{example_codeunit_name}/Other/Reference/ReferenceContent/HowToBuild.md"
1884
+ source=f"https://raw.githubusercontent.com/anionDev/CommonProjectStructureExamples/refs/heads/main/{example_codeunit_name}/Other/Reference/ReferenceContent/HowToBuild.md"
1868
1885
  target=f"{codeunit_folder}/Other/Reference/ReferenceContent/HowToBuild.md"
1869
1886
  self.download_file(source,target)
1870
1887
 
1871
1888
  @GeneralUtilities.check_arguments
1872
1889
  def try_update_basic_repositoryreference_from_examples_repository(self, repository_folder:str):
1873
- source=f"https://raw.githubusercontent.com/anionDevelopment/CommonProjectStructureExamples/refs/heads/main/Other/Reference/RepositoryStructure.mdd"
1890
+ source=f"https://raw.githubusercontent.com/anionDev/CommonProjectStructureExamples/refs/heads/main/Other/Reference/RepositoryStructure.mdd"
1874
1891
  target=f"{repository_folder}/Other/Reference/RepositoryStructure.md"
1875
1892
  self.download_file(source,target)
1876
1893
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.3.20
3
+ Version: 4.3.22
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,6 +1,6 @@
1
1
  ScriptCollection/AnionBuildPlatform.py,sha256=GP-jnb1GbvT8jzlH-cqnxgOzBzeUdiaWnDXtKNjsxiA,12153
2
2
  ScriptCollection/CertificateUpdater.py,sha256=dR5JpJDlZdjD4_pgMz7zCrt1IM7VfatmK6pULSczxQw,9693
3
- ScriptCollection/Executables.py,sha256=DHutD8oaI2g71LV-rZ75gg1h4JywoRCKQDLobWPYS5A,66665
3
+ ScriptCollection/Executables.py,sha256=7iPFQ0xuP_foBTe4lfkTiB51eun1DTD9k-lo5wF-Eug,67720
4
4
  ScriptCollection/GeneralUtilities.py,sha256=qYhrKkwbEewGIppuxYRmGhLP50C443tw7sBlwH7Mkbc,71606
5
5
  ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
6
6
  ScriptCollection/ProcessesRunner.py,sha256=yYaC95h40uszuZPggn2kK3qXIN2ZjGMCavo-NQ53ElQ,1537
@@ -9,11 +9,11 @@ ScriptCollection/ProgramRunnerMock.py,sha256=uTu-aFle1W_oKjeQEmuPsFPQpvo0kRf2FrR
9
9
  ScriptCollection/ProgramRunnerPopen.py,sha256=zVD-gZY85o8wiGFcpYAGNDl-tXaKzipl1Bkhqy2ois4,4681
10
10
  ScriptCollection/ProgramRunnerSudo.py,sha256=RXsiceQ8W6a8YDk_2BPscVbIAmDIpIxqe9WHBy2r4CM,5233
11
11
  ScriptCollection/SCLog.py,sha256=LdzSJy3NnnwYCCefz2h4tiTy4BjT8lOz3IBG_bMOg9E,4821
12
- ScriptCollection/ScriptCollectionCore.py,sha256=0X5OfgPVUB7nj5U0pfyPB-OoqmbWz6SriEvIg2JFvfs,231730
12
+ ScriptCollection/ScriptCollectionCore.py,sha256=zqWcE7-K2hhcu5t4gOQGBg4ShegoRkFBuZaxb7hbYxo,240126
13
13
  ScriptCollection/UnassignedVariablesCheck.py,sha256=v59qLQ5RRvx31ouuCW7NWZj3McWENvGBPkV5ZGBmqJE,4344
14
14
  ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
- ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=o129UYDtLymCRjMZBP9Puaj19ueMHoNt6UTLspfnaRc,1758
16
- ScriptCollection/OCIImages/OCIImageManager.py,sha256=-xanWakEZBEWbgrA1IKzY1hYBWo2j_Juk2hDJPTvwiE,12674
15
+ ScriptCollection/OCIImages/AbstractImageHandler.py,sha256=WO2M28c2tUwsXFNa2L9zqMhdlyObWm3qpPE0LdIs7SE,2315
16
+ ScriptCollection/OCIImages/OCIImageManager.py,sha256=-fhOfwNva41OYBZ6__pn_9s5IZou7Ws1sGF77IUWVDM,17438
17
17
  ScriptCollection/OCIImages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebian.py,sha256=rty9SnftreYWLIwvdUn4LhiHqCTevb_tWuYWoOnRJuo,732
19
19
  ScriptCollection/OCIImages/ConcreteImageHandlers/ImageHandlerDebianSlim.py,sha256=M-4qxKWBZRtKdYQ-uXgfrxRBoZTXEjgqCxFXyFxTyzc,736
@@ -35,14 +35,14 @@ 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=Ll5EOkpVpPiFrM2mLeQXolaF7075IwgtnHXvfdpkH4k,9904
38
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=YqGlKah7N7iU2OBlxtukH0F0ZCyz56psxEfu0Y5UGvA,29122
38
+ ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py,sha256=FAb1AIfsFUg4kIrSleDu1mjbGJTHmqVjTxSQBErtFcI,31104
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=zp7n0Li7GTi4tERDMgDcJ-o3m6131m31zvkat0lALEc,7781
42
42
  ScriptCollection/TFCPS/TFCPS_MergeToStable.py,sha256=jQ0B3yq45we-8a0KuNFMfXCk9MfzPpTv2QgDWMN34x4,22792
43
43
  ScriptCollection/TFCPS/TFCPS_PreBuildCodeunitsScript.py,sha256=JYiDqDsfVJQWS9xWMi_UzfXnXsJRnPRxAzFr82bUEvI,2370
44
44
  ScriptCollection/TFCPS/TFCPS_RemoteBuild.py,sha256=Z8Gw-j5I7VPafHEsVeQJ2gTTKVLAnnhwZhY8IVTi2Qk,11867
45
- ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=di4RRYcKcDEKRfyEsrSMAGxuHSeaqG_v09F4159GzJ0,126271
45
+ ScriptCollection/TFCPS/TFCPS_Tools_General.py,sha256=nPk14lYfIMp5Z9lA8yvXZfzZbV3Cby5JCErJH82bsMI,127650
46
46
  ScriptCollection/TFCPS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
47
47
  ScriptCollection/TFCPS/Docker/TFCPS_CodeUnitSpecific_Docker.py,sha256=wS2yzYUmJ4m0cf6cBYVTHsiXSXfYhHoLFFy8x6yEQvY,19573
48
48
  ScriptCollection/TFCPS/Docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -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=TBYMO1U5wbbSy35VFn4fOh0IwZMLQwsMsP5LAWqGq1E,18175
60
+ ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=i2msd3tmXaB8EWF3tIR5jwveIFlZcmeYXMde4UP32P4,14310
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.20.dist-info/METADATA,sha256=ZkFn19_pVeckzslvcHh1VnocFn6k0GoC3OrnGTs9WB0,7816
67
- scriptcollection-4.3.20.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
68
- scriptcollection-4.3.20.dist-info/entry_points.txt,sha256=MwiP9P29EeSfjS19JOZmqbx8OzpZrUWpgMza3EffBs8,5812
69
- scriptcollection-4.3.20.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
70
- scriptcollection-4.3.20.dist-info/RECORD,,
66
+ scriptcollection-4.3.22.dist-info/METADATA,sha256=nIGhsT-6rGG0hfx_eXXm4xI-PM6o6NTu6k8-3GDZtpI,7816
67
+ scriptcollection-4.3.22.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
68
+ scriptcollection-4.3.22.dist-info/entry_points.txt,sha256=Iq9YMSTWNCAJpBzM5L9CQx80tL9-XUu6MzDRAdBrIPg,5875
69
+ scriptcollection-4.3.22.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
70
+ scriptcollection-4.3.22.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (83.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -6,6 +6,7 @@ scbuildcodeunitsc = ScriptCollection.Executables:BuildCodeUnitsC
6
6
  sccalculatebitcoinblockhash = ScriptCollection.Executables:CalculateBitcoinBlockHash
7
7
  scchangefileextension = ScriptCollection.Executables:ChangeFileExtensions
8
8
  scchangehashofprogram = ScriptCollection.Executables:ChangeHashOfProgram
9
+ sccheckpythonast = ScriptCollection.Executables:CheckPythonAst
9
10
  sccleantoolscache = ScriptCollection.Executables:CleanToolsCache
10
11
  scconvertgitrepositorytobarerepository = ScriptCollection.Executables:ConvertGitRepositoryToBareRepository
11
12
  sccopy = ScriptCollection.Executables:Copy