Skip to content

Commit 03ca8cc

Browse files
Oleksandr Muzyka (EPAM)Oleksandr Muzyka (EPAM)
authored andcommitted
- Refactor SAMM CLI path retrieval for cross-platform compatibility
- Add archive extraction functionality to download_samm_cli - Add SAMM CLI installation and native dependencies to CI workflow - Refactor resource path in test_cli_functions to improve clarity and maintainability - Stop running tests after the first failure
1 parent c5aaf25 commit 03ca8cc

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
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

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
99
#
1010
# SPDX-License-Identifier: MPL-2.0
11+
import platform
1112
import subprocess
1213

1314
from os.path import exists, join
@@ -33,9 +34,14 @@ def __init__(self):
3334
def _get_client_path():
3435
"""Get path to the SAMM CLI executable file."""
3536
base_path = Path(__file__).resolve()
36-
cli_path = join(base_path.parents[2], "samm-cli", "samm.exe")
37+
cli_dir = base_path.parents[2] / "samm-cli"
3738

38-
return cli_path
39+
if platform.system() == "Windows":
40+
cli_file = "samm.exe"
41+
else:
42+
cli_file = "samm" # Unix-like systems
43+
44+
return join(cli_dir, cli_file)
3945

4046
@staticmethod
4147
def _format_argument(key: str, value: Any) -> str:

core/esmf-aspect-meta-model-python/scripts/download_samm_cli.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import os
9+
import tarfile
910
from pathlib import Path
1011
import platform
1112
import requests
@@ -35,6 +36,8 @@ def download_archive_file(url, archive_file):
3536
with open(archive_file, "wb") as f:
3637
print("Downloading %s" % archive_file)
3738
response = requests.get(url, allow_redirects=True, stream=True)
39+
response.raise_for_status() # Fail fast if HTTP error
40+
3841
content_len = response.headers.get('content-length')
3942

4043
if content_len is None:
@@ -55,6 +58,17 @@ def download_archive_file(url, archive_file):
5558
sys.stdout.flush()
5659

5760

61+
def extract_archive(archive_file, dest_dir):
62+
"""Extract archive depending on its file type."""
63+
if archive_file.endswith(".zip"):
64+
with zipfile.ZipFile(archive_file) as archive:
65+
archive.extractall(dest_dir)
66+
elif archive_file.endswith((".tar.gz", ".tgz")):
67+
with tarfile.open(archive_file, mode="r:gz") as archive:
68+
archive.extractall(dest_dir)
69+
else:
70+
raise ValueError(f"Unsupported archive format: {archive_file}")
71+
5872
def download_samm_cli():
5973
try:
6074
samm_cli_file_name = get_samm_cli_file_name()
@@ -70,10 +84,7 @@ def download_samm_cli():
7084
print("\nSAMM CLI archive file downloaded")
7185

7286
print("Start extracting files")
73-
archive = zipfile.ZipFile(archive_file)
74-
for file in archive.namelist():
75-
archive.extract(file, "samm-cli")
76-
archive.close()
87+
extract_archive(archive_file, os.path.join(dir_path, "samm-cli"))
7788
print("Done extracting files.")
7889

7990
print("Deleting SAMM CLI archive file.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from esmf_aspect_meta_model_python.samm_cli.base import SammCli
2323

24-
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"
2525

2626

2727
@pytest.fixture(scope="module")

core/esmf-aspect-meta-model-python/tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description = Run the tests
1111
commands_pre = poetry install
1212
commands =
1313
poetry run pytest {posargs: \
14-
-s -vv \
14+
-x -s -vv \
1515
--cov=esmf_aspect_meta_model_python/ \
1616
--cov-fail-under=85 \
1717
tests/ \
@@ -42,4 +42,4 @@ known_first_party = esmf_aspect_meta_model_python, tests
4242
line_length = 120
4343
lines_between_types = 1
4444
multi_line_output = 3
45-
sections = STDLIB, THIRDPARTY, FIRSTPARTY, LOCALFOLDER
45+
sections = STDLIB, THIRDPARTY, FIRSTPARTY, LOCALFOLDER

0 commit comments

Comments
 (0)