|
1 | 1 | The Aspect Model Loader as part of the Python SDK provided by the [*Eclipse Semantic Modeling Framework*]( |
2 | 2 | https://projects.eclipse.org/projects/dt.esmf). |
3 | 3 |
|
| 4 | +<!-- TOC --> |
| 5 | +* [An Aspect of the Meta Model](#an-aspect-of-the-meta-model) |
| 6 | + * [Set Up SAMM Aspect Meta Model](#set-up-samm-aspect-meta-model) |
| 7 | + * [Install poetry](#install-poetry) |
| 8 | + * [Install project dependencies](#install-project-dependencies) |
| 9 | + * [Download SAMM files](#download-samm-files) |
| 10 | + * [Download SAMM release](#download-samm-release) |
| 11 | + * [Download SAMM branch](#download-samm-branch) |
| 12 | + * [Aspect Meta Model Loader usage](#aspect-meta-model-loader-usage) |
| 13 | + * [Samm Units](#samm-units) |
| 14 | + * [SAMM CLI wrapper class](#samm-cli-wrapper-class) |
| 15 | +* [Scripts](#scripts) |
| 16 | +* [Automation Tasks](#automation-tasks) |
| 17 | + * [tox](#tox) |
| 18 | + * [GitHub actions](#github-actions) |
| 19 | + * [Check New Pull Request](#check-new-pull-request) |
| 20 | + * [Build release](#build-release) |
| 21 | +<!-- TOC --> |
| 22 | + |
4 | 23 | # An Aspect of the Meta Model |
5 | 24 |
|
6 | 25 | The `esmf-aspect-model-loader` package provides the Python implementation for the SAMM Aspect Meta Model, or SAMM. |
7 | 26 | Each Meta Model element and each Characteristic class is represented by an interface with a corresponding |
8 | 27 | implementation. |
9 | 28 |
|
10 | | -## Usage |
| 29 | +## Set Up SAMM Aspect Meta Model |
11 | 30 |
|
12 | | -An Aspect of the Meta Model can be created as follows using the provided `AspectInstantiator`. |
| 31 | +Before getting started to use the `esmf-aspect-model-loader` library you need to apply some set up actions: |
13 | 32 |
|
14 | | -``` |
15 | | -aspect_loader = AspectLoader() |
16 | | -aspect = aspect_loader.load_aspect_model("absolute/path/to/turtle.ttl"); |
| 33 | +Required |
| 34 | +- [Install poetry](#install-poetry) |
| 35 | +- [Install project dependencies](#install-project-dependencies) |
| 36 | +- [Download SAMM files](#download-samm-files) |
| 37 | +Optional |
| 38 | +- [Download SAMM CLI](#download-samm-cli) (needed to use SAMM CLI functions) |
| 39 | +- [Download SAMM test models](#download-test-models) (for running integration tests) |
| 40 | + |
| 41 | +### Install poetry |
| 42 | + |
| 43 | +`Poetry` used as a dependency management for the `esmf-aspect-model-loader`. Follow the next [instruction](https://python-poetry.org/docs/#installation) |
| 44 | + to install it. |
| 45 | + |
| 46 | +To check the poetry version run: |
| 47 | +```console |
| 48 | +poetry --version |
17 | 49 | ``` |
18 | 50 |
|
19 | | -or |
| 51 | +### Install project dependencies |
20 | 52 |
|
| 53 | +Poetry provides convenient functionality for working with dependencies in the project. |
| 54 | +To automatically download and install all the necessary libraries, just run one command: |
| 55 | +```console |
| 56 | +poetry install |
21 | 57 | ``` |
22 | | -aspect_loader = AspectLoader() |
23 | | -aspect = aspect_loader.load_aspect_model_from_multiple_files(["list/of/absolute/paths/to/turtles.ttl"], "aspect_urn"); |
| 58 | +It is required to run `poetry install` once in the esmf-aspect-model-loader module. |
| 59 | + |
| 60 | +### Download SAMM files |
| 61 | + |
| 62 | +There are two possibilities to download the SAMM files and extract the Turtle sources for the Meta Model: |
| 63 | +SAMM release or SAMM branch |
| 64 | + |
| 65 | +#### Download SAMM release |
| 66 | + |
| 67 | +This script downloads a release JAR-file from GitHub, extracts them for further usage in the Aspect Model Loader: |
| 68 | + |
| 69 | +To run script, execute the next command. |
| 70 | +```console |
| 71 | +poetry run download-samm-release |
24 | 72 | ``` |
| 73 | +The version of the SAMM release is specified in the python script. |
| 74 | + |
| 75 | +Link to all Releases: [SAMM Releases](https://github.com/eclipse-esmf/esmf-semantic-aspect-meta-model/releases) |
25 | 76 |
|
26 | | -## Automatic Deployment |
| 77 | +#### Download SAMM branch |
27 | 78 |
|
28 | | -A [GitHub action called 'Release'](https://github.com/eclipse-esmf/esmf-sdk-py-aspect-model-loader/actions/workflows/tagged_release.yml) |
29 | | -has been set up for the `esmf-aspect-model-loader`. This action checks the code quality by running tests, the [static type checker MyPy](https://github.com/python/mypy) and |
30 | | -the [code formatter 'Black'](https://github.com/psf/black). |
| 79 | +The script uses the GitHub API and downloads the files from the `main` GitHub branch. |
31 | 80 |
|
32 | | -## Set Up SAMM Aspect Meta Model for development |
| 81 | +If the script is run in a pipeline, it uses a GitHub token to authorize. If the script is run locally, |
| 82 | +the API is called without a token. This may cause problems because unauthorized API calls are limited. |
33 | 83 |
|
34 | | -In order to download the SAMM sources, it is required to run `poetry install` once in the `esmf-aspect-model-loader` |
35 | | -module. There are two possibilities to download the SAMM files and extract the Turtle sources for the Meta Model. |
| 84 | +Run the next command to download and start working with the Aspect Model Loader. |
| 85 | +```console |
| 86 | +poetry run download-samm-branch |
| 87 | +``` |
| 88 | +Link to all branches: [SAMM Releases](https://github.com/eclipse-esmf/esmf-semantic-aspect-meta-model/branches) |
36 | 89 |
|
37 | | -### Possibility 1 (downloading a release) |
| 90 | +## Aspect Meta Model Loader usage |
38 | 91 |
|
39 | | -The `download_samm_release` script may be executed with |
| 92 | +An Aspect of the Meta Model can be loaded as follows: |
| 93 | +```python |
| 94 | +from esmf_aspect_meta_model_python import AspectLoader |
40 | 95 |
|
| 96 | +loader = AspectLoader() |
| 97 | +model_elements = loader.load_aspect_model("absolute/path/to/turtle.ttl") |
| 98 | +aspect = model_elements[0] |
| 99 | + |
| 100 | +# or you can provide an Aspect URN |
| 101 | + |
| 102 | +loader = AspectLoader() |
| 103 | +aspect_urn = "urn:samm:org.eclipse.esmf.samm:aspect.model:0.0.1#AspectName" |
| 104 | +model_elements = loader.load_aspect_model("absolute/path/to/turtle.ttl", aspect_urn) |
| 105 | +aspect = model_elements[0] |
41 | 106 | ``` |
42 | | -poetry run download-samm-release |
43 | | -``` |
44 | 107 |
|
45 | | -It downloads a release JAR-file from GitHub and extracts the SAMM Files. |
46 | | -The version is specified in the python script. |
| 108 | +## Samm Units |
| 109 | + |
| 110 | +SAMMUnitsGraph is a class contains functions for accessing units of measurement. |
| 111 | +```python |
| 112 | +from esmf_aspect_meta_model_python.samm_meta_model import SammUnitsGraph |
47 | 113 |
|
48 | | -Link to all Releases: https://github.com/eclipse-esmf/esmf-semantic-aspect-meta-model/releases |
| 114 | +units_graph = SammUnitsGraph() |
| 115 | +unit_data = units_graph.get_info("unit:volt") |
| 116 | +# {'preferredName': rdflib.term.Literal('volt', lang='en'), 'commonCode': rdflib.term.Literal('VLT'), ... } |
49 | 117 |
|
50 | | -### Possibility 2 (downloading from the repository) |
| 118 | +units_graph.print_description(unit_data) |
| 119 | +# preferredName: volt |
| 120 | +# commonCode: VLT |
| 121 | +# ... |
| 122 | +# symbol: V |
| 123 | +``` |
| 124 | + |
| 125 | +## SAMM CLI wrapper class |
| 126 | + |
| 127 | +The SAMM CLI is a command line tool provided number of functions for working with Aspect Models. |
51 | 128 |
|
52 | | -It may happen that there is no .jar file that is up to date with the changes of the SAMM. |
53 | | -This script is an alternative to the `download_samm_release.py` and extracts the files from the repository |
54 | | -directly instead of using the newest release. |
| 129 | +More detailed information about SAMM CLI functionality can be found in the |
| 130 | +[SAMM CLI documentation](https://eclipse-esmf.github.io/esmf-developer-guide/tooling-guide/samm-cli.html). |
55 | 131 |
|
56 | | -The script uses the GitHub API and downloads the files from the `main` branch. If the script is run in a |
57 | | -pipeline, it uses a GitHub token to authorize. If the script is run locally, the API is called without a token. |
58 | | -This may cause problems because unauthorized API calls are limited. |
| 132 | +Python Aspect Model Loader provide a wrapper class to be able to call SAMM CLI functions from the Python code. |
| 133 | +For instance, validation of a model can be done with the following code snippet: |
59 | 134 |
|
60 | | -This script can be executed with |
| 135 | +```python |
| 136 | +from esmf_aspect_meta_model_python.samm_cli_functions import SammCli |
61 | 137 |
|
| 138 | +samm_cli = SammCli() |
| 139 | +model_path = "Paht_to_the_model/Model.ttl" |
| 140 | +samm_cli.validate(model_path) |
| 141 | +# Input model is valid |
62 | 142 | ``` |
63 | | -poetry run download-samm-branch |
| 143 | + |
| 144 | +List of SAMMCLI functions: |
| 145 | +- validate |
| 146 | +- to_openapi |
| 147 | +- to_schema |
| 148 | +- to_json |
| 149 | +- to_html |
| 150 | +- to_png |
| 151 | +- to_svg |
| 152 | + |
| 153 | +# Scripts |
| 154 | + |
| 155 | +The Aspect Model Loader provide scripts for downloading some additional code and data. |
| 156 | +Provided scripts: |
| 157 | + - download-samm-release |
| 158 | + - download-samm-branch |
| 159 | + - download-samm-cli |
| 160 | + - download-test-models |
| 161 | + |
| 162 | +All scripts run like a poetry command. The poetry is available from the folder where [pyproject.toml](pyproject.toml) |
| 163 | +is located. |
| 164 | + |
| 165 | +# Automation Tasks |
| 166 | +## tox |
| 167 | + |
| 168 | +`tox` is used for the tests automation purpose. There are two environments with different purposes and tests can |
| 169 | +be running with the tox: |
| 170 | +- pep8: static code checks (PEP8 style) with MyPy and Black |
| 171 | +- py310: unit and integration tests |
| 172 | + |
| 173 | +```console |
| 174 | +# run all checks use the next command |
| 175 | +poetry run tox |
| 176 | + |
| 177 | +# run only pep8 checks |
| 178 | +poetry run tox -e pep8 |
| 179 | + |
| 180 | +# run tests |
| 181 | +poetry run tox -e py310 |
64 | 182 | ``` |
65 | | -to download and start working with the Aspect Model Loader. |
| 183 | + |
| 184 | +## GitHub actions |
| 185 | + |
| 186 | +There are two actions on the GitHub repo: |
| 187 | +- [Check New Pull Request](../../.github/workflows/push_request_check.yml) |
| 188 | +- [Build release](../../.github/workflows/tagged_release.yml) |
| 189 | + |
| 190 | +### Check New Pull Request |
| 191 | +This action run after creation or updating a pull request and run all automation tests with tox command. |
| 192 | + |
| 193 | +### Build release |
| 194 | +Prepare and publish a new release for the `esmf-aspect-model-loader` to the PyPi: |
| 195 | +[esmf-aspect-model-loader](https://pypi.org/project/esmf-aspect-model-loader/.) |
| 196 | + |
| 197 | +A list of the available releases on the GitHub: |
| 198 | +[Releases](https://github.com/eclipse-esmf/esmf-sdk-py-aspect-model-loader/releases). |
0 commit comments