spl-core 4.1.0__py3-none-any.whl → 4.1.2__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.
spl_core/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "4.1.0"
1
+ __version__ = "4.1.2"
@@ -27,7 +27,7 @@ class BaseVariantTestRunner(ABC):
27
27
 
28
28
  @property
29
29
  def expected_variant_report_artifacts(self) -> List[Path]:
30
- return [Path("reports/reports/index.html")]
30
+ return [Path("reports/html/index.html")]
31
31
 
32
32
  @property
33
33
  def expected_component_report_artifacts(self) -> List[Path]:
@@ -39,23 +39,46 @@ class BaseVariantTestRunner(ABC):
39
39
  Path("coverage/index.html"),
40
40
  ]
41
41
 
42
+ @property
43
+ def create_artifacts_archive(self) -> bool:
44
+ return True
45
+
46
+ @property
47
+ def create_artifacts_json(self) -> bool:
48
+ return True
49
+
50
+ @property
51
+ def expected_archive_artifacts(self) -> List[Path]:
52
+ return self.expected_build_artifacts
53
+
54
+ def assert_artifact_exists(self, dir: Path, artifact: Path) -> None:
55
+ if artifact.is_absolute():
56
+ assert artifact.exists(), f"Artifact {artifact} does not exist" # noqa: S101
57
+ else:
58
+ assert Path.joinpath(dir, artifact).exists(), f"Artifact {Path.joinpath(dir, artifact)} does not exist" # noqa: S101
59
+
42
60
  def test_build(self) -> None:
43
61
  spl_build: SplBuild = SplBuild(variant=self.variant, build_kit="prod")
44
62
  assert 0 == spl_build.execute(target="all") # noqa: S101
45
63
  for artifact in self.expected_build_artifacts:
46
- assert artifact.exists() or Path.joinpath(spl_build.build_dir, artifact).exists() # noqa: S101
64
+ self.assert_artifact_exists(dir=spl_build.build_dir, artifact=artifact)
65
+ if self.create_artifacts_archive:
66
+ # create artifacts archive
67
+ spl_build.create_artifacts_archive(self.expected_archive_artifacts)
68
+ if self.create_artifacts_json:
69
+ spl_build.create_artifacts_json(self.expected_archive_artifacts)
47
70
 
48
71
  def test_unittest(self) -> None:
49
72
  spl_build: SplBuild = SplBuild(variant=self.variant, build_kit="test")
50
73
  assert 0 == spl_build.execute(target="unittests") # noqa: S101
51
74
  for artifact in self.expected_test_artifacts:
52
- assert artifact.exists() # noqa: S101
75
+ self.assert_artifact_exists(dir=spl_build.build_dir, artifact=artifact)
53
76
 
54
77
  def test_reports(self) -> None:
55
78
  spl_build: SplBuild = SplBuild(variant=self.variant, build_kit="test")
56
79
  assert 0 == spl_build.execute(target="all") # noqa: S101
57
80
  for artifact in self.expected_variant_report_artifacts:
58
- assert Path.joinpath(spl_build.build_dir, artifact).exists() # noqa: S101
81
+ self.assert_artifact_exists(dir=spl_build.build_dir, artifact=artifact)
59
82
  for component in self.component_paths:
60
83
  for artifact in self.expected_component_report_artifacts:
61
- assert Path.joinpath(spl_build.build_dir, component, artifact).exists() # noqa: S101
84
+ self.assert_artifact_exists(dir=Path.joinpath(spl_build.build_dir, "reports", "html", spl_build.build_dir, component, "reports"), artifact=artifact)
@@ -1,4 +1,7 @@
1
+ import json
1
2
  import time
3
+ import zipfile
4
+ from dataclasses import dataclass
2
5
  from pathlib import Path
3
6
  from typing import List, Optional
4
7
 
@@ -7,6 +10,34 @@ from py_app_dev.core.logging import time_it
7
10
  from spl_core.common.command_line_executor import CommandLineExecutor
8
11
 
9
12
 
13
+ @dataclass
14
+ class ArchiveArtifact:
15
+ archive_path: Path
16
+ absolute_path: Path
17
+
18
+
19
+ class ArtifactsCollection:
20
+ def __init__(self, artifacts: List[Path], build_dir: Path):
21
+ self.archive_artifacts: List[ArchiveArtifact] = []
22
+ for artifact in artifacts:
23
+ if artifact.is_absolute():
24
+ artifact_path = artifact
25
+ else:
26
+ artifact_path = Path.joinpath(build_dir.absolute(), artifact)
27
+ if artifact_path.is_dir():
28
+ for artifact in artifact_path.glob("**/*"):
29
+ if artifact.is_file():
30
+ if artifact_path.is_relative_to(build_dir.absolute()):
31
+ self.archive_artifacts.append(ArchiveArtifact(archive_path=artifact.relative_to(build_dir.absolute()), absolute_path=artifact.absolute()))
32
+ else:
33
+ self.archive_artifacts.append(ArchiveArtifact(archive_path=Path(artifact.name), absolute_path=artifact.absolute()))
34
+ else:
35
+ if artifact_path.is_relative_to(build_dir.absolute()):
36
+ self.archive_artifacts.append(ArchiveArtifact(archive_path=artifact_path.relative_to(build_dir.absolute()), absolute_path=artifact_path.absolute()))
37
+ else:
38
+ self.archive_artifacts.append(ArchiveArtifact(archive_path=Path(artifact_path.name), absolute_path=artifact_path.absolute()))
39
+
40
+
10
41
  class SplBuild:
11
42
  """Class for building an SPL repository."""
12
43
 
@@ -75,3 +106,57 @@ class SplBuild:
75
106
  else:
76
107
  break
77
108
  return return_code
109
+
110
+ def create_artifacts_archive(self, expected_artifacts: List[Path]) -> Path:
111
+ """
112
+ Create a zip file containing the collected artifacts.
113
+
114
+ Args:
115
+ expected_artifacts: List of Path of artifacts which should be archived
116
+
117
+ Returns:
118
+ Path: The path to the created zip file.
119
+
120
+ Raises:
121
+ Exception: If there is an error creating the zip file.
122
+
123
+ """
124
+ zip_path = self.build_dir / "artifacts.zip"
125
+
126
+ # Delete the file if it already exists
127
+ if zip_path.exists():
128
+ zip_path.unlink()
129
+
130
+ try:
131
+ with zipfile.ZipFile(zip_path, "w") as zip_file:
132
+ artifacts_collection = ArtifactsCollection(artifacts=expected_artifacts, build_dir=self.build_dir)
133
+ for artifact in artifacts_collection.archive_artifacts:
134
+ zip_file.write(artifact.absolute_path, arcname=artifact.archive_path)
135
+ print(f"Zip file created at: {zip_path}")
136
+ return zip_path
137
+ except Exception as e:
138
+ print(f"Error creating artifacts zip file: {e}")
139
+ raise e
140
+
141
+ def create_artifacts_json(self, expected_artifacts: List[Path]) -> Path:
142
+ """
143
+ Create a JSON file listing the collected artifacts.
144
+
145
+ Returns:
146
+ Path: The path to the created JSON file.
147
+
148
+ Raises:
149
+ Exception: If there is an error creating the JSON file.
150
+
151
+ """
152
+ artifacts_collection = ArtifactsCollection(artifacts=expected_artifacts, build_dir=self.build_dir)
153
+ json_content = {
154
+ "variant": self.variant,
155
+ "build_kit": self.build_kit,
156
+ "artifacts": [str(artifact.archive_path.as_posix()) for artifact in artifacts_collection.archive_artifacts],
157
+ }
158
+ json_path = self.build_dir / "artifacts.json"
159
+
160
+ json_path.write_text(json.dumps(json_content, indent=4))
161
+
162
+ return json_path
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: spl-core
3
- Version: 4.1.0
3
+ Version: 4.1.2
4
4
  Summary: Software Product Line Support for CMake
5
5
  Home-page: https://github.com/avengineers/spl-core
6
6
  License: MIT
@@ -1,4 +1,4 @@
1
- spl_core/__init__.py,sha256=jegJMYuSW90VKiMotVdNAakBvYVPirm-A5oeyJVuhH8,22
1
+ spl_core/__init__.py,sha256=AyLvA6hLK9mzQgiHyEbmvYQ9t6-oye0gm_KltlPS_oc,22
2
2
  spl_core/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  spl_core/common/cmake.py,sha256=qId_QIGqvG_qkJWOTJjiW723nev6p0vvP3O0Jlfppz4,2054
4
4
  spl_core/common/command_line_executor.py,sha256=2ck2ndExyjfFORGMHhtOPTWA3gJGJ_GdZfopen2ISoY,2019
@@ -60,9 +60,9 @@ spl_core/project_creator/templates/variant/{{cookiecutter.flavor}}/{{cookiecutte
60
60
  spl_core/project_creator/templates/variant/{{cookiecutter.flavor}}/{{cookiecutter.subsystem}}/parts.cmake,sha256=s-SMLPvajH4ZGupruSuh-SbL8jackverQpxGqdoD-Io,77
61
61
  spl_core/project_creator/variant.py,sha256=juZWBvLT7i1ZtP1LlGBDalzTf0mhFvfoON43VoqjZOA,532
62
62
  spl_core/project_creator/workspace_artifacts.py,sha256=E4oZjnFgC2-cz9jYIYUZzOC9R07LBJAbgGwHAuK0Arg,1279
63
- spl_core/test_utils/base_variant_test_runner.py,sha256=xoMiNxCxXNyNdwAJ0xmzwqgMPrNJOSeanbttlDOxQSA,2256
64
- spl_core/test_utils/spl_build.py,sha256=J7gj9Q979pivkYi6Bm2YUSCpjCXQ72rioCZbAgcCoLY,2172
65
- spl_core-4.1.0.dist-info/LICENSE,sha256=UjjA0o8f5tT3wVm7qodTLAhPWLl6kgVyn9FPAd1VeYY,1099
66
- spl_core-4.1.0.dist-info/METADATA,sha256=VHPQGIRfVlJq74E4--POmNp3_aC1Ir3_Qmh3SdV41g8,1997
67
- spl_core-4.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
68
- spl_core-4.1.0.dist-info/RECORD,,
63
+ spl_core/test_utils/base_variant_test_runner.py,sha256=4ugideRMJqj1oaSboMSK7qZnAwg3O8Ysk23SdIi_t1o,3221
64
+ spl_core/test_utils/spl_build.py,sha256=TtYFTY94Fa9eXdtY9NavrCulx-NEONRm81GSLHGB_yQ,5599
65
+ spl_core-4.1.2.dist-info/LICENSE,sha256=UjjA0o8f5tT3wVm7qodTLAhPWLl6kgVyn9FPAd1VeYY,1099
66
+ spl_core-4.1.2.dist-info/METADATA,sha256=HY7Mbor5i8ITEqAw4pVhqfH1MBI-27lOQK34TTXWp4c,1997
67
+ spl_core-4.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
68
+ spl_core-4.1.2.dist-info/RECORD,,