ScriptCollection 4.3.19__py3-none-any.whl → 4.3.21__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)
@@ -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.19"
41
+ version = "4.3.21"
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")
@@ -2440,11 +2557,10 @@ class ScriptCollectionCore:
2440
2557
  # /nofetch and /nonormalize: avoid network calls / branch normalization (no auth, no DNS, deterministic in containers and offline).
2441
2558
  # called twice as workaround for issue 1877 in gitversion ( https://github.com/GitTools/GitVersion/issues/1877 )
2442
2559
  # timeoutInSeconds: gitversion finishes within seconds on a normal repository; enforce a timeout so a hanging gitversion-process (observed in some build-containers) aborts the build instead of waiting forever.
2443
- gitversion_timeout_in_seconds: int = 30
2560
+ gitversion_timeout_in_seconds: int = 300
2444
2561
  result = self.run_program_argsasarray("gitversion", ["/nofetch", "/nonormalize", "/showVariable", variable], folder, timeoutInSeconds=gitversion_timeout_in_seconds)
2445
2562
  result = self.run_program_argsasarray("gitversion", ["/nofetch", "/nonormalize", "/showVariable", variable], folder, timeoutInSeconds=gitversion_timeout_in_seconds)
2446
2563
  result = GeneralUtilities.strip_new_line_character(result[1])
2447
-
2448
2564
  return result
2449
2565
 
2450
2566
  @GeneralUtilities.check_arguments
@@ -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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scriptcollection
3
- Version: 4.3.19
3
+ Version: 4.3.21
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,7 +9,7 @@ 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=qepijVe-7O3FHy2GSbV8tSeT66ElNCTJgEs3sQ0gn0A,231731
12
+ ScriptCollection/ScriptCollectionCore.py,sha256=XIWHoT5QfjIS7Q9d9eJbL0rusP0AddwTaDVVhGG6Wrs,240126
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=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
@@ -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.19.dist-info/METADATA,sha256=Hvd2A0a2Llg_nC0Z9xFXJjarM2o3g_3hx1ztc4KXHRI,7816
67
- scriptcollection-4.3.19.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
68
- scriptcollection-4.3.19.dist-info/entry_points.txt,sha256=MwiP9P29EeSfjS19JOZmqbx8OzpZrUWpgMza3EffBs8,5812
69
- scriptcollection-4.3.19.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
70
- scriptcollection-4.3.19.dist-info/RECORD,,
66
+ scriptcollection-4.3.21.dist-info/METADATA,sha256=FrpFP-xf87f-nRdbWPG5dILQAW0qfEFZ0wNYvsi8A2w,7816
67
+ scriptcollection-4.3.21.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
68
+ scriptcollection-4.3.21.dist-info/entry_points.txt,sha256=Iq9YMSTWNCAJpBzM5L9CQx80tL9-XUu6MzDRAdBrIPg,5875
69
+ scriptcollection-4.3.21.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
70
+ scriptcollection-4.3.21.dist-info/RECORD,,
@@ -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