Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SAMM cli usage #33

Merged
merged 2 commits into from
Apr 22, 2024
Merged

Add SAMM cli usage #33

merged 2 commits into from
Apr 22, 2024

Conversation

Hanna-Shalamitskaya-EPAM
Copy link
Contributor

Changes:

  • added interface for calling SAMM CLI function;
  • update tests.

import sys
import zipfile

BASE_PATH = "https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.6.1/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it's worth extracting the version of CLI to config, or at least to a constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a constant for the SAMM CLI version



class SammCli:
"""Class to eecute SAMM CLI functions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Class to eecute SAMM CLI functions.
"""Class to execute SAMM CLI functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

class SammCli:
"""Class to eecute SAMM CLI functions.

If there is no downloaded SAMM CLI, code will identify operation system and download a corresponding client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If there is no downloaded SAMM CLI, code will identify operation system and download a corresponding client.
If there is no downloaded SAMM CLI, the code will identify the operating system and download a corresponding SAMM CLI version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

If there is no SAMM Cli executable file, run a script for downloading.
"""
if not exists(self._samm):
# download SAMM CLI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment, this is redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

return cli_path

def _validate_client(self):
"""Validate SAMM Cli.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unify the name, e.g. use "SAMM CLI" everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed for all comments

param path_to_model: local path to the aspect model file (*.ttl)
possible arguments:
- output, o: output file path (default: stdout)
- api-base-url, b: the base url for the Aspect API used in the OpenAPI specification, b="http://mysite.de"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please something neutral as example, e.g. http://example.com/ or http://localhost/. http://mysite.de is an actually existing website.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.
Note: This description is taken from the ESMF documentation (https://eclipse-esmf.github.io/esmf-developer-guide/tooling-guide/samm-cli.html)

import sys
import zipfile

BASE_PATH = "https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.6.1/"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would make sense to define the version string ("2.6.1") as a variable or constant, since it's repeated many times over.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a separate constant for the version number

print("Start extracting files")
archive = zipfile.ZipFile(archive_file)
for file in archive.namelist():
archive.extract(file, ".\\samm-cli")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work on all platforms (because of the backslash \)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaces with os specific separator

print(f"Start downloading SAMM CLI {samm_cli_file_name}")
url = BASE_PATH + samm_cli_file_name
dir_path = Path(__file__).resolve().parent
archive_file = os.path.join(dir_path, f".\\{samm_cli_file_name}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to use:
archive_file = os.path.join(dir_path, samm_cli_file_name)
so that it works for all os systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

print("Start extracting files")
archive = zipfile.ZipFile(archive_file)
for file in archive.namelist():
archive.extract(file, ".\\samm-cli")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have to use, also here something like:
archive.extract(file, os.path.join("", "samm-cli"))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@atextor atextor merged commit 3d643eb into eclipse-esmf:main Apr 22, 2024
2 checks passed
@atextor atextor deleted the use-samm-cli branch April 22, 2024 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants