ScriptCollection 4.4.34__py3-none-any.whl → 4.4.35__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/GeneralUtilities.py +1 -1
- ScriptCollection/ScriptCollectionCore.py +1 -1
- ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +48 -10
- ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py +34 -7
- ScriptCollection/TFCPS/NpmDependencies.py +109 -0
- ScriptCollection/TFCPS/PubDependencies.py +164 -0
- ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py +5 -48
- {scriptcollection-4.4.34.dist-info → scriptcollection-4.4.35.dist-info}/METADATA +1 -1
- {scriptcollection-4.4.34.dist-info → scriptcollection-4.4.35.dist-info}/RECORD +12 -10
- {scriptcollection-4.4.34.dist-info → scriptcollection-4.4.35.dist-info}/WHEEL +0 -0
- {scriptcollection-4.4.34.dist-info → scriptcollection-4.4.35.dist-info}/entry_points.txt +0 -0
- {scriptcollection-4.4.34.dist-info → scriptcollection-4.4.35.dist-info}/top_level.txt +0 -0
|
@@ -1275,7 +1275,7 @@ class GeneralUtilities:
|
|
|
1275
1275
|
cert = crypto.load_certificate(crypto.FILETYPE_PEM, certificate_file_content.read())
|
|
1276
1276
|
date_as_bytes = cert.get_notAfter()
|
|
1277
1277
|
date_as_string = date_as_bytes.decode("utf-8")
|
|
1278
|
-
result = datetime.strptime(date_as_string, '%Y%m%d%H%M%SZ')
|
|
1278
|
+
result = datetime.strptime(date_as_string, '%Y%m%d%H%M%SZ').replace(tzinfo=timezone.utc)
|
|
1279
1279
|
return result
|
|
1280
1280
|
|
|
1281
1281
|
@staticmethod
|
|
@@ -11,9 +11,10 @@ import zipfile
|
|
|
11
11
|
import yaml
|
|
12
12
|
|
|
13
13
|
from ...ArbTranslationsOrganizer import ArbTranslationsOrganizer
|
|
14
|
-
from ...GeneralUtilities import GeneralUtilities
|
|
14
|
+
from ...GeneralUtilities import GeneralUtilities, VersionEcholon
|
|
15
15
|
from ...SCLog import LogLevel
|
|
16
16
|
from ...ScriptCollectionCore import ScriptCollectionCore
|
|
17
|
+
from ..PubDependencies import PubDependencies
|
|
17
18
|
from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base,TFCPS_CodeUnitSpecific_Base_CLI
|
|
18
19
|
from ..TFCPS_RemoteBuild import TFCPS_RemoteBuild, RunnerOperatingSystem
|
|
19
20
|
|
|
@@ -666,16 +667,53 @@ class TFCPS_CodeUnitSpecific_Flutter_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
666
667
|
return re.sub(r' name="lib(\.[^"]*)?"', lambda match: f' name="{codeunit_name}{match.group(1) or ""}"', cobertura_xml_content)
|
|
667
668
|
|
|
668
669
|
|
|
669
|
-
def get_dependencies(self)->dict[str,set[str]]:
|
|
670
|
-
return dict[str,set[str]]()#TODO
|
|
671
|
-
|
|
672
670
|
@GeneralUtilities.check_arguments
|
|
673
|
-
def
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
671
|
+
def get_pubspec_files(self) -> list[str]:
|
|
672
|
+
"""Returns the package-file of every package of this codeunit."""
|
|
673
|
+
return [os.path.join(package_folder, "pubspec.yaml") for package_folder in self.__get_package_folders()]
|
|
674
|
+
|
|
675
|
+
@GeneralUtilities.check_arguments
|
|
676
|
+
def get_dependencies(self) -> dict[str, set[str]]:
|
|
677
|
+
return GeneralUtilities.merge_dependency_lists([PubDependencies.get_dependencies(pubspec_file) for pubspec_file in self.get_pubspec_files()])
|
|
678
|
+
|
|
679
|
+
@GeneralUtilities.check_arguments
|
|
680
|
+
def get_available_versions(self, dependencyname: str) -> list[str]:
|
|
681
|
+
return PubDependencies.get_available_versions(dependencyname)
|
|
682
|
+
|
|
683
|
+
@GeneralUtilities.check_arguments
|
|
684
|
+
def set_dependency_version(self, name: str, new_version: str) -> None:
|
|
685
|
+
# A codeunit can consist of several packages, and a dependency which several of them declare has to be set
|
|
686
|
+
# in every one of them: get_dependencies reports the dependencies of all packages of the codeunit together,
|
|
687
|
+
# so a package which keeps the former version would make the codeunit use two versions of one dependency.
|
|
688
|
+
dependency_was_set: bool = False
|
|
689
|
+
for pubspec_file in self.get_pubspec_files():
|
|
690
|
+
if PubDependencies.set_dependency_version(pubspec_file, name, new_version):
|
|
691
|
+
dependency_was_set = True
|
|
692
|
+
GeneralUtilities.assert_condition(dependency_was_set, f"No package of the codeunit \"{self.get_codeunit_name()}\" contains a dependency which is named \"{name}\".")
|
|
693
|
+
|
|
694
|
+
@GeneralUtilities.check_arguments
|
|
695
|
+
def update_dependencies_with_specific_echolon(self, echolon: VersionEcholon) -> None:
|
|
696
|
+
"""Updates the dependencies of this codeunit and confirms the result in the lock-files of its packages.
|
|
697
|
+
|
|
698
|
+
The update changes the versions the package-files ask for, and the lock-files still state the versions which
|
|
699
|
+
were resolved before. Writing them again is part of the update: without it the state of the dependencies of
|
|
700
|
+
the codeunit would be spread over two files which do not agree, and pub would resolve the old versions
|
|
701
|
+
again as long as they still fit the new constraints.
|
|
702
|
+
|
|
703
|
+
The lock-files are only written when the update really changed a version, because writing them means
|
|
704
|
+
resolving the dependencies again, which is the most expensive part of an update-run."""
|
|
705
|
+
dependencies_before_the_update: dict[str, set[str]] = self.get_dependencies()
|
|
706
|
+
super().update_dependencies_with_specific_echolon(echolon)
|
|
707
|
+
if dependencies_before_the_update == self.get_dependencies():
|
|
708
|
+
return
|
|
709
|
+
for package_folder in self.__get_package_folders():
|
|
710
|
+
# Every package below a package-folder is resolved too, for the same reason for which the linting does
|
|
711
|
+
# so: a package which lies deeper (for example the "example"-application of a library) has a lock-file
|
|
712
|
+
# of its own which states the same dependencies.
|
|
713
|
+
for folder_to_resolve in TFCPS_CodeUnitSpecific_Flutter_Functions.__get_folders_with_a_package(package_folder):
|
|
714
|
+
self._protected_sc.run_with_epew("flutter", "pub get", folder_to_resolve, print_live_output=self.get_verbosity() == LogLevel.Debug)
|
|
715
|
+
|
|
716
|
+
|
|
679
717
|
class TFCPS_CodeUnitSpecific_Flutter_CLI:
|
|
680
718
|
|
|
681
719
|
@staticmethod
|
|
@@ -4,9 +4,10 @@ import json
|
|
|
4
4
|
from pathlib import Path
|
|
5
5
|
import xml.etree.ElementTree as ET
|
|
6
6
|
from lxml import etree
|
|
7
|
-
from ...GeneralUtilities import GeneralUtilities
|
|
7
|
+
from ...GeneralUtilities import GeneralUtilities, VersionEcholon
|
|
8
8
|
from ...SCLog import LogLevel
|
|
9
9
|
from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base,TFCPS_CodeUnitSpecific_Base_CLI
|
|
10
|
+
from ..NpmDependencies import NpmDependencies
|
|
10
11
|
from ...HTTPMaintenanceOverheadHelper import HTTPMaintenanceOverheadHelper
|
|
11
12
|
|
|
12
13
|
class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
@@ -126,17 +127,43 @@ class TFCPS_CodeUnitSpecific_NodeJS_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
126
127
|
self._protected_sc.run_with_epew("cyclonedx-npm", f"--output-format xml --output-file {relative_path_to_bom_file}", self.get_codeunit_folder(),print_live_output=self._protected_sc.log.loglevel==LogLevel.Diagnostic,encode_argument_in_base64=True)
|
|
127
128
|
self._protected_sc.format_xml_file(self.get_codeunit_folder()+"/"+relative_path_to_bom_file)
|
|
128
129
|
|
|
130
|
+
@GeneralUtilities.check_arguments
|
|
131
|
+
def get_package_json_file(self)->str:
|
|
132
|
+
"""Returns the package-file of this codeunit."""
|
|
133
|
+
return os.path.join(self.get_codeunit_folder(),"package.json")
|
|
134
|
+
|
|
135
|
+
@GeneralUtilities.check_arguments
|
|
129
136
|
def get_dependencies(self)->dict[str,set[str]]:
|
|
130
|
-
return
|
|
131
|
-
|
|
137
|
+
return GeneralUtilities.merge_dependency_lists([NpmDependencies.get_dependencies(self.get_package_json_file())])
|
|
138
|
+
|
|
132
139
|
@GeneralUtilities.check_arguments
|
|
133
140
|
def get_available_versions(self,dependencyname:str)->list[str]:
|
|
134
|
-
return
|
|
135
|
-
|
|
141
|
+
return NpmDependencies.get_available_versions(dependencyname)
|
|
142
|
+
|
|
136
143
|
@GeneralUtilities.check_arguments
|
|
137
144
|
def set_dependency_version(self,name:str,new_version:str)->None:
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
package_json_file:str=self.get_package_json_file()
|
|
146
|
+
GeneralUtilities.assert_condition(NpmDependencies.set_dependency_version(package_json_file,name,new_version),f"The package-file \"{package_json_file}\" does not contain a dependency which is named \"{name}\".")
|
|
147
|
+
self._protected_sc.format_json_file(package_json_file)
|
|
148
|
+
|
|
149
|
+
@GeneralUtilities.check_arguments
|
|
150
|
+
def update_dependencies_with_specific_echolon(self,echolon:VersionEcholon)->None:
|
|
151
|
+
"""Updates the dependencies of this codeunit and confirms the result in its lock-file.
|
|
152
|
+
|
|
153
|
+
The update changes the versions the package-file asks for, and the lock-file still states the versions which
|
|
154
|
+
were resolved before. Writing it again is part of the update: without it the state of the dependencies of
|
|
155
|
+
the codeunit would be spread over two files which do not agree, and the next build would install the old
|
|
156
|
+
versions again.
|
|
157
|
+
|
|
158
|
+
The lock-file is only written when the update really changed a version, because writing it means installing
|
|
159
|
+
the dependencies again, which is the most expensive part of an update-run."""
|
|
160
|
+
dependencies_before_the_update:dict[str,set[str]]=self.get_dependencies()
|
|
161
|
+
super().update_dependencies_with_specific_echolon(echolon)
|
|
162
|
+
if dependencies_before_the_update!=self.get_dependencies():
|
|
163
|
+
#The cache must not be used here: the whole point of this install is to resolve the dependencies again.
|
|
164
|
+
self.tfcps_Tools_General.do_npm_install(self.get_codeunit_folder(),True,False)
|
|
165
|
+
|
|
166
|
+
|
|
140
167
|
@GeneralUtilities.check_arguments
|
|
141
168
|
def add_culture_chooser(self,site_title:str,supported_cultures:list[str])->None:
|
|
142
169
|
output_folder=self.get_codeunit_folder()+"/Other/Artifacts/BuildResult_WebApplication/browser"
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import re
|
|
3
|
+
import requests
|
|
4
|
+
from ..GeneralUtilities import GeneralUtilities, Dependency
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class NpmDependencies:
|
|
8
|
+
"""Reads and writes the dependencies which a npm-package-file ("package.json") declares and asks the
|
|
9
|
+
npm-registry which versions of such a dependency exist.
|
|
10
|
+
|
|
11
|
+
This is implemented here and not inside one of the codeunit-type-specific classes because a nodejs-codeunit and
|
|
12
|
+
a typescript-codeunit declare their dependencies in exactly the same file-format and resolve them from exactly
|
|
13
|
+
the same registry. Only the location of the package-file differs between them, which is why every operation
|
|
14
|
+
takes that file as its argument."""
|
|
15
|
+
|
|
16
|
+
__dependency_sections: tuple = ("dependencies", "devDependencies")
|
|
17
|
+
__version_regex: str = r"^\d+\.\d+\.\d+$"
|
|
18
|
+
__range_prefixes: tuple = ("^", "~")
|
|
19
|
+
|
|
20
|
+
@staticmethod
|
|
21
|
+
@GeneralUtilities.check_arguments
|
|
22
|
+
def get_dependencies(package_json_file: str) -> list[Dependency]:
|
|
23
|
+
"""Returns the updatable dependencies which the given package-file declares."""
|
|
24
|
+
content: dict = NpmDependencies.__read_package_file(package_json_file)
|
|
25
|
+
return [Dependency(name, version) for name, version in NpmDependencies.get_dependency_entries(content)]
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
@GeneralUtilities.check_arguments
|
|
29
|
+
def get_dependency_entries(package_json_content: dict) -> list[tuple[str, str]]:
|
|
30
|
+
"""Returns the updatable dependencies of the given package-file-content as tuples of their name and their
|
|
31
|
+
version.
|
|
32
|
+
|
|
33
|
+
Only a dependency whose version is a plain version-number is returned, because a dependency which points to
|
|
34
|
+
a file, a repository or a tag has no version on the registry which could be updated, and a dependency which
|
|
35
|
+
declares a version-range has no single version which an update could raise."""
|
|
36
|
+
result: list[tuple[str, str]] = []
|
|
37
|
+
for section in NpmDependencies.__dependency_sections:
|
|
38
|
+
for name, declared_version in package_json_content.get(section, {}).items():
|
|
39
|
+
# A declared version usually carries a range-prefix ("^1.2.3" or "~1.2.3"), which is not part of
|
|
40
|
+
# the version itself.
|
|
41
|
+
version_without_prefix: str = NpmDependencies.__remove_range_prefix(declared_version)
|
|
42
|
+
if re.match(NpmDependencies.__version_regex, version_without_prefix) is not None:
|
|
43
|
+
result.append((name, version_without_prefix))
|
|
44
|
+
return result
|
|
45
|
+
|
|
46
|
+
@staticmethod
|
|
47
|
+
@GeneralUtilities.check_arguments
|
|
48
|
+
def get_available_versions(dependencyname: str) -> list[str]:
|
|
49
|
+
"""Returns every published version of the given package which is a plain version-number.
|
|
50
|
+
|
|
51
|
+
A pre-release carries a suffix ("1.2.3-beta.1") and is deliberately not returned: an update which runs
|
|
52
|
+
unattended must not move a codeunit onto a version which its publisher did not release as a regular one."""
|
|
53
|
+
# The registry of npm answers with all published versions of a package. The abbreviated metadata-format is
|
|
54
|
+
# requested because the full document additionally contains the readme of every single version, which is a
|
|
55
|
+
# multiple of the amount of data which is needed here.
|
|
56
|
+
response = requests.get(f"https://registry.npmjs.org/{dependencyname}", headers={"Accept": "application/vnd.npm.install-v1+json"}, timeout=60)
|
|
57
|
+
response.raise_for_status()
|
|
58
|
+
result: list[str] = []
|
|
59
|
+
for version_string in response.json().get("versions", {}).keys():
|
|
60
|
+
if re.match(NpmDependencies.__version_regex, version_string) is not None:
|
|
61
|
+
result.append(version_string)
|
|
62
|
+
return result
|
|
63
|
+
|
|
64
|
+
@staticmethod
|
|
65
|
+
@GeneralUtilities.check_arguments
|
|
66
|
+
def set_dependency_version(package_json_file: str, name: str, new_version: str) -> bool:
|
|
67
|
+
"""Sets the version of the dependency [name] in the given package-file and returns whether that package-file
|
|
68
|
+
declares a dependency with that name at all."""
|
|
69
|
+
content: dict = NpmDependencies.__read_package_file(package_json_file)
|
|
70
|
+
if not NpmDependencies.declares_dependency(content, name):
|
|
71
|
+
return False
|
|
72
|
+
new_content: dict = NpmDependencies.set_dependency_version_in_content(content, name, new_version)
|
|
73
|
+
GeneralUtilities.write_text_to_file(package_json_file, json.dumps(new_content, indent=2, ensure_ascii=False)+"\n")
|
|
74
|
+
return True
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
@GeneralUtilities.check_arguments
|
|
78
|
+
def declares_dependency(package_json_content: dict, name: str) -> bool:
|
|
79
|
+
"""Returns whether the given package-file-content declares a dependency which is named [name]."""
|
|
80
|
+
for section in NpmDependencies.__dependency_sections:
|
|
81
|
+
if name in package_json_content.get(section, {}):
|
|
82
|
+
return True
|
|
83
|
+
return False
|
|
84
|
+
|
|
85
|
+
@staticmethod
|
|
86
|
+
@GeneralUtilities.check_arguments
|
|
87
|
+
def set_dependency_version_in_content(package_json_content: dict, name: str, new_version: str) -> dict:
|
|
88
|
+
"""Returns the given package-file-content with the version of the dependency [name] set to [new_version].
|
|
89
|
+
The content is returned unchanged when it does not declare a dependency with that name."""
|
|
90
|
+
for section in NpmDependencies.__dependency_sections:
|
|
91
|
+
if name in package_json_content.get(section, {}):
|
|
92
|
+
# The range-prefix of the former declaration is kept, because it states how the project wants to
|
|
93
|
+
# accept updates and that is not a decision of this function.
|
|
94
|
+
former_declaration: str = package_json_content[section][name]
|
|
95
|
+
prefix: str = former_declaration[0] if former_declaration[0] in NpmDependencies.__range_prefixes else GeneralUtilities.empty_string
|
|
96
|
+
package_json_content[section][name] = f"{prefix}{new_version}"
|
|
97
|
+
return package_json_content
|
|
98
|
+
|
|
99
|
+
@staticmethod
|
|
100
|
+
@GeneralUtilities.check_arguments
|
|
101
|
+
def __remove_range_prefix(declared_version: str) -> str:
|
|
102
|
+
if declared_version.startswith(NpmDependencies.__range_prefixes):
|
|
103
|
+
return declared_version[1:]
|
|
104
|
+
return declared_version
|
|
105
|
+
|
|
106
|
+
@staticmethod
|
|
107
|
+
@GeneralUtilities.check_arguments
|
|
108
|
+
def __read_package_file(package_json_file: str) -> dict:
|
|
109
|
+
return json.loads(GeneralUtilities.read_text_from_file(package_json_file))
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import requests
|
|
3
|
+
from ..GeneralUtilities import GeneralUtilities, Dependency
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class PubDependencies:
|
|
7
|
+
"""Reads and writes the dependencies which a pub-package-file ("pubspec.yaml") declares and asks pub.dev which
|
|
8
|
+
versions of such a dependency exist.
|
|
9
|
+
|
|
10
|
+
This is implemented here and not inside one of the codeunit-type-specific classes because a flutter-codeunit and
|
|
11
|
+
a dart-codeunit declare their dependencies in exactly the same file-format and resolve them from exactly the
|
|
12
|
+
same package-source. Only the location of the package-file differs between them, which is why every operation
|
|
13
|
+
takes that file as its argument.
|
|
14
|
+
|
|
15
|
+
The package-file is processed line by line and not by loading and dumping it as yaml: writing it back as yaml
|
|
16
|
+
would drop its comments and normalize its whole formatting, while a pubspec.yaml is a file which is maintained
|
|
17
|
+
by hand and in which an update of one version must not rewrite anything else."""
|
|
18
|
+
|
|
19
|
+
__dependency_sections: tuple = ("dependencies", "dev_dependencies", "dependency_overrides")
|
|
20
|
+
__version_regex: str = r"^\d+\.\d+\.\d+$"
|
|
21
|
+
__version_constraint_regex: str = r"^(\^?)(\d+\.\d+\.\d+)$"
|
|
22
|
+
|
|
23
|
+
@staticmethod
|
|
24
|
+
@GeneralUtilities.check_arguments
|
|
25
|
+
def get_dependencies(pubspec_file: str) -> list[Dependency]:
|
|
26
|
+
"""Returns the updatable dependencies which the given package-file declares."""
|
|
27
|
+
content: str = GeneralUtilities.read_text_from_file(pubspec_file)
|
|
28
|
+
return [Dependency(name, version) for name, version in PubDependencies.get_dependency_entries(content)]
|
|
29
|
+
|
|
30
|
+
@staticmethod
|
|
31
|
+
@GeneralUtilities.check_arguments
|
|
32
|
+
def get_dependency_entries(pubspec_content: str) -> list[tuple[str, str]]:
|
|
33
|
+
"""Returns the updatable dependencies of the given package-file-content as tuples of their name and their
|
|
34
|
+
version.
|
|
35
|
+
|
|
36
|
+
Only a dependency which declares a plain version-constraint is returned: a dependency which is declared as a
|
|
37
|
+
block (a sdk-, a path- or a git-dependency, for example) is not resolved from pub.dev at all, and a
|
|
38
|
+
dependency which declares a version-range has no single version which an update could raise."""
|
|
39
|
+
result: list[tuple[str, str]] = []
|
|
40
|
+
for _, _, name, version_constraint in PubDependencies.__enumerate_entries(PubDependencies.__content_to_lines(pubspec_content)):
|
|
41
|
+
constraint_match = re.match(PubDependencies.__version_constraint_regex, version_constraint)
|
|
42
|
+
if constraint_match is not None:
|
|
43
|
+
# A declared constraint usually carries the caret-prefix ("^1.2.3"), which is not part of the
|
|
44
|
+
# version itself.
|
|
45
|
+
result.append((name, constraint_match.group(2)))
|
|
46
|
+
return result
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
@GeneralUtilities.check_arguments
|
|
50
|
+
def get_available_versions(dependencyname: str) -> list[str]:
|
|
51
|
+
"""Returns every published version of the given package which is a plain version-number.
|
|
52
|
+
|
|
53
|
+
A retracted version is skipped, because its publisher declared it as a version which must not be used
|
|
54
|
+
anymore. A pre-release carries a suffix ("1.2.3-beta.1") and is deliberately not returned either: an update
|
|
55
|
+
which runs unattended must not move a codeunit onto a version which its publisher did not release as a
|
|
56
|
+
regular one."""
|
|
57
|
+
# The api of pub.dev answers with all published versions of a package.
|
|
58
|
+
response = requests.get(f"https://pub.dev/api/packages/{dependencyname}", headers={"Accept": "application/vnd.pub.v2+json"}, timeout=60)
|
|
59
|
+
response.raise_for_status()
|
|
60
|
+
result: list[str] = []
|
|
61
|
+
for published_version in response.json()["versions"]:
|
|
62
|
+
if published_version.get("retracted", False):
|
|
63
|
+
continue
|
|
64
|
+
version_string: str = str(published_version["version"])
|
|
65
|
+
if re.match(PubDependencies.__version_regex, version_string) is not None:
|
|
66
|
+
result.append(version_string)
|
|
67
|
+
return result
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
@GeneralUtilities.check_arguments
|
|
71
|
+
def set_dependency_version(pubspec_file: str, name: str, new_version: str) -> bool:
|
|
72
|
+
"""Sets the version of the dependency [name] in the given package-file and returns whether that package-file
|
|
73
|
+
declares a dependency with that name at all."""
|
|
74
|
+
lines: list[str] = GeneralUtilities.read_lines_from_file(pubspec_file)
|
|
75
|
+
if not PubDependencies.declares_dependency(lines, name):
|
|
76
|
+
return False
|
|
77
|
+
GeneralUtilities.write_lines_to_file(pubspec_file, PubDependencies.set_dependency_version_in_lines(lines, name, new_version))
|
|
78
|
+
return True
|
|
79
|
+
|
|
80
|
+
@staticmethod
|
|
81
|
+
@GeneralUtilities.check_arguments
|
|
82
|
+
def declares_dependency(pubspec_lines: list[str], name: str) -> bool:
|
|
83
|
+
"""Returns whether the given lines of a package-file declare a dependency which is named [name]."""
|
|
84
|
+
for _, _, entry_name, _ in PubDependencies.__enumerate_entries(pubspec_lines):
|
|
85
|
+
if entry_name == name:
|
|
86
|
+
return True
|
|
87
|
+
return False
|
|
88
|
+
|
|
89
|
+
@staticmethod
|
|
90
|
+
@GeneralUtilities.check_arguments
|
|
91
|
+
def set_dependency_version_in_lines(pubspec_lines: list[str], name: str, new_version: str) -> list[str]:
|
|
92
|
+
"""Returns the given lines of a package-file with the version of the dependency [name] set to [new_version].
|
|
93
|
+
|
|
94
|
+
Only the version itself is replaced, so the indentation, the constraint-prefix and a comment of the line
|
|
95
|
+
stay as they are. A dependency which does not declare a plain version-constraint is not touched, for the
|
|
96
|
+
same reason for which get_dependency_entries does not return it."""
|
|
97
|
+
result: list[str] = list(pubspec_lines)
|
|
98
|
+
for index, _, entry_name, version_constraint in PubDependencies.__enumerate_entries(pubspec_lines):
|
|
99
|
+
if entry_name != name:
|
|
100
|
+
continue
|
|
101
|
+
constraint_match = re.match(PubDependencies.__version_constraint_regex, version_constraint)
|
|
102
|
+
if constraint_match is None:
|
|
103
|
+
continue
|
|
104
|
+
former_constraint: str = constraint_match.group(0)
|
|
105
|
+
new_constraint: str = f"{constraint_match.group(1)}{new_version}"
|
|
106
|
+
# The line is split into what stands in front of the constraint, the constraint itself and what stands
|
|
107
|
+
# behind it (a comment), so that only the constraint is exchanged and the rest of the line is kept.
|
|
108
|
+
line_match = re.match(r"^(\s*"+re.escape(entry_name)+r":\s*)"+re.escape(former_constraint)+r"(.*)$", result[index])
|
|
109
|
+
GeneralUtilities.assert_condition(line_match is not None, f"The line \"{result[index]}\" does not declare the dependency \"{entry_name}\" in the way it was read from it.")
|
|
110
|
+
result[index] = f"{line_match.group(1)}{new_constraint}{line_match.group(2)}"
|
|
111
|
+
return result
|
|
112
|
+
|
|
113
|
+
@staticmethod
|
|
114
|
+
@GeneralUtilities.check_arguments
|
|
115
|
+
def __enumerate_entries(pubspec_lines: list[str]) -> list[tuple[int, str, str, str]]:
|
|
116
|
+
"""Returns every dependency which the given lines of a package-file declare, as tuples of the index of the
|
|
117
|
+
line which declares it, the section it is declared in, its name and the value it is declared with."""
|
|
118
|
+
current_section: str = None
|
|
119
|
+
entry_indentation: int = None
|
|
120
|
+
result: list[tuple[int, str, str, str]] = []
|
|
121
|
+
for index, line in enumerate(pubspec_lines):
|
|
122
|
+
line_without_comment: str = PubDependencies.__remove_comment(line)
|
|
123
|
+
if not GeneralUtilities.string_has_content(line_without_comment):
|
|
124
|
+
continue
|
|
125
|
+
if not line_without_comment.startswith(" "):
|
|
126
|
+
# A line without indentation declares a new top-level key, so the section which was processed until
|
|
127
|
+
# here has ended. Only a key without a value of its own opens a section which can contain
|
|
128
|
+
# dependencies.
|
|
129
|
+
section_match = re.match(r"^([A-Za-z0-9_]+):$", line_without_comment)
|
|
130
|
+
current_section = section_match.group(1) if section_match is not None else None
|
|
131
|
+
entry_indentation = None
|
|
132
|
+
continue
|
|
133
|
+
if current_section not in PubDependencies.__dependency_sections:
|
|
134
|
+
continue
|
|
135
|
+
indentation: int = len(line_without_comment)-len(line_without_comment.lstrip(" "))
|
|
136
|
+
if entry_indentation is None:
|
|
137
|
+
# The first indented line of a section states on which indentation the dependencies of that section
|
|
138
|
+
# are declared. Everything which is indented deeper belongs to the declaration of one of them (the
|
|
139
|
+
# "sdk"-key of a sdk-dependency or the "version"-key of a hosted dependency, for example) and is not
|
|
140
|
+
# a dependency of its own.
|
|
141
|
+
entry_indentation = indentation
|
|
142
|
+
if indentation != entry_indentation:
|
|
143
|
+
continue
|
|
144
|
+
entry_match = re.match(r"^\s+([A-Za-z0-9_]+):\s*(\S.*)$", line_without_comment)
|
|
145
|
+
if entry_match is not None:
|
|
146
|
+
result.append((index, current_section, entry_match.group(1), entry_match.group(2)))
|
|
147
|
+
return result
|
|
148
|
+
|
|
149
|
+
@staticmethod
|
|
150
|
+
@GeneralUtilities.check_arguments
|
|
151
|
+
def __remove_comment(line: str) -> str:
|
|
152
|
+
"""Returns the given line without its comment and without its trailing whitespace. In yaml a "#" starts a
|
|
153
|
+
comment when it stands at the beginning of a line or when a whitespace stands in front of it."""
|
|
154
|
+
comment_match = re.search(r"(^|\s)#", line)
|
|
155
|
+
if comment_match is None:
|
|
156
|
+
return line.rstrip()
|
|
157
|
+
return line[:comment_match.start()].rstrip()
|
|
158
|
+
|
|
159
|
+
@staticmethod
|
|
160
|
+
@GeneralUtilities.check_arguments
|
|
161
|
+
def __content_to_lines(pubspec_content: str) -> list[str]:
|
|
162
|
+
# The lines are taken as they are, because the indentation of a line is what states whether it declares a
|
|
163
|
+
# dependency or a detail of one.
|
|
164
|
+
return GeneralUtilities.string_to_lines(pubspec_content, True, False)
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
|
-
import re
|
|
3
|
-
import json
|
|
4
2
|
import shutil
|
|
5
|
-
import requests
|
|
6
3
|
from lxml import etree
|
|
7
|
-
from ...GeneralUtilities import GeneralUtilities
|
|
4
|
+
from ...GeneralUtilities import GeneralUtilities
|
|
8
5
|
from ...SCLog import LogLevel
|
|
6
|
+
from ..NpmDependencies import NpmDependencies
|
|
9
7
|
from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base, TFCPS_CodeUnitSpecific_Base_CLI
|
|
10
8
|
|
|
11
9
|
class TFCPS_CodeUnitSpecific_TypeScript_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
@@ -123,57 +121,16 @@ class TFCPS_CodeUnitSpecific_TypeScript_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
123
121
|
|
|
124
122
|
@GeneralUtilities.check_arguments
|
|
125
123
|
def get_dependencies(self) -> dict[str, set[str]]:
|
|
126
|
-
return GeneralUtilities.merge_dependency_lists([self.
|
|
127
|
-
|
|
128
|
-
@GeneralUtilities.check_arguments
|
|
129
|
-
def __get_dependencies_from_package_json_file(self) -> list[Dependency]:
|
|
130
|
-
result: list[Dependency] = []
|
|
131
|
-
for name, dependency_version in self.__enumerate_dependency_entries():
|
|
132
|
-
result.append(Dependency(name, dependency_version))
|
|
133
|
-
return result
|
|
134
|
-
|
|
135
|
-
@GeneralUtilities.check_arguments
|
|
136
|
-
def __enumerate_dependency_entries(self) -> list[tuple[str, str]]:
|
|
137
|
-
"""Returns the dependencies of the package-file as tuples of their name and their version. Only a
|
|
138
|
-
dependency whose version is a plain version-number is returned, because a dependency which points to a
|
|
139
|
-
file, a repository or a tag has no version which could be updated."""
|
|
140
|
-
content = json.loads(GeneralUtilities.read_text_from_file(self.get_package_json_file()))
|
|
141
|
-
result: list[tuple[str, str]] = []
|
|
142
|
-
for section in ("dependencies", "devDependencies"):
|
|
143
|
-
for name, declared_version in content.get(section, {}).items():
|
|
144
|
-
# A declared version usually carries a range-prefix ("^1.2.3" or "~1.2.3"), which is not part of
|
|
145
|
-
# the version itself.
|
|
146
|
-
version_without_prefix = declared_version.lstrip("^~")
|
|
147
|
-
if re.match(r"^\d+\.\d+\.\d+$", version_without_prefix) is not None:
|
|
148
|
-
result.append((name, version_without_prefix))
|
|
149
|
-
return result
|
|
124
|
+
return GeneralUtilities.merge_dependency_lists([NpmDependencies.get_dependencies(self.get_package_json_file())])
|
|
150
125
|
|
|
151
126
|
@GeneralUtilities.check_arguments
|
|
152
127
|
def get_available_versions(self, dependencyname: str) -> list[str]:
|
|
153
|
-
|
|
154
|
-
response = requests.get(f"https://registry.npmjs.org/{dependencyname}", headers={"Accept": "application/vnd.npm.install-v1+json"}, timeout=60)
|
|
155
|
-
response.raise_for_status()
|
|
156
|
-
result: list[str] = []
|
|
157
|
-
for version_string in response.json().get("versions", {}).keys():
|
|
158
|
-
if re.match(r"^\d+\.\d+\.\d+$", version_string) is not None:
|
|
159
|
-
result.append(version_string)
|
|
160
|
-
return result
|
|
128
|
+
return NpmDependencies.get_available_versions(dependencyname)
|
|
161
129
|
|
|
162
130
|
@GeneralUtilities.check_arguments
|
|
163
131
|
def set_dependency_version(self, name: str, new_version: str) -> None:
|
|
164
132
|
package_json_file = self.get_package_json_file()
|
|
165
|
-
|
|
166
|
-
dependency_was_set: bool = False
|
|
167
|
-
for section in ("dependencies", "devDependencies"):
|
|
168
|
-
if name in content.get(section, {}):
|
|
169
|
-
# The range-prefix of the former declaration is kept, because it states how the project wants to
|
|
170
|
-
# accept updates and that is not a decision of this function.
|
|
171
|
-
former_declaration = content[section][name]
|
|
172
|
-
prefix = former_declaration[0] if former_declaration[0] in ("^", "~") else GeneralUtilities.empty_string
|
|
173
|
-
content[section][name] = f"{prefix}{new_version}"
|
|
174
|
-
dependency_was_set = True
|
|
175
|
-
GeneralUtilities.assert_condition(dependency_was_set, f'The package-file "{package_json_file}" does not contain a dependency which is named "{name}".')
|
|
176
|
-
GeneralUtilities.write_text_to_file(package_json_file, json.dumps(content, indent=2, ensure_ascii=False) + "\n")
|
|
133
|
+
GeneralUtilities.assert_condition(NpmDependencies.set_dependency_version(package_json_file, name, new_version), f'The package-file "{package_json_file}" does not contain a dependency which is named "{name}".')
|
|
177
134
|
self._protected_sc.format_json_file(package_json_file)
|
|
178
135
|
|
|
179
136
|
class TFCPS_CodeUnitSpecific_TypeScript_CLI:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scriptcollection
|
|
3
|
-
Version: 4.4.
|
|
3
|
+
Version: 4.4.35
|
|
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
|
|
@@ -2,7 +2,7 @@ ScriptCollection/AnionBuildPlatform.py,sha256=LF9b4f4iqgsjgXZjS0RHiEBw73tQANfu0O
|
|
|
2
2
|
ScriptCollection/ArbTranslationsOrganizer.py,sha256=FLJcNP6qFTQOkxL7es0Sq3O7kb_TgoRreqH-uogR4xA,12201
|
|
3
3
|
ScriptCollection/CertificateUpdater.py,sha256=bD0VhKQsD2cNRTG1kzMkhgpd0BZw7igbG30goKw5p1A,9749
|
|
4
4
|
ScriptCollection/Executables.py,sha256=Ovq6LVhtP6mqCPmBxch9WgTmePBk7F8MLyZUBkQloAE,74171
|
|
5
|
-
ScriptCollection/GeneralUtilities.py,sha256=
|
|
5
|
+
ScriptCollection/GeneralUtilities.py,sha256=JO95CNaNjH_ooZ0db56kwRjRDgT_-RdWAvClItlnQBM,72045
|
|
6
6
|
ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
|
|
7
7
|
ScriptCollection/ProcessesRunner.py,sha256=Va9O-ohWoRfe4pO2gPBzc940gkM5BpP4Txcu1CmLOvg,1494
|
|
8
8
|
ScriptCollection/ProgramRunnerBase.py,sha256=eZenpiIFW1dhvSVCG7cfBs5hO4_KLlOxR7oXoSxUDmk,2286
|
|
@@ -12,7 +12,7 @@ ScriptCollection/ProgramRunnerSudo.py,sha256=ot9Ib-plQ8wejR9M2XXfnx6GR-va9k8SH1g
|
|
|
12
12
|
ScriptCollection/RepositoryDiagramGenerator.py,sha256=K_u2NW_p4ozdWD50irJEkkcDVa70TcUJpZN63TeXSLw,7092
|
|
13
13
|
ScriptCollection/RepositoryHistoryAnalyzer.py,sha256=rD8eC5lMUe5MHmCBHfYft_G-N9IbvtsFGkU7EMwPjrY,5779
|
|
14
14
|
ScriptCollection/SCLog.py,sha256=Fjf8Pdi63cXHGMxL_aI6A0dwGm7QIfrv3czjvpSUlaM,4705
|
|
15
|
-
ScriptCollection/ScriptCollectionCore.py,sha256=
|
|
15
|
+
ScriptCollection/ScriptCollectionCore.py,sha256=X5dxmzYQQVWo-dbvLMbiODnmSkrc3_Ypeekfp4_3Zc8,300265
|
|
16
16
|
ScriptCollection/TestKind.py,sha256=jqLJwNvQeyea7SZf-UFzMC9pM0znv4do7FIC1xq8u9M,1672
|
|
17
17
|
ScriptCollection/UnassignedVariablesCheck.py,sha256=8xNcp1D5HeOLO1a1NEerq2TsnpFhw7yzYPkaay-oisY,3804
|
|
18
18
|
ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -31,8 +31,10 @@ ScriptCollection/Resources/CultureChooser/index.html,sha256=gxQzbrSp4WU52TqN-gcB
|
|
|
31
31
|
ScriptCollection/Resources/Dependencies/JRE/Version.txt,sha256=WlFzNJMH4lfVzW5QGHnuE52jLujSGpQ48zVB-Cln-7g,9
|
|
32
32
|
ScriptCollection/Resources/Dependencies/OpenAPIGenerator/Version.txt,sha256=hdAgOhOHx4s13fJ-j0A06oYoM9rdEfDe0RzHoeAKXxo,7
|
|
33
33
|
ScriptCollection/Resources/MaintenanceSite/MaintenanceSite.html,sha256=CX9S1bdOz6xU2aGfr03tJRGczQrlpn-IeODc15d5kc0,232
|
|
34
|
+
ScriptCollection/TFCPS/NpmDependencies.py,sha256=IfUh9EyrkHxovGRWYagNMZjBUXyKjZ4AG-Z8leehw24,6304
|
|
34
35
|
ScriptCollection/TFCPS/PackageSource.py,sha256=tQoMbxrIbV3mYHKH2wgOoGzIHY1TvBH8EAFpWGhryrQ,1311
|
|
35
36
|
ScriptCollection/TFCPS/PlantUMLRenderer.py,sha256=upnafiGKV-SdRI8iRBkbbWHN2u6v9KxoswdKi12AwoY,11060
|
|
37
|
+
ScriptCollection/TFCPS/PubDependencies.py,sha256=hl6BfYjzb0-esO-pqyV_sxBLbHBi55GEgUiub3lma_8,9922
|
|
36
38
|
ScriptCollection/TFCPS/SCTaskRunnerServer.py,sha256=tub8_1QBu0nWAaGnBWp2nErOW-SOHf_UL6qjOSGbnxU,31026
|
|
37
39
|
ScriptCollection/TFCPS/TFCPS_BuildCodeUnitsHook.py,sha256=67_DQwoH5bhxxSmwtuAeoW1NOCMiLMzOy48OqlJX-KY,1744
|
|
38
40
|
ScriptCollection/TFCPS/TFCPS_CodeUnitSpecific_Base.py,sha256=umUfQDErp7xFLkDnSbQMxzUWnKtcGlrZnIvFcTpfGJs,40499
|
|
@@ -57,22 +59,22 @@ ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationGenerate.py,sha256=
|
|
|
57
59
|
ScriptCollection/TFCPS/DotNet/CertificateGeneratorInformationNoGenerate.py,sha256=i0zEGehj0sttxjjZtoq2KFSKp_ulxVyWp_ZgAhIY_So,241
|
|
58
60
|
ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py,sha256=GCFzDNAnmm40EeqOYgD_EeuEwDY58ujwJ1-Zn_naamc,61797
|
|
59
61
|
ScriptCollection/TFCPS/DotNet/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
60
|
-
ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py,sha256=
|
|
62
|
+
ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py,sha256=Gj4Akt0t_7e0dmT5qCSzz-o1TCuzPP_AtuG4gW6Vv3Q,55812
|
|
61
63
|
ScriptCollection/TFCPS/Flutter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
62
64
|
ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py,sha256=m4Pax-U6o5XuspLnLfnWjyQMtoC7zBDDNJW9EhLWjeE,9012
|
|
63
65
|
ScriptCollection/TFCPS/Go/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
64
66
|
ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py,sha256=HDZlU70lF4nxUgsi7-TaFrFpbw_imw6dBagfgL6tDW8,10593
|
|
65
67
|
ScriptCollection/TFCPS/Maven/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
66
|
-
ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=
|
|
68
|
+
ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py,sha256=U2J_jZxy9-tJdShx_bhDkASgDbkL0BsHGtDdEYFhb7o,16534
|
|
67
69
|
ScriptCollection/TFCPS/NodeJS/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
68
70
|
ScriptCollection/TFCPS/Python/TFCPS_CodeUnitSpecific_Python.py,sha256=Wi9anRljuvW1-UplYhI_QNR2szxaitHiXVJ6p4nUEI8,21089
|
|
69
71
|
ScriptCollection/TFCPS/Python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
70
72
|
ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=yyjWPMHQjPLkMLlfjrOjhEieFEW_PDm7RWbs4I1TWWY,12275
|
|
71
73
|
ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
72
|
-
ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=
|
|
74
|
+
ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=ILVhJHvwG5TvPBBqSvyACYb7W9QnWrJpxKgHu8IQu4g,9249
|
|
73
75
|
ScriptCollection/TFCPS/TypeScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
74
|
-
scriptcollection-4.4.
|
|
75
|
-
scriptcollection-4.4.
|
|
76
|
-
scriptcollection-4.4.
|
|
77
|
-
scriptcollection-4.4.
|
|
78
|
-
scriptcollection-4.4.
|
|
76
|
+
scriptcollection-4.4.35.dist-info/METADATA,sha256=d9CXU1ObLnRbzhZzs_T5koy9agJBD84T96yJpTA_GTc,7690
|
|
77
|
+
scriptcollection-4.4.35.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
78
|
+
scriptcollection-4.4.35.dist-info/entry_points.txt,sha256=GNma7tN0J59EvK71su-G1w22RnZ05bXcPrELyLx3AL0,6151
|
|
79
|
+
scriptcollection-4.4.35.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
|
|
80
|
+
scriptcollection-4.4.35.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|