Skip to content

Commit a264760

Browse files
Oleksandr Muzyka (EPAM)Oleksandr Muzyka (EPAM)
authored andcommitted
Refactor SAMM CLI, add archive extraction, update CI & version bump
- Enhance SAMM CLI functions with capture output option and update tests - Add ability to download samm-cli for macOS - Add archive extraction functionality to download_samm_cli - Add SAMM CLI installation and native dependencies to CI workflow - Stop running tests after the first failure - Refactor resource path in test_cli_functions to improve clarity and maintainability - Refactor SAMM CLI path retrieval for cross-platform compatibility
1 parent 0790810 commit a264760

File tree

9 files changed

+401
-137
lines changed

9 files changed

+401
-137
lines changed

.github/workflows/push_request_check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
cd core/esmf-aspect-meta-model-python
3636
poetry install
3737
poetry run download-samm-release
38+
poetry run download-samm-cli
3839
poetry build
3940
4041
- name: run tests

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ dmypy.json
6969

7070
# SAMM
7171
core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_aspect_meta_model/samm/
72-
/core/esmf-aspect-meta-model-python/samm-cli/
72+
core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_cli/samm-cli/
7373
/core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/java_models/resources/

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_cli/base.py

Lines changed: 89 additions & 48 deletions
Large diffs are not rendered by default.

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_cli/constants.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616

1717

1818
class SAMMCliConstants:
19-
BASE_PATH = Template("https://github.com/eclipse-esmf/esmf-sdk/releases/download/v$version_number/$file_name")
20-
JAVA_CLI_VERSION = JAVA_CLI_VERSION
21-
LINUX_FILE_NAME = Template("samm-cli-$version_number-linux-x86_64.tar.gz")
2219
SAMM_VERSION = SAMM_VERSION
20+
JAVA_CLI_VERSION = JAVA_CLI_VERSION
21+
22+
BASE_PATH = Template("https://github.com/eclipse-esmf/esmf-sdk/releases/download/v$version_number/$file_name")
23+
2324
WIN_FILE_NAME = Template("samm-cli-$version_number-windows-x86_64.zip")
25+
LINUX_FILE_NAME = Template("samm-cli-$version_number-linux-x86_64.tar.gz")
26+
MAC_FILE_NAME = Template("samm-cli-$version_number-macos-x86_64.tar.gz")
2427

2528

2629
class SAMMCLICommands:

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/samm_cli/download.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Download SAMM CLI.
22
3-
Windows: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-windows-x86_64.zip
4-
Linux: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-linux-x86_64.tar.gz
5-
JAR: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2.jar
3+
Windows: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.11.1/samm-cli-2.11.1-windows-x86_64.zip
4+
Linux: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.11.1/samm-cli-2.11.1-linux-x86_64.tar.gz
5+
JAR: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.11.1/samm-cli-2.11.1.jar
66
"""
77

88
import os
99
import platform
1010
import sys
11+
import tarfile
1112
import zipfile
1213

1314
from pathlib import Path
@@ -24,6 +25,8 @@ def get_samm_cli_file_name():
2425
file_name = Const.WIN_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION)
2526
elif platform.system() == "Linux":
2627
file_name = Const.LINUX_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION)
28+
elif platform.system() == "Darwin": # macOS
29+
file_name = Const.MAC_FILE_NAME.substitute(version_number=Const.JAVA_CLI_VERSION)
2730
else:
2831
raise NotImplementedError(
2932
f"Please download a SAMM CLI manually for your operation system from '{Const.BASE_PATH}'"
@@ -37,6 +40,8 @@ def download_archive_file(url, archive_file):
3740
with open(archive_file, "wb") as f:
3841
print("Downloading %s" % archive_file)
3942
response = requests.get(url, allow_redirects=True, stream=True)
43+
response.raise_for_status() # Fail fast if HTTP error
44+
4045
content_len = response.headers.get("content-length")
4146

4247
if content_len is None:
@@ -57,6 +62,18 @@ def download_archive_file(url, archive_file):
5762
sys.stdout.flush()
5863

5964

65+
def extract_archive(archive_file, dest_dir):
66+
"""Extract archive depending on its file type."""
67+
if archive_file.endswith(".zip"):
68+
with zipfile.ZipFile(archive_file) as archive:
69+
archive.extractall(dest_dir)
70+
elif archive_file.endswith((".tar.gz", ".tgz")):
71+
with tarfile.open(archive_file, mode="r:gz") as archive:
72+
archive.extractall(dest_dir)
73+
else:
74+
raise ValueError(f"Unsupported archive format: {archive_file}")
75+
76+
6077
def download_samm_cli():
6178
try:
6279
samm_cli_file_name = get_samm_cli_file_name()
@@ -72,11 +89,7 @@ def download_samm_cli():
7289
print("\nSAMM CLI archive file downloaded")
7390

7491
print("Start extracting files")
75-
archive = zipfile.ZipFile(archive_file)
76-
extracted_files_path = os.path.join(dir_path, "samm-cli")
77-
for file in archive.namelist():
78-
archive.extract(file, extracted_files_path)
79-
archive.close()
92+
extract_archive(archive_file, dest_dir=os.path.join(dir_path, "samm-cli"))
8093
print("Done extracting files")
8194

8295
print("Deleting SAMM CLI archive file")

core/esmf-aspect-meta-model-python/tests/integration/cli_functions.py renamed to core/esmf-aspect-meta-model-python/tests/integration/test_cli_functions.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
111
"""Integration tests for SAMM CLI functions."""
212

313
import json
@@ -11,7 +21,7 @@
1121

1222
from esmf_aspect_meta_model_python.samm_cli.base import SammCli
1323

14-
RESOURCE_PATH = os.getcwd() / Path("tests/integration/resources/org.eclipse.esmf.test.general/2.1.0")
24+
RESOURCE_PATH = Path(__file__).parent / "resources" / "org.eclipse.esmf.test.general" / "2.1.0"
1525

1626

1727
@pytest.fixture(scope="module")
@@ -41,18 +51,29 @@ def samm_cli():
4151
class TestSammCliIntegration:
4252
"""Integration tests for SAMM CLI transformations."""
4353

44-
def test_prettyprint(self, samm_cli, file_path, temp_output_dir):
45-
"""Test pretty-printing the model."""
46-
output_file = os.path.join(temp_output_dir, "prettyprinted.ttl")
54+
class TestPrettyPrint:
55+
"""Test pretty-printing functionality."""
4756

48-
samm_cli.prettyprint(file_path, output=output_file)
57+
def test_file_output(self, samm_cli, file_path, temp_output_dir):
58+
"""Test pretty-printing to a file."""
59+
output_file = os.path.join(temp_output_dir, "prettyprinted.ttl")
4960

50-
assert os.path.exists(output_file)
51-
assert os.path.getsize(output_file) > 0
52-
with open(output_file, "r") as f:
53-
content = f.read()
54-
assert "@prefix" in content
55-
assert ":SampleAspect" in content
61+
samm_cli.prettyprint(file_path, output=output_file)
62+
63+
assert os.path.exists(output_file)
64+
assert os.path.getsize(output_file) > 0
65+
with open(output_file, "r") as f:
66+
content = f.read()
67+
assert "@prefix" in content
68+
assert ":SampleAspect" in content
69+
70+
def test_capture_output(self, samm_cli, file_path):
71+
"""Test pretty-printing with captured output."""
72+
prettyprinted_content = samm_cli.prettyprint(file_path, capture=True)
73+
74+
assert isinstance(prettyprinted_content, str)
75+
assert "@prefix" in prettyprinted_content
76+
assert ":SampleAspect" in prettyprinted_content
5677

5778
def test_to_json(self, samm_cli, file_path, temp_output_dir):
5879
"""Test generating example JSON payload."""

0 commit comments

Comments
 (0)