ScriptCollection 4.4.57__py3-none-any.whl → 4.4.58__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.
- ScriptCollection/ScriptCollectionCore.py +1 -1
- ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py +117 -8
- {scriptcollection-4.4.57.dist-info → scriptcollection-4.4.58.dist-info}/METADATA +1 -1
- {scriptcollection-4.4.57.dist-info → scriptcollection-4.4.58.dist-info}/RECORD +7 -7
- {scriptcollection-4.4.57.dist-info → scriptcollection-4.4.58.dist-info}/WHEEL +0 -0
- {scriptcollection-4.4.57.dist-info → scriptcollection-4.4.58.dist-info}/entry_points.txt +0 -0
- {scriptcollection-4.4.57.dist-info → scriptcollection-4.4.58.dist-info}/top_level.txt +0 -0
|
@@ -4,8 +4,10 @@ import re
|
|
|
4
4
|
import shutil
|
|
5
5
|
import uuid
|
|
6
6
|
import json
|
|
7
|
+
import requests
|
|
7
8
|
from lxml import etree
|
|
8
9
|
import yaml
|
|
10
|
+
from packaging.version import Version
|
|
9
11
|
from .CertificateGeneratorInformationBase import CertificateGeneratorInformationBase
|
|
10
12
|
from ...GeneralUtilities import GeneralUtilities, VersionEcholon
|
|
11
13
|
from ...SCLog import LogLevel
|
|
@@ -843,12 +845,50 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
843
845
|
return f'filename="{filename_relative}"'
|
|
844
846
|
|
|
845
847
|
|
|
848
|
+
@GeneralUtilities.check_arguments
|
|
846
849
|
def get_dependencies(self)->dict[str,set[str]]:
|
|
847
|
-
|
|
848
|
-
|
|
850
|
+
csproj_file: str = self.csproj_file
|
|
851
|
+
root: etree._ElementTree = etree.parse(csproj_file)
|
|
852
|
+
result: dict[str, set[str]] = {}
|
|
853
|
+
for package_reference in root.xpath("//PackageReference"):
|
|
854
|
+
attributes: dict[str, str] = {name.lower(): value for name, value in package_reference.attrib.items()}
|
|
855
|
+
package_name: str = attributes.get("include")
|
|
856
|
+
if package_name:
|
|
857
|
+
version: str = attributes.get("version")
|
|
858
|
+
if version:
|
|
859
|
+
version_clean = version.strip().strip("[]")
|
|
860
|
+
if package_name not in result:
|
|
861
|
+
result[package_name] = set()
|
|
862
|
+
result[package_name].add(version_clean)
|
|
863
|
+
return result
|
|
864
|
+
|
|
849
865
|
@GeneralUtilities.check_arguments
|
|
850
|
-
def get_available_versions(self,dependencyname:str)->list[str]:
|
|
851
|
-
|
|
866
|
+
def get_available_versions(self, dependencyname: str) -> list[str]:
|
|
867
|
+
try:
|
|
868
|
+
url = f"https://api.nuget.org/v3/flatcontainer/{dependencyname.lower()}/index.json"
|
|
869
|
+
response = requests.get(url, timeout=10)
|
|
870
|
+
if response.status_code != 200:
|
|
871
|
+
return []
|
|
872
|
+
data = response.json()
|
|
873
|
+
versions: list[str] = data.get("versions", [])
|
|
874
|
+
if not versions:
|
|
875
|
+
return []
|
|
876
|
+
return TFCPS_CodeUnitSpecific_DotNet_Functions.select_updatable_versions_from_nuget_versions(versions)
|
|
877
|
+
except Exception:
|
|
878
|
+
return []
|
|
879
|
+
|
|
880
|
+
@staticmethod
|
|
881
|
+
@GeneralUtilities.check_arguments
|
|
882
|
+
def select_updatable_versions_from_nuget_versions(versions: list[str]) -> list[str]:
|
|
883
|
+
"""Returns the versions from a raw NuGet-version-list which the dependency-update can handle, sorted from the
|
|
884
|
+
latest to the oldest. Only plain three-part-versions (major.minor.patch) are kept: NuGet also lists four-part-
|
|
885
|
+
versions (for example "1.8.0.7") and pre-release-versions (for example "2.8.0-preview4" or "2.9.2-ci-210"), which
|
|
886
|
+
the rest of the update-logic does not support (it asserts a three-part-format) and which "packaging.version.Version"
|
|
887
|
+
can not always parse. Without this strict filter such an unparseable string would let the sorting below raise, which
|
|
888
|
+
the caller turns into an empty version-list and therefore into the misleading error "Version-list can not be empty"
|
|
889
|
+
for a dependency whose registry actually offers usable versions."""
|
|
890
|
+
three_part_versions = [version for version in versions if re.match(r"^\d+\.\d+\.\d+$", version)]
|
|
891
|
+
return sorted(three_part_versions, key=lambda version: Version(version), reverse=True)
|
|
852
892
|
|
|
853
893
|
@GeneralUtilities.check_arguments
|
|
854
894
|
def update_dependencies_with_specific_echolon(self, echolon: VersionEcholon) -> None:
|
|
@@ -858,12 +898,81 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
858
898
|
resolved before. Writing them again is part of the update: without it the next build fails with NU1004, and the
|
|
859
899
|
state of the dependencies of the codeunit would be spread over two places which do not agree."""
|
|
860
900
|
super().update_dependencies_with_specific_echolon(echolon)
|
|
901
|
+
self.synchronize_dependency_versions_across_project_files()
|
|
861
902
|
self.tfcps_Tools_General.update_lock_files_of_dotnet_codeunit(self.get_codeunit_folder())
|
|
862
903
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
904
|
+
@GeneralUtilities.check_arguments
|
|
905
|
+
def get_csproj_files_of_codeunit(self) -> list[str]:
|
|
906
|
+
"""Returns the project-files of this codeunit (the project-file of the library/application and the project-file of
|
|
907
|
+
its tests). Build-output (`bin`, `obj`) and the `Other`-folder (which holds scripts and build-artifacts, not the
|
|
908
|
+
source-projects) are excluded, so only the project-files which declare the dependencies of the codeunit remain."""
|
|
909
|
+
codeunit_folder = self.get_codeunit_folder()
|
|
910
|
+
ignored_folder_names = {"bin", "obj", "Other", ".vs", "node_modules"}
|
|
911
|
+
result: list[str] = []
|
|
912
|
+
for csproj_file in glob.glob(os.path.join(codeunit_folder, "**", "*.csproj"), recursive=True):
|
|
913
|
+
relative_parts = os.path.relpath(csproj_file, codeunit_folder).split(os.sep)
|
|
914
|
+
if not any(part in ignored_folder_names for part in relative_parts):
|
|
915
|
+
result.append(csproj_file)
|
|
916
|
+
return sorted(result)
|
|
917
|
+
|
|
918
|
+
@GeneralUtilities.check_arguments
|
|
919
|
+
def synchronize_dependency_versions_across_project_files(self) -> None:
|
|
920
|
+
"""Pins every dependency which the project-file of this codeunit declares to the same version in the other
|
|
921
|
+
project-files of the codeunit (typically the test-project). The test-project references the library-project, so
|
|
922
|
+
NuGet rejects a restore in which the test-project pins a shared dependency lower than the version the library-
|
|
923
|
+
project requires (error NU1605). The library-project is the source of truth, because its dependencies are the ones
|
|
924
|
+
the update resolves. This runs after every update (and is idempotent when the versions already agree), so a shared
|
|
925
|
+
dependency stays consistent even when the library-project did not have to be changed in this update but the test-
|
|
926
|
+
project was still pinned to an older version from a previous, only partially applied update. The notation of each
|
|
927
|
+
project-file is preserved by set_dependency_version_in_csproj_content (an exact pin keeps its brackets)."""
|
|
928
|
+
main_csproj_file = self.csproj_file
|
|
929
|
+
main_dependencies = self.get_dependencies()
|
|
930
|
+
other_csproj_files = [csproj_file for csproj_file in self.get_csproj_files_of_codeunit() if os.path.abspath(csproj_file) != os.path.abspath(main_csproj_file)]
|
|
931
|
+
for other_csproj_file in other_csproj_files:
|
|
932
|
+
former_content = GeneralUtilities.read_text_from_file(other_csproj_file)
|
|
933
|
+
new_content = former_content
|
|
934
|
+
for dependency_name, dependency_versions in main_dependencies.items():
|
|
935
|
+
new_content = TFCPS_CodeUnitSpecific_DotNet_Functions.set_dependency_version_in_csproj_content(new_content, dependency_name, next(iter(dependency_versions)))
|
|
936
|
+
if new_content != former_content:
|
|
937
|
+
GeneralUtilities.write_text_to_file(other_csproj_file, new_content)
|
|
938
|
+
|
|
939
|
+
@GeneralUtilities.check_arguments
|
|
940
|
+
def set_dependency_version(self, name: str, new_version: str) -> None:
|
|
941
|
+
"""Sets the version of the given dependency in the project-file of this codeunit (the same project-file from which
|
|
942
|
+
get_dependencies reads the dependencies)."""
|
|
943
|
+
csproj_file: str = self.csproj_file
|
|
944
|
+
former_content: str = GeneralUtilities.read_text_from_file(csproj_file)
|
|
945
|
+
new_content: str = TFCPS_CodeUnitSpecific_DotNet_Functions.set_dependency_version_in_csproj_content(former_content, name, new_version)
|
|
946
|
+
GeneralUtilities.assert_condition(new_content != former_content, f"The dependency \"{name}\" could not be set to version \"{new_version}\" because the project-file \"{csproj_file}\" does not declare it with a version-attribute.")
|
|
947
|
+
GeneralUtilities.write_text_to_file(csproj_file, new_content)
|
|
948
|
+
|
|
949
|
+
@staticmethod
|
|
950
|
+
@GeneralUtilities.check_arguments
|
|
951
|
+
def set_dependency_version_in_csproj_content(content: str, name: str, new_version: str) -> str:
|
|
952
|
+
"""Returns the content of a .csproj-file in which the version of the given dependency is set to the new version.
|
|
953
|
+
The version is written into the "Version"-attribute of every "PackageReference" whose "Include"-attribute names
|
|
954
|
+
the dependency; the rest of the file (formatting, order and every other dependency) stays untouched, the same way
|
|
955
|
+
the pub- and npm-updaters change only the declaration of the dependency they update. The notation of the former
|
|
956
|
+
version is preserved: a version which was pinned exactly with brackets (for example "[2.9.1]") keeps its brackets
|
|
957
|
+
("[2.9.2]") and an unbracketed version stays unbracketed, so that the meaning the project-file assigns to the
|
|
958
|
+
declaration (an exact pin stays an exact pin) is not changed by the update. A project-file which does not declare
|
|
959
|
+
the dependency with a version-attribute is returned unchanged."""
|
|
960
|
+
package_reference_tag = re.compile(r"<PackageReference\b[^>]*?/?>", re.IGNORECASE)
|
|
961
|
+
include_attribute = re.compile(r'\bInclude\s*=\s*"([^"]*)"', re.IGNORECASE)
|
|
962
|
+
version_attribute = re.compile(r'(\bVersion\s*=\s*")(\[?)([^"]*?)(\]?)(")', re.IGNORECASE)
|
|
963
|
+
|
|
964
|
+
def replace_version_in_tag(tag_match: re.Match) -> str:
|
|
965
|
+
tag: str = tag_match.group(0)
|
|
966
|
+
include_match = include_attribute.search(tag)
|
|
967
|
+
if include_match is None or include_match.group(1) != name:
|
|
968
|
+
return tag
|
|
969
|
+
|
|
970
|
+
def replace_version(version_match: re.Match) -> str:
|
|
971
|
+
keeps_brackets: bool = version_match.group(2) == "[" and version_match.group(4) == "]"
|
|
972
|
+
replacement_version: str = f"[{new_version}]" if keeps_brackets else new_version
|
|
973
|
+
return f"{version_match.group(1)}{replacement_version}{version_match.group(5)}"
|
|
974
|
+
return version_attribute.sub(replace_version, tag, count=1)
|
|
975
|
+
return package_reference_tag.sub(replace_version_in_tag, content)
|
|
867
976
|
|
|
868
977
|
|
|
869
978
|
class TFCPS_CodeUnitSpecific_DotNet_CLI:
|
|
@@ -11,7 +11,7 @@ ScriptCollection/ProgramRunnerSudo.py,sha256=vwKq-MOcqsgiKhSf-MBUDBC_UyaU8evP3Ro
|
|
|
11
11
|
ScriptCollection/RepositoryDiagramGenerator.py,sha256=K_u2NW_p4ozdWD50irJEkkcDVa70TcUJpZN63TeXSLw,7092
|
|
12
12
|
ScriptCollection/RepositoryHistoryAnalyzer.py,sha256=u9141B9D-Kef-9uo3yR7BXKUMzIKLVsesnYk7H-cWm4,6157
|
|
13
13
|
ScriptCollection/SCLog.py,sha256=Fjf8Pdi63cXHGMxL_aI6A0dwGm7QIfrv3czjvpSUlaM,4705
|
|
14
|
-
ScriptCollection/ScriptCollectionCore.py,sha256=
|
|
14
|
+
ScriptCollection/ScriptCollectionCore.py,sha256=VYrCeryVrs20r0_EQLe9Nw_cBTdBmRoDCuZXebfYiMk,310633
|
|
15
15
|
ScriptCollection/TestKind.py,sha256=jqLJwNvQeyea7SZf-UFzMC9pM0znv4do7FIC1xq8u9M,1672
|
|
16
16
|
ScriptCollection/UnassignedVariablesCheck.py,sha256=8xNcp1D5HeOLO1a1NEerq2TsnpFhw7yzYPkaay-oisY,3804
|
|
17
17
|
ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -57,7 +57,7 @@ ScriptCollection/TFCPS/Docker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
|
|
|
57
57
|
ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationBase.py,sha256=bT6Gd5pQpZCw4OQz6HWkPCSn5z__eUUEisABLDSxd0o,200
|
|
58
58
|
ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py,sha256=QyjOfMY22JWCvKjMelHiDWbJiWqotOfebpJpgDUaoO4,237
|
|
59
59
|
ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationNoGenerate.py,sha256=i0zEGehj0sttxjjZtoq2KFSKp_ulxVyWp_ZgAhIY_So,241
|
|
60
|
-
ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py,sha256=
|
|
60
|
+
ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py,sha256=78i5ImH9JzBgbhKIls-K9jXNfLAHv-6rn1IOpI9x4BU,71196
|
|
61
61
|
ScriptCollection/TFCPS/DotNet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
62
62
|
ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py,sha256=9PMxJFB4nyKGzl916UOCvHB5toIyLcWk-ZAM8vPdLxw,64571
|
|
63
63
|
ScriptCollection/TFCPS/Flutter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -73,8 +73,8 @@ ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=yyjWPMHQjPLkML
|
|
|
73
73
|
ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
74
74
|
ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=ILVhJHvwG5TvPBBqSvyACYb7W9QnWrJpxKgHu8IQu4g,9249
|
|
75
75
|
ScriptCollection/TFCPS/TypeScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
76
|
-
scriptcollection-4.4.
|
|
77
|
-
scriptcollection-4.4.
|
|
78
|
-
scriptcollection-4.4.
|
|
79
|
-
scriptcollection-4.4.
|
|
80
|
-
scriptcollection-4.4.
|
|
76
|
+
scriptcollection-4.4.58.dist-info/METADATA,sha256=HTvSlWdrzMPoIIpvzNGA5BL9zdSKKKEpMLod2rzbDlI,8032
|
|
77
|
+
scriptcollection-4.4.58.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
78
|
+
scriptcollection-4.4.58.dist-info/entry_points.txt,sha256=--Xk3EcTa14uk1YnUD8CQ2naQjNKJFohScd1ONy4CeY,6135
|
|
79
|
+
scriptcollection-4.4.58.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
|
|
80
|
+
scriptcollection-4.4.58.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|