Skip to content

Commit

Permalink
Consistency improvements and linting (#1)
Browse files Browse the repository at this point in the history
## Description

Consistency improvements and linting

## Changes Made

* Lint Markdown
* Ling Dockerfile
* Uniform argument management
* Manage dependencies using poetry

## Related Issues

N/A

## Checklist

- [x] I have used a PR title that is descriptive enough for a release
note.
- [x] I have tested these changes locally.
- [x] I have added appropriate tests or updated existing tests.
- [ ] I have tested these changes on a dedicated VM or a customer VM
[name of the VM]
- [x] I have added appropriate documentation or updated existing
documentation.

Signed-off-by: Federico M. Facca <federico.facca@zaphiro.ch>
  • Loading branch information
chicco785 committed Jul 28, 2023
1 parent da4e952 commit 1d90620
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ endif()
message(STATUS "Using output folder: ${CGMES_OUTPUT_FOLDER}")
set(SCHEMA_FOLDER "${CMAKE_CURRENT_SOURCE_DIR}/cgmes_schema/${USE_CIM_VERSION}")
find_package (Python COMPONENTS Interpreter)
execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/build.py ${CGMES_OUTPUT_FOLDER} ${SCHEMA_FOLDER} ${CIM_OUTPUT_LANG})
execute_process(WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/build.py --outdir=${CGMES_OUTPUT_FOLDER} --schemadir=${SCHEMA_FOLDER} --langdir=${CIM_OUTPUT_LANG})
unset(SCHEMA_FOLDER)

28 changes: 13 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from alpine
run apk update
run apk add python3 git py3-pip py3-lxml file
run pip3 install --upgrade pip
run pip3 install xmltodict chevron
FROM alpine
RUN apk update
RUN apk add python3 git py3-pip py3-lxml file
RUN pip3 install --upgrade pip
RUN pip3 install xmltodict chevron

copy cpp/ /CIMgen/cpp/
copy java/ /CIMgen/java/
copy javascript/ /CIMgen/javascript/
copy javascript_react/ /CIMgen/javascript_react/
copy python/ /CIMgen/python/
copy CIMgen.py build.py /CIMgen/
copy CIMgen.py build.py /CIMgen/
workdir /CIMgen
entrypoint [ "/usr/bin/python3", "build.py", "/cgmes_output", "/cgmes_schema" ]
cmd [ "cpp" ]
COPY cpp/ /CIMgen/cpp/
COPY java/ /CIMgen/java/
COPY javascript/ /CIMgen/javascript/
COPY python/ /CIMgen/python/
COPY CIMgen.py build.py /CIMgen/
WORKDIR /CIMgen
ENTRYPOINT [ "/usr/bin/python3", "build.py", "--outdir=/cgmes_output", "--schemadir=/cgmes_schema" ]
CMD [ "--langdir=cpp" ]
61 changes: 37 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Python tool for code generation from CIM data model for several programming languages

## Concept overview
## Concept overview

![Overview CIMgen](documentation/images/CIMgen.svg)

Expand All @@ -13,50 +13,63 @@ Python tool for code generation from CIM data model for several programming lang
#### Generating C++ files on Linux (Ubuntu)

```bash
$ sudo apt install python
$ pip3 install xmltodict chevron cmake
$ cmake -P .
sudo apt install python
curl -sSL https://install.python-poetry.org | python3 - # install poetry
poetry install --no-root # install dependencies
poetry run cmake -P CMakeLists.txt
```

This will build version CGMES_2.4.15_27JAN2020 in the subfolder with the same name.

If you wish to build an alternative version, you can see available options in the subfolder called cgmes_schema.

They can be built using a cmake variable:

```
$ cmake -DUSE_CIM_VERSION=CGMES_2.4.15_16FEB2016 -P .
```bash
poetry run cmake -DUSE_CIM_VERSION=CGMES_2.4.15_16FEB2016 -P CMakeLists.txt
```

#### Generating C++ files in a Docker container

```bash
$ docker build -t cimgen -f Dockerfile .
$ export OUTPUT_DIR=$(pwd)/CGMES_2.4.15_27JAN2020_cpp
$ export SCHEMA_DIR=$(pwd)/cgmes_schema/CGMES_2.4.15_27JAN2020
$ docker run -v ${OUTPUT_DIR}:/cgmes_output -v ${SCHEMA_DIR}:/cgmes_schema cimgen
docker build -t cimgen -f Dockerfile .
export OUTPUT_DIR=$(pwd)/CGMES_2.4.15_27JAN2020_cpp
export SCHEMA_DIR=$(pwd)/cgmes_schema/CGMES_2.4.15_27JAN2020
docker run -v ${OUTPUT_DIR}:/cgmes_output -v ${SCHEMA_DIR}:/cgmes_schema cimgen
```

### Generating Python files

#### Generating Python files on Linux

```bash
$ sudo apt install python
$ pip3 install xmltodict chevron
$ export OUTPUT_DIR=$(pwd)/CGMES_2.4.15_27JAN2020_python
$ export SCHEMA_DIR=$(pwd)/cgmes_schema/CGMES_2.4.15_27JAN2020
$ ./build.py ${OUTPUT_DIR} ${SCHEMA_DIR} python
OUTPUT_DIR can be set to whichever absolute path you wish to create the files in.
If you wish to build an alternative version, you can see available options in the subfolder called cgmes_schema
sudo apt install python
pip3 install xmltodict chevron
export OUTPUT_DIR=$(pwd)/CGMES_2.4.15_27JAN2020_python
export SCHEMA_DIR=$(pwd)/cgmes_schema/CGMES_2.4.15_27JAN2020
./build.py --outdir=${OUTPUT_DIR} --schemadir=${SCHEMA_DIR} --langdir=python
```

`OUTPUT_DIR` can be set to whichever absolute path you wish to create the files
in.
If you wish to build an alternative version, you can see available options in
the subfolder called cgmes_schema

#### Generating Python files in a Docker container
```
$ docker build -t cimgen -f Dockerfile .
$ export OUTPUT_DIR=$(pwd)/CGMES_2.4.15_27JAN2020_python
$ export SCHEMA_DIR=$(pwd)/cgmes_schema/CGMES_2.4.15_27JAN2020
$ docker run -v ${OUTPUT_DIR}:/cgmes_output -v ${SCHEMA_DIR}:/cgmes_schema cimgen python

```bash
docker build -t cimgen -f Dockerfile .
export OUTPUT_DIR=$(pwd)/CGMES_2.4.15_27JAN2020_python
export SCHEMA_DIR=$(pwd)/cgmes_schema/CGMES_2.4.15_27JAN2020
docker run -v ${OUTPUT_DIR}:/cgmes_output -v ${SCHEMA_DIR}:/cgmes_schema cimgen --langdir=python
```

## Publications

If you are using CIMgen for your research, please cite the following paper in your publications:
If you are using CIMgen for your research, please cite the following paper in
your publications:

Dinkelbach, J., Razik, L., Mirz, M., Benigni, A., Monti, A.: Template-based generation of programming language specific code for smart grid modelling compliant with CIM and CGMES.
Dinkelbach, J., Razik, L., Mirz, M., Benigni, A., Monti, A.: Template-based
generation of programming language specific code for smart grid modelling
compliant with CIM and CGMES.
J. Eng. 2023, 1–13 (2022). [https://doi.org/10.1049/tje2.12208](https://doi.org/10.1049/tje2.12208)
6 changes: 3 additions & 3 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import importlib

parser = argparse.ArgumentParser(description='Generate some CIM classes.')
parser.add_argument('outdir', type=str, help='The output directory')
parser.add_argument('schemadir', type=str, help='The schema directory')
parser.add_argument('langdir', type=str, help='The langpack directory')
parser.add_argument('--outdir', type=str, help='The output directory', required=True)
parser.add_argument('--schemadir', type=str, help='The schema directory', required=True)
parser.add_argument('--langdir', type=str, help='The langpack directory', required=True)
parser.add_argument('--cgmes_version', type=str, choices=['cgmes_v2_4_13', 'cgmes_v2_4_15', 'cgmes_v3_0_0'], default='cgmes_v2_4_15', help='CGMES Version')
args = parser.parse_args()

Expand Down
57 changes: 57 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "cimgen"
version = "0.1.0"
description = "Code generation from CIM data model for several programming languages"
authors = []
license = "Apache License 2.0"
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
xmltodict = "^0.13.0"
chevron = "^0.14.0"
cmake = "^3.27.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 1d90620

Please sign in to comment.