ScriptCollection 4.4.2__py3-none-any.whl → 4.4.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ScriptCollection/Executables.py +1 -1
- ScriptCollection/GeneralUtilities.py +13 -1
- ScriptCollection/Resources/CultureChooser/CultureChooser.js +0 -0
- ScriptCollection/Resources/CultureChooser/index.html +0 -0
- ScriptCollection/Resources/Dependencies/JRE/Version.txt +0 -0
- ScriptCollection/Resources/Dependencies/OpenAPIGenerator/Version.txt +0 -0
- ScriptCollection/Resources/Dependencies/PlantUML/Version.txt +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans-Bold.ttf +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans-BoldOblique.ttf +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans-Oblique.ttf +0 -0
- ScriptCollection/Resources/Fonts/DejaVuSans.ttf +0 -0
- ScriptCollection/Resources/Fonts/LICENSE.txt +0 -0
- ScriptCollection/Resources/MaintenanceSite/MaintenanceSite.html +0 -0
- ScriptCollection/SCLog.py +1 -1
- ScriptCollection/ScriptCollectionCore.py +117 -11
- ScriptCollection/TFCPS/DotNet/TFCPS_CodeUnitSpecific_DotNet.py +1 -1
- ScriptCollection/TFCPS/Flutter/TFCPS_CodeUnitSpecific_Flutter.py +1 -1
- ScriptCollection/TFCPS/Go/TFCPS_CodeUnitSpecific_Go.py +128 -47
- ScriptCollection/TFCPS/Maven/TFCPS_CodeUnitSpecific_Maven.py +139 -7
- ScriptCollection/TFCPS/NodeJS/TFCPS_CodeUnitSpecific_NodeJS.py +8 -2
- ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py +169 -7
- ScriptCollection/TFCPS/TFCPS_CodeUnit_BuildCodeUnits.py +2 -2
- ScriptCollection/TFCPS/TFCPS_Tools_General.py +126 -9
- ScriptCollection/TFCPS/TFCPS_VisualRegressionTests.py +446 -0
- ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py +188 -0
- ScriptCollection/TFCPS/TypeScript/__init__.py +0 -0
- ScriptCollection/TestKind.py +41 -0
- {scriptcollection-4.4.2.dist-info → scriptcollection-4.4.4.dist-info}/METADATA +168 -168
- {scriptcollection-4.4.2.dist-info → scriptcollection-4.4.4.dist-info}/RECORD +21 -17
- {scriptcollection-4.4.2.dist-info → scriptcollection-4.4.4.dist-info}/WHEEL +0 -0
- {scriptcollection-4.4.2.dist-info → scriptcollection-4.4.4.dist-info}/entry_points.txt +0 -0
- {scriptcollection-4.4.2.dist-info → scriptcollection-4.4.4.dist-info}/top_level.txt +0 -0
ScriptCollection/Executables.py
CHANGED
|
@@ -575,7 +575,7 @@ def NormalizeLineEndings() -> int:
|
|
|
575
575
|
if not os.path.isfile(args.path):
|
|
576
576
|
GeneralUtilities.write_message_to_stderr(f"File '{args.path}' does not exist.")
|
|
577
577
|
return 1
|
|
578
|
-
ScriptCollectionCore().
|
|
578
|
+
ScriptCollectionCore().normalize_invisible_characters(args.path)
|
|
579
579
|
return 0
|
|
580
580
|
|
|
581
581
|
|
|
@@ -72,12 +72,24 @@ class GeneralUtilities:
|
|
|
72
72
|
@staticmethod
|
|
73
73
|
def check_arguments(function):
|
|
74
74
|
def __check_function(*args, **named_args):
|
|
75
|
-
|
|
75
|
+
# "signature" is used instead of "getfullargspec", because it follows the "__wrapped__"-chain which
|
|
76
|
+
# "functools.wraps" sets. Without that this decorator would only see the wrapper when it is applied
|
|
77
|
+
# above another decorator (for example above "deprecated"), and a wrapper has no named parameters,
|
|
78
|
+
# so no argument could be checked at all.
|
|
79
|
+
try:
|
|
80
|
+
parameters: list = list(inspect.signature(function).parameters)
|
|
81
|
+
except (ValueError, TypeError):
|
|
82
|
+
parameters: list = inspect.getfullargspec(function)[0].copy()
|
|
76
83
|
arguments: list = list(tuple(args)).copy()
|
|
77
84
|
if "self" in parameters:
|
|
78
85
|
parameters.remove("self")
|
|
79
86
|
arguments.pop(0)
|
|
80
87
|
for index, argument in enumerate(arguments):
|
|
88
|
+
if len(parameters) <= index:
|
|
89
|
+
# More arguments were passed than the function has parameters. That is a wrong call, but it
|
|
90
|
+
# is not this check which has to report it: the call of the function below raises the
|
|
91
|
+
# regular TypeError of python, whose message names the expected and the given amount.
|
|
92
|
+
break
|
|
81
93
|
if argument is not None: # Check type of None is not possible. None is always a valid argument-value
|
|
82
94
|
if parameters[index] in function.__annotations__: # Check if a type-hint for parameter exist. If not, no parameter-type available for argument-type-check
|
|
83
95
|
# Check type of arguments if the type is a generic type seems to be impossible.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
ScriptCollection/SCLog.py
CHANGED
|
@@ -39,7 +39,7 @@ from .ProgramRunnerBase import ProgramRunnerBase
|
|
|
39
39
|
from .ProgramRunnerPopen import ProgramRunnerPopen
|
|
40
40
|
from .SCLog import SCLog, LogLevel
|
|
41
41
|
|
|
42
|
-
version = "4.4.
|
|
42
|
+
version = "4.4.4"
|
|
43
43
|
__version__ = version
|
|
44
44
|
|
|
45
45
|
class VSCodeWorkspaceShellTask:
|
|
@@ -201,6 +201,8 @@ class ScriptCollectionCore:
|
|
|
201
201
|
log: SCLog = None
|
|
202
202
|
# Magic string which can be used inside the arguments of run_command_in_folder. Every occurrence of it will be replaced by the (resolved) actual_folder.
|
|
203
203
|
run_command_in_folder_actual_folder_placeholder: str = "{actual_folder}"
|
|
204
|
+
# The bytes with which a file starts when it was written with a utf8-byte-order-mark. See normalize_invisible_characters.
|
|
205
|
+
__utf8_byte_order_mark: bytes = b"\xef\xbb\xbf"
|
|
204
206
|
# Base-url of the GitHub-REST-API. This is an internal constant on purpose and deliberately not exposed as a parameter of the GitHub-functions.
|
|
205
207
|
__github_api_base_url: str = "https://api.github.com"
|
|
206
208
|
|
|
@@ -1634,6 +1636,101 @@ class ScriptCollectionCore:
|
|
|
1634
1636
|
for thumbnail_to_delete in preview_files:
|
|
1635
1637
|
os.remove(thumbnail_to_delete)
|
|
1636
1638
|
|
|
1639
|
+
@GeneralUtilities.check_arguments
|
|
1640
|
+
def start_rtsp_test_stream(self, target_address: str, additional_text: str = None, width: int = 640, height: int = 480, frames_per_second: int = 10, font_file: str = None, working_directory: str = None) -> int:
|
|
1641
|
+
"""Starts a video-stream which shows a number that is counted up once per second and publishes it to the
|
|
1642
|
+
given rtsp-address. Returns the process-id of the running ffmpeg, which can be passed to
|
|
1643
|
+
GeneralUtilities.kill_process to stop the stream again.
|
|
1644
|
+
|
|
1645
|
+
The purpose of this stream is to be a reproducible replacement for a real camera in testcases: the picture
|
|
1646
|
+
depends only on how long the stream is running, so a screenshot which is taken after 1.5 seconds always shows
|
|
1647
|
+
the same number as a screenshot which is taken after 1.5 seconds in another run.
|
|
1648
|
+
|
|
1649
|
+
The address has to point to a running rtsp-server (mediamtx, for example) which accepts the publishing of a
|
|
1650
|
+
stream; ffmpeg does not open a port by itself.
|
|
1651
|
+
|
|
1652
|
+
:param target_address: The rtsp-address to publish to, for example "rtsp://localhost:8554/teststream".
|
|
1653
|
+
:param additional_text: An optional text which is shown below the number. Useful to tell two streams apart.
|
|
1654
|
+
Only letters, digits and spaces are allowed: everything else would have to be escaped
|
|
1655
|
+
for the filter-syntax of ffmpeg, and a stream which only exists for testcases does not
|
|
1656
|
+
need a text which requires that.
|
|
1657
|
+
:param font_file: The font which is used. When it is not given then a font of the operating-system is used.
|
|
1658
|
+
"""
|
|
1659
|
+
GeneralUtilities.assert_condition(target_address.startswith("rtsp://"), f"'{target_address}' is not a rtsp-address.")
|
|
1660
|
+
argument: list[str] = self.__get_arguments_for_test_stream(additional_text, width, height, frames_per_second, font_file) + [
|
|
1661
|
+
"-f", "rtsp",
|
|
1662
|
+
# Tcp instead of udp, because udp loses pictures under load, which would make a screenshot show
|
|
1663
|
+
# something else than the number which belongs to the moment it was taken.
|
|
1664
|
+
"-rtsp_transport", "tcp",
|
|
1665
|
+
target_address]
|
|
1666
|
+
return self.run_program_argsasarray_async("ffmpeg", argument, working_directory, title=f"RTSP-test-stream ({target_address})")
|
|
1667
|
+
|
|
1668
|
+
@GeneralUtilities.check_arguments
|
|
1669
|
+
def create_test_stream_video(self, target_file: str, duration_in_seconds: int, additional_text: str = None, width: int = 640, height: int = 480, frames_per_second: int = 10, font_file: str = None, working_directory: str = None) -> None:
|
|
1670
|
+
"""Writes a video-file which shows the same picture as start_rtsp_test_stream, but into a file instead of
|
|
1671
|
+
to a rtsp-address and as fast as possible instead of in realtime.
|
|
1672
|
+
|
|
1673
|
+
This exists to be able to create the expected pictures of a testcase without recording a stream: the pictures
|
|
1674
|
+
are the same, so a picture of this file can be used as the baseline for a picture of a recorded stream.
|
|
1675
|
+
|
|
1676
|
+
:param target_file: The video-file which is written.
|
|
1677
|
+
:param duration_in_seconds: How long the video is. The number is counted up once per second, so a video of ten
|
|
1678
|
+
seconds contains the numbers 0 to 9.
|
|
1679
|
+
"""
|
|
1680
|
+
argument: list[str] = self.__get_arguments_for_test_stream(additional_text, width, height, frames_per_second, font_file, realtime=False) + [
|
|
1681
|
+
"-t", str(duration_in_seconds),
|
|
1682
|
+
"-y", target_file]
|
|
1683
|
+
self.run_program_argsasarray("ffmpeg", argument, working_directory, throw_exception_if_exitcode_is_not_zero=True)
|
|
1684
|
+
|
|
1685
|
+
@GeneralUtilities.check_arguments
|
|
1686
|
+
def __get_arguments_for_test_stream(self, additional_text: str, width: int, height: int, frames_per_second: int, font_file: str, realtime: bool = True) -> list[str]:
|
|
1687
|
+
"""Returns the ffmpeg-arguments which produce the picture of a test-stream. The picture is defined here
|
|
1688
|
+
only once, so that the video which is used as the expected result really shows the same as the stream."""
|
|
1689
|
+
if additional_text is not None:
|
|
1690
|
+
GeneralUtilities.assert_condition(re.fullmatch("[a-zA-Z0-9 ]+", additional_text) is not None, f"The additional text must consist of letters, digits and spaces only, but it is '{additional_text}'.")
|
|
1691
|
+
if font_file is None:
|
|
1692
|
+
font_file = self.__get_font_file_for_drawing_text()
|
|
1693
|
+
# "%{eif:t:d}" is the amount of seconds the stream is running, rounded down to an integer, so the number
|
|
1694
|
+
# changes exactly once per second. The colons of it have to be escaped, because the filter-syntax of
|
|
1695
|
+
# ffmpeg uses the colon as the separator between two options.
|
|
1696
|
+
escaped_font_file = font_file.replace("\\", "/").replace(":", "\\:")
|
|
1697
|
+
text_filters: list[str] = [f"drawtext=fontfile='{escaped_font_file}':text='%{{eif\\:t\\:d}}':fontsize={int(height/4)}:fontcolor=white:x=(w-text_w)/2:y=(h-text_h)/2"]
|
|
1698
|
+
if additional_text is not None:
|
|
1699
|
+
text_filters.append(f"drawtext=fontfile='{escaped_font_file}':text='{additional_text}':fontsize={int(height/12)}:fontcolor=white:x=(w-text_w)/2:y=h*3/4")
|
|
1700
|
+
result: list[str] = []
|
|
1701
|
+
if realtime:
|
|
1702
|
+
# "-re" makes ffmpeg send the pictures in realtime instead of as fast as it can, which is what a
|
|
1703
|
+
# camera does and what makes the number correspond to the elapsed time.
|
|
1704
|
+
result.append("-re")
|
|
1705
|
+
result = result + [
|
|
1706
|
+
"-f", "lavfi",
|
|
1707
|
+
"-i", f"color=c=black:s={width}x{height}:r={frames_per_second}",
|
|
1708
|
+
"-vf", ",".join(text_filters),
|
|
1709
|
+
"-c:v", "libx264",
|
|
1710
|
+
"-preset", "ultrafast",
|
|
1711
|
+
"-tune", "zerolatency",
|
|
1712
|
+
# Without this the stream is not playable by every client, because they expect a chroma-subsampling
|
|
1713
|
+
# which the default of libx264 does not use for this input.
|
|
1714
|
+
"-pix_fmt", "yuv420p",
|
|
1715
|
+
# One keyframe per second, so a client which connects in between shows a picture immediately.
|
|
1716
|
+
"-g", str(frames_per_second)]
|
|
1717
|
+
return result
|
|
1718
|
+
|
|
1719
|
+
@GeneralUtilities.check_arguments
|
|
1720
|
+
def __get_font_file_for_drawing_text(self) -> str:
|
|
1721
|
+
"""Returns a font-file of the operating-system. A font-file is used instead of a font-name because
|
|
1722
|
+
resolving a name requires fontconfig, which does not exist on every system ffmpeg runs on."""
|
|
1723
|
+
candidates: list[str] = [
|
|
1724
|
+
"C:/Windows/Fonts/arial.ttf",
|
|
1725
|
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
|
1726
|
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
|
1727
|
+
"/usr/share/fonts/TTF/DejaVuSans.ttf",
|
|
1728
|
+
"/System/Library/Fonts/Supplemental/Arial.ttf"]
|
|
1729
|
+
for candidate in candidates:
|
|
1730
|
+
if os.path.isfile(candidate):
|
|
1731
|
+
return candidate
|
|
1732
|
+
raise ValueError(f"No font-file was found. Pass one explicitly. Checked: {', '.join(candidates)}")
|
|
1733
|
+
|
|
1637
1734
|
@GeneralUtilities.check_arguments
|
|
1638
1735
|
def extract_pdf_pages(self, file: str, from_page: int, to_page: int, outputfile: str) -> None:
|
|
1639
1736
|
pdf_reader: PdfReader = PdfReader(file)
|
|
@@ -2478,6 +2575,7 @@ class ScriptCollectionCore:
|
|
|
2478
2575
|
|
|
2479
2576
|
@GeneralUtilities.check_arguments
|
|
2480
2577
|
def run_with_epew(self, program: str, argument: str = "", working_directory: str = None, print_errors_as_information: bool = False, log_file: str = None, timeoutInSeconds: int = None, addLogOverhead: bool = False, title: str = None, log_namespace: str = "", arguments_for_log: str =None, throw_exception_if_exitcode_is_not_zero: bool = True, custom_argument: object = None, interactive: bool = False,print_live_output:bool=False,encode_argument_in_base64:bool=False) -> tuple[int, str, str, int]:
|
|
2578
|
+
GeneralUtilities.assert_condition(GeneralUtilities.epew_is_available(), "Epew is not available.")
|
|
2481
2579
|
epew_argument:list[str]=["-p",program ,"-w", working_directory]
|
|
2482
2580
|
if encode_argument_in_base64:
|
|
2483
2581
|
if arguments_for_log is None:
|
|
@@ -3144,7 +3242,7 @@ TXDX
|
|
|
3144
3242
|
content = json.loads(GeneralUtilities.read_text_from_file(file, encoding))
|
|
3145
3243
|
formatted_content = json.dumps(content, indent=indentation, sort_keys=False, ensure_ascii=False)
|
|
3146
3244
|
GeneralUtilities.write_text_to_file(file, formatted_content.rstrip("\n") + "\n", encoding)
|
|
3147
|
-
self.
|
|
3245
|
+
self.normalize_invisible_characters(file)
|
|
3148
3246
|
|
|
3149
3247
|
@GeneralUtilities.check_arguments
|
|
3150
3248
|
def format_xml_file(self, file: str,add_xml_declaration:bool=True) -> None:
|
|
@@ -3161,7 +3259,7 @@ TXDX
|
|
|
3161
3259
|
ET.indent(element)
|
|
3162
3260
|
content = self.__serialize_xml_element(element, add_xml_declaration)
|
|
3163
3261
|
GeneralUtilities.write_text_to_file(file, content.rstrip("\n") + "\n", encoding)
|
|
3164
|
-
self.
|
|
3262
|
+
self.normalize_invisible_characters(file)
|
|
3165
3263
|
|
|
3166
3264
|
@GeneralUtilities.check_arguments
|
|
3167
3265
|
def __serialize_xml_element(self, element: ET.Element, add_xml_declaration: bool) -> str:
|
|
@@ -3192,25 +3290,33 @@ TXDX
|
|
|
3192
3290
|
content = GeneralUtilities.read_text_from_file(file, encoding)
|
|
3193
3291
|
content=self.format_html_content(content, add_html_declaration)
|
|
3194
3292
|
GeneralUtilities.write_text_to_file(file, content, encoding)
|
|
3195
|
-
self.
|
|
3293
|
+
self.normalize_invisible_characters(file)
|
|
3196
3294
|
|
|
3197
3295
|
@GeneralUtilities.check_arguments
|
|
3198
|
-
def
|
|
3199
|
-
# Normalizes all physical line-endings of the given file to LF (replaces CRLF and lone CR by LF)
|
|
3200
|
-
#
|
|
3201
|
-
#
|
|
3296
|
+
def normalize_invisible_characters(self, file: str) -> None:
|
|
3297
|
+
# Normalizes all physical line-endings of the given file to LF (replaces CRLF and lone CR by LF) and removes
|
|
3298
|
+
# a utf8-byte-order-mark at the begin of the file.
|
|
3299
|
+
# Operates on the raw bytes so no character-encoding is assumed and only the line-ending-bytes and the
|
|
3300
|
+
# byte-order-mark are touched; the file is only rewritten when its content actually changes.
|
|
3202
3301
|
content = GeneralUtilities.read_binary_from_file(file)
|
|
3203
|
-
normalized_content = content
|
|
3302
|
+
normalized_content = content
|
|
3303
|
+
# Utf8 has no byte-order which could be marked, so the mark carries no information. But it is part of the
|
|
3304
|
+
# content of the file for everything which does not know it, which is why it breaks tools which expect the
|
|
3305
|
+
# file to start with its actual content (a shebang-line, an xml-declaration or the name of a column of a
|
|
3306
|
+
# csv-file, for example).
|
|
3307
|
+
if normalized_content.startswith(ScriptCollectionCore.__utf8_byte_order_mark):
|
|
3308
|
+
normalized_content = normalized_content[len(ScriptCollectionCore.__utf8_byte_order_mark):]
|
|
3309
|
+
normalized_content = normalized_content.replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
3204
3310
|
if normalized_content != content:
|
|
3205
3311
|
GeneralUtilities.write_binary_to_file(file, normalized_content)
|
|
3206
3312
|
|
|
3207
3313
|
@GeneralUtilities.check_arguments
|
|
3208
|
-
def
|
|
3314
|
+
def normalize_invisible_characters_of_files_in_folder(self, folder: str, file_extensions: list[str]) -> None:
|
|
3209
3315
|
"""Normalizes the line-endings of all not-git-ignored files inside 'folder' which have one of the given
|
|
3210
3316
|
file-extensions. The file-extensions must be given without a leading dot (example: ["ts", "js"])."""
|
|
3211
3317
|
for file_extension in file_extensions:
|
|
3212
3318
|
for file in self.get_not_git_ignored_files_of_folder(folder, f".{file_extension}"):
|
|
3213
|
-
self.
|
|
3319
|
+
self.normalize_invisible_characters(file)
|
|
3214
3320
|
|
|
3215
3321
|
@GeneralUtilities.check_arguments
|
|
3216
3322
|
def remove_trailing_linebreak(self, file: str) -> None:
|
|
@@ -347,7 +347,7 @@ class TFCPS_CodeUnitSpecific_DotNet_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
347
347
|
def linting(self) -> None:
|
|
348
348
|
codeunit_name = self.get_codeunit_name()
|
|
349
349
|
codeunit_folder = self.get_codeunit_folder()
|
|
350
|
-
self._protected_sc.
|
|
350
|
+
self._protected_sc.normalize_invisible_characters_of_files_in_folder(codeunit_folder, ["cs"])
|
|
351
351
|
nuspec_file = os.path.join(codeunit_folder, "Other", "Build", f"{codeunit_name}.nuspec")
|
|
352
352
|
if os.path.isfile(nuspec_file):
|
|
353
353
|
self._protected_sc.format_xml_file(nuspec_file)
|
|
@@ -86,7 +86,7 @@ class TFCPS_CodeUnitSpecific_Flutter_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
|
86
86
|
@GeneralUtilities.check_arguments
|
|
87
87
|
def linting(self) -> None:
|
|
88
88
|
codeunit_folder = self.get_codeunit_folder()
|
|
89
|
-
self._protected_sc.
|
|
89
|
+
self._protected_sc.normalize_invisible_characters_of_files_in_folder(codeunit_folder, ["java","dart", "kt", "html"])
|
|
90
90
|
#TODO call the flutter-linting here when available
|
|
91
91
|
|
|
92
92
|
@GeneralUtilities.check_arguments
|
|
@@ -1,72 +1,153 @@
|
|
|
1
1
|
import os
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
from ...
|
|
5
|
-
from ...SCLog import
|
|
6
|
-
from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base,TFCPS_CodeUnitSpecific_Base_CLI
|
|
2
|
+
import re
|
|
3
|
+
import requests
|
|
4
|
+
from ...GeneralUtilities import GeneralUtilities, Dependency
|
|
5
|
+
from ...SCLog import LogLevel
|
|
6
|
+
from ..TFCPS_CodeUnitSpecific_Base import TFCPS_CodeUnitSpecific_Base, TFCPS_CodeUnitSpecific_Base_CLI
|
|
7
7
|
|
|
8
8
|
class TFCPS_CodeUnitSpecific_Go_Functions(TFCPS_CodeUnitSpecific_Base):
|
|
9
|
+
"""Implements the tasks of a codeunit which contains a go-module.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
The go-module is expected in "<codeunit>/<codeunit>" and it contains its testcases in the same module,
|
|
12
|
+
because that is the layout go defines: the testcases of a file live in a "_test.go"-file next to it."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, current_file: str, verbosity: LogLevel, targetenvironmenttype: str, use_cache: bool, is_pre_merge: bool):
|
|
15
|
+
super().__init__(current_file, verbosity, targetenvironmenttype, use_cache, is_pre_merge)
|
|
16
|
+
|
|
17
|
+
@GeneralUtilities.check_arguments
|
|
18
|
+
def get_go_module_folder(self) -> str:
|
|
19
|
+
"""Returns the folder which contains the go.mod-file of this codeunit."""
|
|
20
|
+
return os.path.join(self.get_codeunit_folder(), self.get_codeunit_name())
|
|
21
|
+
|
|
22
|
+
@GeneralUtilities.check_arguments
|
|
23
|
+
def get_go_module_file(self) -> str:
|
|
24
|
+
return os.path.join(self.get_go_module_folder(), "go.mod")
|
|
25
|
+
|
|
26
|
+
@GeneralUtilities.check_arguments
|
|
27
|
+
def get_go_module_name(self) -> str:
|
|
28
|
+
"""Returns the name of the go-module as it is declared in the go.mod-file. The paths in the
|
|
29
|
+
coverage-report of go are prefixed with it, so it is required to resolve them."""
|
|
30
|
+
for line in GeneralUtilities.read_lines_from_file(self.get_go_module_file()):
|
|
31
|
+
match = re.match(r"^module\s+(\S+)$", line.strip())
|
|
32
|
+
if match is not None:
|
|
33
|
+
return match.group(1)
|
|
34
|
+
raise ValueError(f'The go-module-file "{self.get_go_module_file()}" does not declare a module-name.')
|
|
12
35
|
|
|
13
36
|
@GeneralUtilities.check_arguments
|
|
14
37
|
def build(self) -> None:
|
|
15
|
-
|
|
16
|
-
self.
|
|
38
|
+
codeunit_name = self.get_codeunit_name()
|
|
39
|
+
target_folder = os.path.join(self.get_artifacts_folder(), "BuildResult_Go")
|
|
40
|
+
GeneralUtilities.ensure_directory_exists(target_folder)
|
|
41
|
+
executable_name = codeunit_name+(".exe" if GeneralUtilities.current_system_is_windows() else GeneralUtilities.empty_string)
|
|
42
|
+
# The package of the module-root is built explicitly ("."). "./..." would build every package of the module,
|
|
43
|
+
# which go refuses when a single output-file is given.
|
|
44
|
+
self.__run_go(f"build -o {os.path.join(target_folder, executable_name)} .")
|
|
45
|
+
self.__generate_bom_for_go_module()
|
|
46
|
+
self.copy_source_files_to_output_directory()
|
|
17
47
|
|
|
18
48
|
@GeneralUtilities.check_arguments
|
|
19
|
-
def
|
|
20
|
-
|
|
49
|
+
def __generate_bom_for_go_module(self) -> None:
|
|
50
|
+
codeunit_version = self.tfcps_Tools_General.get_version_of_codeunit(self.get_codeunit_file())
|
|
51
|
+
bom_folder = os.path.join(self.get_artifacts_folder(), "BOM")
|
|
52
|
+
GeneralUtilities.ensure_directory_exists(bom_folder)
|
|
53
|
+
target_bom_file = os.path.join(bom_folder, f"{self.get_codeunit_name()}.{codeunit_version}.bom.xml")
|
|
54
|
+
self._protected_sc.run_program("cyclonedx-gomod", f"mod -licenses -output {target_bom_file} -output-version 1.5", self.get_go_module_folder(), print_live_output=self.get_verbosity() == LogLevel.Debug)
|
|
55
|
+
GeneralUtilities.assert_file_exists(target_bom_file)
|
|
56
|
+
self._protected_sc.format_xml_file(target_bom_file)
|
|
21
57
|
|
|
22
58
|
@GeneralUtilities.check_arguments
|
|
23
59
|
def linting(self) -> None:
|
|
24
|
-
|
|
60
|
+
self.__run_go("vet ./...")
|
|
61
|
+
# "gofmt -l" prints the files which are not formatted as gofmt would format them and exits with 0 either way,
|
|
62
|
+
# so the output has to be evaluated to recognize that there are linting-issues.
|
|
63
|
+
formatting_result = self._protected_sc.run_program("gofmt", "-l .", self.get_go_module_folder())
|
|
64
|
+
unformatted_files = [line.strip() for line in GeneralUtilities.string_to_lines(formatting_result[1]) if GeneralUtilities.string_has_content(line.strip())]
|
|
65
|
+
if 0 < len(unformatted_files):
|
|
66
|
+
for unformatted_file in unformatted_files:
|
|
67
|
+
self._protected_sc.log.log(f'File "{unformatted_file}" is not formatted as gofmt formats it.', LogLevel.Warning)
|
|
68
|
+
raise ValueError(f"{len(unformatted_files)} file(s) are not formatted as gofmt formats them.")
|
|
25
69
|
|
|
26
70
|
@GeneralUtilities.check_arguments
|
|
27
|
-
def
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
cls.set("filename", f"./{filename}")
|
|
36
|
-
cls.set("name",str(filename).rsplit("/", 1)[-1])
|
|
37
|
-
tree.write(coverage_file, encoding="utf-8", xml_declaration=True, pretty_print=True)
|
|
71
|
+
def do_common_tasks(self, current_codeunit_version: str) -> None:
|
|
72
|
+
self.do_common_tasks_base(current_codeunit_version)
|
|
73
|
+
# A go-module does not declare its own version: the version of a go-module is the git-tag it is published with,
|
|
74
|
+
# so there is no version in the go.mod-file which could be set here.
|
|
75
|
+
|
|
76
|
+
@GeneralUtilities.check_arguments
|
|
77
|
+
def generate_reference(self) -> None:
|
|
78
|
+
self.generate_reference_using_docfx()
|
|
38
79
|
|
|
39
80
|
@GeneralUtilities.check_arguments
|
|
40
81
|
def run_testcases(self) -> None:
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
82
|
+
codeunit_name = self.get_codeunit_name()
|
|
83
|
+
go_module_folder = self.get_go_module_folder()
|
|
84
|
+
coverprofile_file = os.path.join(GeneralUtilities.get_temp_folder(), f"{codeunit_name}.coverprofile")
|
|
85
|
+
GeneralUtilities.ensure_file_does_not_exist(coverprofile_file)
|
|
86
|
+
coverage_file = os.path.join(self.get_artifacts_folder(), "TestCoverage", "TestCoverage.xml")
|
|
87
|
+
GeneralUtilities.ensure_file_does_not_exist(coverage_file)
|
|
88
|
+
try:
|
|
89
|
+
# The coverprofile is written into the temp-folder and not into the module-folder, so that a file which is
|
|
90
|
+
# not git-ignored is not left behind in the codeunit when the testcases fail.
|
|
91
|
+
self.__run_go(f"test -coverprofile={coverprofile_file} ./...")
|
|
92
|
+
self.tfcps_Tools_General.convert_go_coverprofile_to_cobertura_report(coverprofile_file, coverage_file, codeunit_name, self.get_codeunit_folder(), self.get_go_module_name(), codeunit_name)
|
|
93
|
+
finally:
|
|
94
|
+
GeneralUtilities.ensure_file_does_not_exist(coverprofile_file)
|
|
95
|
+
self.run_testcases_common_post_task(self.get_repository_folder(), codeunit_name, True, self.get_target_environment_type())
|
|
96
|
+
|
|
55
97
|
@GeneralUtilities.check_arguments
|
|
56
|
-
def
|
|
57
|
-
|
|
58
|
-
|
|
98
|
+
def __run_go(self, arguments: str) -> None:
|
|
99
|
+
self._protected_sc.run_program("go", arguments, self.get_go_module_folder(), print_live_output=self.get_verbosity() == LogLevel.Debug)
|
|
100
|
+
|
|
101
|
+
@GeneralUtilities.check_arguments
|
|
102
|
+
def get_dependencies(self) -> dict[str, set[str]]:
|
|
103
|
+
return GeneralUtilities.merge_dependency_lists([self.__get_dependencies_from_go_module_file()])
|
|
104
|
+
|
|
105
|
+
@GeneralUtilities.check_arguments
|
|
106
|
+
def __get_dependencies_from_go_module_file(self) -> list[Dependency]:
|
|
107
|
+
result: list[Dependency] = []
|
|
108
|
+
is_in_require_block: bool = False
|
|
109
|
+
for line in GeneralUtilities.read_lines_from_file(self.get_go_module_file()):
|
|
110
|
+
stripped_line = line.strip()
|
|
111
|
+
if stripped_line == "require (":
|
|
112
|
+
is_in_require_block = True
|
|
113
|
+
continue
|
|
114
|
+
if is_in_require_block and stripped_line == ")":
|
|
115
|
+
is_in_require_block = False
|
|
116
|
+
continue
|
|
117
|
+
if stripped_line.startswith("//") or not GeneralUtilities.string_has_content(stripped_line):
|
|
118
|
+
continue
|
|
119
|
+
# A dependency is declared either in a require-block or in a single require-line.
|
|
120
|
+
match = re.match(r"^(?:require\s+)?(\S+)\s+v(\d+\.\d+\.\d+)(?:\s+//.*)?$", stripped_line)
|
|
121
|
+
if match is not None and (is_in_require_block or stripped_line.startswith("require ")):
|
|
122
|
+
result.append(Dependency(match.group(1), match.group(2)))
|
|
123
|
+
return result
|
|
124
|
+
|
|
59
125
|
@GeneralUtilities.check_arguments
|
|
60
|
-
def
|
|
61
|
-
|
|
62
|
-
|
|
126
|
+
def get_available_versions(self, dependencyname: str) -> list[str]:
|
|
127
|
+
# The go-module-proxy answers with the published versions of a module, one version per line.
|
|
128
|
+
response = requests.get(f"https://proxy.golang.org/{dependencyname.lower()}/@v/list", timeout=60)
|
|
129
|
+
response.raise_for_status()
|
|
130
|
+
result: list[str] = []
|
|
131
|
+
for line in GeneralUtilities.string_to_lines(response.text):
|
|
132
|
+
match = re.match(r"^v(\d+\.\d+\.\d+)$", line.strip())
|
|
133
|
+
if match is not None:
|
|
134
|
+
result.append(match.group(1))
|
|
135
|
+
return result
|
|
136
|
+
|
|
137
|
+
@GeneralUtilities.check_arguments
|
|
138
|
+
def set_dependency_version(self, name: str, new_version: str) -> None:
|
|
139
|
+
# "go get" is used instead of rewriting the go.mod-file, because it also updates the go.sum-file, which
|
|
140
|
+
# contains the checksums of the dependencies and would make the build fail if it did not match the go.mod-file.
|
|
141
|
+
self.__run_go(f"get {name}@v{new_version}")
|
|
142
|
+
self.__run_go("mod tidy")
|
|
143
|
+
|
|
63
144
|
class TFCPS_CodeUnitSpecific_Go_CLI:
|
|
64
145
|
|
|
65
146
|
@staticmethod
|
|
66
147
|
@GeneralUtilities.check_arguments
|
|
67
|
-
def parse(file:str)->TFCPS_CodeUnitSpecific_Go_Functions:
|
|
68
|
-
parser=TFCPS_CodeUnitSpecific_Base_CLI.get_base_parser()
|
|
148
|
+
def parse(file: str) -> TFCPS_CodeUnitSpecific_Go_Functions:
|
|
149
|
+
parser = TFCPS_CodeUnitSpecific_Base_CLI.get_base_parser()
|
|
69
150
|
#add custom parameter if desired
|
|
70
|
-
args=parser.parse_args()
|
|
71
|
-
result:TFCPS_CodeUnitSpecific_Go_Functions=TFCPS_CodeUnitSpecific_Go_Functions(file,LogLevel(int(args.verbosity)),args.targetenvironmenttype,not args.nocache,args.ispremerge)
|
|
151
|
+
args = parser.parse_args()
|
|
152
|
+
result: TFCPS_CodeUnitSpecific_Go_Functions = TFCPS_CodeUnitSpecific_Go_Functions(file, LogLevel(int(args.verbosity)), args.targetenvironmenttype, not args.nocache, args.ispremerge)
|
|
72
153
|
return result
|