From 1d0e27f206c8b85f5f1422ee61333148f1d3c325 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Mon, 1 Jul 2024 15:34:57 +0200 Subject: [PATCH 01/13] Updated generated file strings Signed-off-by: Santiago Figueroa --- .../power_grid_model_c/src/dataset_class_maps.cpp.jinja | 2 +- .../power_grid_model_c/src/dataset_definitions.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code_generation/templates/power_grid_model_c/power_grid_model_c/src/dataset_class_maps.cpp.jinja b/code_generation/templates/power_grid_model_c/power_grid_model_c/src/dataset_class_maps.cpp.jinja index ff9ff3b7d..ed849f3db 100644 --- a/code_generation/templates/power_grid_model_c/power_grid_model_c/src/dataset_class_maps.cpp.jinja +++ b/code_generation/templates/power_grid_model_c/power_grid_model_c/src/dataset_class_maps.cpp.jinja @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MPL-2.0 -// This header file is automatically generated. DO NOT modify it manually! +// This file is automatically generated. DO NOT modify it manually! // clang-format off diff --git a/power_grid_model_c/power_grid_model_c/src/dataset_definitions.cpp b/power_grid_model_c/power_grid_model_c/src/dataset_definitions.cpp index 70bd343b9..52951134e 100644 --- a/power_grid_model_c/power_grid_model_c/src/dataset_definitions.cpp +++ b/power_grid_model_c/power_grid_model_c/src/dataset_definitions.cpp @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MPL-2.0 -// This header file is automatically generated. DO NOT modify it manually! +// This file is automatically generated. DO NOT modify it manually! // clang-format off From 2a955df1952a372e2d15a0142fe9fa50e32b91fe Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Mon, 1 Jul 2024 17:20:14 +0200 Subject: [PATCH 02/13] Workflow for code generation Signed-off-by: Santiago Figueroa --- .github/workflows/check-generated-code.yml | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/check-generated-code.yml diff --git a/.github/workflows/check-generated-code.yml b/.github/workflows/check-generated-code.yml new file mode 100644 index 000000000..222a83081 --- /dev/null +++ b/.github/workflows/check-generated-code.yml @@ -0,0 +1,66 @@ +# SPDX-FileCopyrightText: Contributors to the Power Grid Model project +# +# SPDX-License-Identifier: MPL-2.0 + +name: Check Generated Code + +on: + # run pipeline on push event of main branch + push: + branches: + - main + paths: + - code_generation/** + - .github/workflows/* + - power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/** + - power_grid_model_c/power_grid_model_c/** + - src/power_grid_model/core/** + - pyproject.toml + # run pipeline on pull request + pull_request: + paths: + - code_generation/** + - .github/workflows/* + - power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/** + - power_grid_model_c/power_grid_model_c/** + - src/power_grid_model/core/** + - pyproject.toml + # run pipeline on merge queue + merge_group: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-generated-code: + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 + + - name: Install dependencies + run: | + pip install --upgrade pip + pip install -r code_generation/requirements.txt + + - name: Generate code + run: python code_generation/code_gen.py + + - name: Check generated code + run: | + if [ -n "$git status --porcelain" ]; then + echo "The following files are outdated or were manually updated:" + git status --porcelain + exit 1 + else + echo "All the generated files are up to date." + fi + \ No newline at end of file From e4d54427fc6242c270d03925f128112aabc01c82 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Mon, 1 Jul 2024 17:30:09 +0200 Subject: [PATCH 03/13] Fixed typo Signed-off-by: Santiago Figueroa --- .github/workflows/check-generated-code.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-generated-code.yml b/.github/workflows/check-generated-code.yml index 222a83081..f611ab2a5 100644 --- a/.github/workflows/check-generated-code.yml +++ b/.github/workflows/check-generated-code.yml @@ -56,7 +56,7 @@ jobs: - name: Check generated code run: | - if [ -n "$git status --porcelain" ]; then + if [ -n "$(git status --porcelain)" ]; then echo "The following files are outdated or were manually updated:" git status --porcelain exit 1 From aeff8af046a1b6751a54b6f1268c3b3243ad85c5 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 09:05:55 +0200 Subject: [PATCH 04/13] Check generated code moved into check-code-quality action Signed-off-by: Santiago Figueroa --- .github/workflows/check-code-quality.yml | 12 ++++ .github/workflows/check-generated-code.yml | 66 ---------------------- 2 files changed, 12 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/check-generated-code.yml diff --git a/.github/workflows/check-code-quality.yml b/.github/workflows/check-code-quality.yml index 85aabd328..4c6f93f77 100644 --- a/.github/workflows/check-code-quality.yml +++ b/.github/workflows/check-code-quality.yml @@ -75,3 +75,15 @@ jobs: git status --porcelain --untracked-files=no exit 1 fi + + - name: Check generated code + run: | + pip install -r code_generation/requirements.txt + python code_generation/code_gen.py + if [ -n "$(git status --porcelain)" ]; then + echo "The following files are outdated or were manually updated:" + git status --porcelain + exit 1 + else + echo "All the generated files are up to date." + fi \ No newline at end of file diff --git a/.github/workflows/check-generated-code.yml b/.github/workflows/check-generated-code.yml deleted file mode 100644 index f611ab2a5..000000000 --- a/.github/workflows/check-generated-code.yml +++ /dev/null @@ -1,66 +0,0 @@ -# SPDX-FileCopyrightText: Contributors to the Power Grid Model project -# -# SPDX-License-Identifier: MPL-2.0 - -name: Check Generated Code - -on: - # run pipeline on push event of main branch - push: - branches: - - main - paths: - - code_generation/** - - .github/workflows/* - - power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/** - - power_grid_model_c/power_grid_model_c/** - - src/power_grid_model/core/** - - pyproject.toml - # run pipeline on pull request - pull_request: - paths: - - code_generation/** - - .github/workflows/* - - power_grid_model_c/power_grid_model/include/power_grid_model/auxiliary/** - - power_grid_model_c/power_grid_model_c/** - - src/power_grid_model/core/** - - pyproject.toml - # run pipeline on merge queue - merge_group: - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - check-generated-code: - - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.9 - - - name: Install dependencies - run: | - pip install --upgrade pip - pip install -r code_generation/requirements.txt - - - name: Generate code - run: python code_generation/code_gen.py - - - name: Check generated code - run: | - if [ -n "$(git status --porcelain)" ]; then - echo "The following files are outdated or were manually updated:" - git status --porcelain - exit 1 - else - echo "All the generated files are up to date." - fi - \ No newline at end of file From 9ef8898070f2c440c3caf9d4bd80bcac50a0d652 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 10:19:01 +0200 Subject: [PATCH 05/13] Changed logic to only check files related to code generation. Signed-off-by: Santiago Figueroa --- .github/workflows/check-code-quality.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check-code-quality.yml b/.github/workflows/check-code-quality.yml index 4c6f93f77..6e1dc6d8c 100644 --- a/.github/workflows/check-code-quality.yml +++ b/.github/workflows/check-code-quality.yml @@ -78,11 +78,13 @@ jobs: - name: Check generated code run: | + status_before=$(git status --porcelain) pip install -r code_generation/requirements.txt python code_generation/code_gen.py - if [ -n "$(git status --porcelain)" ]; then + status_after=$(git status --porcelain) + if [ "$status_before" != "$status_after" ]; then echo "The following files are outdated or were manually updated:" - git status --porcelain + diff <(echo "$status_before") <(echo "$status_after") | grep '^[<>]' exit 1 else echo "All the generated files are up to date." From f8367a51fe2c8839c0016edcf29dafffc498dbb2 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 11:31:42 +0200 Subject: [PATCH 06/13] Simplified logic Signed-off-by: Santiago Figueroa --- .github/workflows/check-code-quality.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check-code-quality.yml b/.github/workflows/check-code-quality.yml index 6e1dc6d8c..f38f6c32c 100644 --- a/.github/workflows/check-code-quality.yml +++ b/.github/workflows/check-code-quality.yml @@ -77,14 +77,13 @@ jobs: fi - name: Check generated code + if: success() run: | - status_before=$(git status --porcelain) pip install -r code_generation/requirements.txt python code_generation/code_gen.py - status_after=$(git status --porcelain) - if [ "$status_before" != "$status_after" ]; then + if [ -n "$(git status --porcelain)" ]; then echo "The following files are outdated or were manually updated:" - diff <(echo "$status_before") <(echo "$status_after") | grep '^[<>]' + git status --porcelain exit 1 else echo "All the generated files are up to date." From a8d1ad563edb50be32b41e6bd1b1e01e999acd6c Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 12:06:01 +0200 Subject: [PATCH 07/13] EOF whitespace Signed-off-by: Santiago Figueroa --- .github/workflows/check-code-quality.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-code-quality.yml b/.github/workflows/check-code-quality.yml index f38f6c32c..369a33308 100644 --- a/.github/workflows/check-code-quality.yml +++ b/.github/workflows/check-code-quality.yml @@ -87,4 +87,5 @@ jobs: exit 1 else echo "All the generated files are up to date." - fi \ No newline at end of file + fi + \ No newline at end of file From ddb03c6c5bff5216571e7cb00fb9d8bae1127110 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 12:14:06 +0200 Subject: [PATCH 08/13] Test: Not run on formatting issues Signed-off-by: Santiago Figueroa --- src/power_grid_model/__init__.py | 3 +++ src/power_grid_model/enum.py | 1 + 2 files changed, 4 insertions(+) diff --git a/src/power_grid_model/__init__.py b/src/power_grid_model/__init__.py index 605f0deeb..44dc326ab 100644 --- a/src/power_grid_model/__init__.py +++ b/src/power_grid_model/__init__.py @@ -6,7 +6,10 @@ from power_grid_model.core.dataset_definitions import ComponentType, DatasetType from power_grid_model.core.power_grid_meta import initialize_array, power_grid_meta_data + from power_grid_model.core.power_grid_model import PowerGridModel + + from power_grid_model.enum import ( Branch3Side, BranchSide, diff --git a/src/power_grid_model/enum.py b/src/power_grid_model/enum.py index 75b8df54f..c956211b6 100644 --- a/src/power_grid_model/enum.py +++ b/src/power_grid_model/enum.py @@ -105,6 +105,7 @@ class MeasuredTerminalType(IntEnum): """ shunt = 3 """ + Measuring the terminal between a shunt and a node """ load = 4 From 520c6a5fb5a08261ae84380cddf18e580fe87b88 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 12:19:06 +0200 Subject: [PATCH 09/13] Test: Run and failing on changed template Signed-off-by: Santiago Figueroa --- .../src/power_grid_model/core/dataset_class_maps.py.jinja | 2 +- src/power_grid_model/__init__.py | 3 --- src/power_grid_model/enum.py | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja b/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja index 4fa699669..f23486fd0 100644 --- a/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja +++ b/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja @@ -62,7 +62,7 @@ class ComponentType(str, Enum): def _str_to_datatype(data_type: Any) -> DatasetType: - """Helper function to transform data_type str to DatasetType.""" + """Helper function to transform data_type str to DatasetType. Testing!""" if isinstance(data_type, str): return DatasetType[data_type] return data_type diff --git a/src/power_grid_model/__init__.py b/src/power_grid_model/__init__.py index 44dc326ab..605f0deeb 100644 --- a/src/power_grid_model/__init__.py +++ b/src/power_grid_model/__init__.py @@ -6,10 +6,7 @@ from power_grid_model.core.dataset_definitions import ComponentType, DatasetType from power_grid_model.core.power_grid_meta import initialize_array, power_grid_meta_data - from power_grid_model.core.power_grid_model import PowerGridModel - - from power_grid_model.enum import ( Branch3Side, BranchSide, diff --git a/src/power_grid_model/enum.py b/src/power_grid_model/enum.py index c956211b6..75b8df54f 100644 --- a/src/power_grid_model/enum.py +++ b/src/power_grid_model/enum.py @@ -105,7 +105,6 @@ class MeasuredTerminalType(IntEnum): """ shunt = 3 """ - Measuring the terminal between a shunt and a node """ load = 4 From 754f9d155e79f012cd1465ac1b351b5883c344b1 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 12:23:15 +0200 Subject: [PATCH 10/13] Test: Run and failing on changed generated file. Signed-off-by: Santiago Figueroa --- .../src/power_grid_model/core/dataset_class_maps.py.jinja | 2 +- src/power_grid_model/core/dataset_definitions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja b/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja index f23486fd0..4fa699669 100644 --- a/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja +++ b/code_generation/templates/src/power_grid_model/core/dataset_class_maps.py.jinja @@ -62,7 +62,7 @@ class ComponentType(str, Enum): def _str_to_datatype(data_type: Any) -> DatasetType: - """Helper function to transform data_type str to DatasetType. Testing!""" + """Helper function to transform data_type str to DatasetType.""" if isinstance(data_type, str): return DatasetType[data_type] return data_type diff --git a/src/power_grid_model/core/dataset_definitions.py b/src/power_grid_model/core/dataset_definitions.py index d8f0c2a93..278237fcf 100644 --- a/src/power_grid_model/core/dataset_definitions.py +++ b/src/power_grid_model/core/dataset_definitions.py @@ -46,7 +46,7 @@ class DatasetType(str, Enum, metaclass=_MetaEnum): class ComponentType(str, Enum): """ - A ComponentType is the type of a grid component. + A ComponentType is the type of a grid component. Testing! - Examples: From 3e930018ba6095eda10b59978a40075cca11ec9e Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 12:27:05 +0200 Subject: [PATCH 11/13] Test: Run and failing on changed code generator Signed-off-by: Santiago Figueroa --- code_generation/code_gen.py | 2 +- src/power_grid_model/core/dataset_definitions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code_generation/code_gen.py b/code_generation/code_gen.py index 32ec49a3d..e1e7169a9 100644 --- a/code_generation/code_gen.py +++ b/code_generation/code_gen.py @@ -104,7 +104,7 @@ def render_dataset_class_maps(self, template_path: Path, data_path: Path, output all_map = {} for dataset in dataset_meta_data: if dataset.is_template: - prefixes = ["sym_", "asym_"] + prefixes = ["sym_"] else: prefixes = [""] for prefix in prefixes: diff --git a/src/power_grid_model/core/dataset_definitions.py b/src/power_grid_model/core/dataset_definitions.py index 278237fcf..d8f0c2a93 100644 --- a/src/power_grid_model/core/dataset_definitions.py +++ b/src/power_grid_model/core/dataset_definitions.py @@ -46,7 +46,7 @@ class DatasetType(str, Enum, metaclass=_MetaEnum): class ComponentType(str, Enum): """ - A ComponentType is the type of a grid component. Testing! + A ComponentType is the type of a grid component. - Examples: From 9c40f587e3e07dc1fb0dde7e5fad429236c5b237 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 12:32:37 +0200 Subject: [PATCH 12/13] Run and passing: all up to date Signed-off-by: Santiago Figueroa --- code_generation/code_gen.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code_generation/code_gen.py b/code_generation/code_gen.py index e1e7169a9..32ec49a3d 100644 --- a/code_generation/code_gen.py +++ b/code_generation/code_gen.py @@ -104,7 +104,7 @@ def render_dataset_class_maps(self, template_path: Path, data_path: Path, output all_map = {} for dataset in dataset_meta_data: if dataset.is_template: - prefixes = ["sym_"] + prefixes = ["sym_", "asym_"] else: prefixes = [""] for prefix in prefixes: From 3820052c7d6d3a840383c167ceef1da502fdec30 Mon Sep 17 00:00:00 2001 From: Santiago Figueroa Date: Tue, 2 Jul 2024 14:55:10 +0200 Subject: [PATCH 13/13] Message formatting Signed-off-by: Santiago Figueroa --- .github/workflows/check-code-quality.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-code-quality.yml b/.github/workflows/check-code-quality.yml index 369a33308..dc3c5a0d8 100644 --- a/.github/workflows/check-code-quality.yml +++ b/.github/workflows/check-code-quality.yml @@ -82,10 +82,11 @@ jobs: pip install -r code_generation/requirements.txt python code_generation/code_gen.py if [ -n "$(git status --porcelain)" ]; then + echo echo "The following files are outdated or were manually updated:" git status --porcelain exit 1 else + echo echo "All the generated files are up to date." fi - \ No newline at end of file