Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3e2e028
Add mypy to pre-commit (and introduce data_types.py)
bramstoeller Jul 28, 2022
336809f
Add mypy to pre-commit (and introduce data_types.py)
bramstoeller Jul 28, 2022
19e9fe1
Merge branch 'feature/isort' into feature/mypy
bramstoeller Jul 28, 2022
77cb3e3
Add mypy explanation to CONTRIBUTING.md
bramstoeller Jul 28, 2022
dbb38ad
Add examples to the data_types
bramstoeller Jul 28, 2022
6152b67
Merge branch 'feature/isort' into feature/mypy
bramstoeller Jul 28, 2022
6df30e8
Use absolute imports
bramstoeller Jul 28, 2022
7667a01
Merge branch 'feature/mypy' of github.com:alliander-opensource/power-…
bramstoeller Jul 28, 2022
2f713db
Import TypeAlias from typing_extensions
bramstoeller Jul 28, 2022
f1bf169
Merge branch 'release/1.4' into feature/mypy
bramstoeller Jul 28, 2022
d531070
Fix TypeAlias issue for python 3.8
bramstoeller Jul 28, 2022
89fc152
Add pylint to pyproject.toml
bramstoeller Jul 28, 2022
a72b291
Merge branch 'release/1.4' into feature/mypy
bramstoeller Aug 2, 2022
a48a5d2
Make sure the SingleArray and DenseBatchArray are not constructable
bramstoeller Aug 2, 2022
5785caa
Rename manual_testing to file_io
bramstoeller Aug 2, 2022
4e9175f
Add code-quality checks to github workflow
bramstoeller Aug 2, 2022
f433e5c
import_input_data and import_update_data
bramstoeller Aug 2, 2022
eb7cd5c
Install power-grid-model before running pylint
bramstoeller Aug 2, 2022
929bcbd
Install power-grid-model before running pylint
bramstoeller Aug 2, 2022
788d0b7
Install power-grid-model before running pylint
bramstoeller Aug 2, 2022
7caa2bd
Remove module from import in __init__.py
bramstoeller Aug 2, 2022
596ecd5
inject_extra_info()
bramstoeller Aug 2, 2022
66716c2
Install pgm before pylint
bramstoeller Aug 2, 2022
f258bef
pylint power_grid_model
bramstoeller Aug 2, 2022
32607e7
Fix typo
bramstoeller Aug 3, 2022
8d58fe2
Run git diff in pipeline
bramstoeller Aug 3, 2022
1d9aff6
Restore README.md in pipeline
bramstoeller Aug 3, 2022
d9221df
Restore README.md in pipeline
bramstoeller Aug 3, 2022
cf584f8
Attempt to increase Sonar Cognitive Complexity
bramstoeller Aug 3, 2022
f9d00f2
Revert "Attempt to increase Sonar Cognitive Complexity"
bramstoeller Aug 3, 2022
09cb0e2
Merge utils
bramstoeller Aug 3, 2022
09770ce
Simplify update_input_data
bramstoeller Aug 3, 2022
de8dfe1
Simplify split_sparse_batches_in_batches
bramstoeller Aug 3, 2022
5eb51f9
Run isort black and mypy on root dir
bramstoeller Aug 3, 2022
931f624
Fix type hinting in setup.py
bramstoeller Aug 3, 2022
f3214ee
Use absolute imports in the base __init__.py file
bramstoeller Aug 4, 2022
85d1880
Use absolute imports in the base __init__.py file
bramstoeller Aug 4, 2022
05d34c5
Update isort config
bramstoeller Aug 4, 2022
4ab8537
Update code quality badge in readme
bramstoeller Aug 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@


# GitHub Action that uses
# Black to reformat the Python code in an incoming pull request.
# isort, black, mypy and pylint to reformat the Python code in an incoming pull request.
# clang-format to reformat the C++ code in an incoming pull request.
# If all code in the pull request is compliant with Black and clang-format then this Action
# does nothing. Otherwise, it will print the files which need to be reformatted and raise an error.

name: Format Code
name: Check Code Quality

on:
# run pipeline on push event of main or release branch
Expand All @@ -21,7 +21,7 @@ on:
pull_request:

jobs:
code-format-check:
check-code-quality:
if: (github.event_name == 'push') || (!startsWith(github.head_ref, 'release'))
runs-on: ubuntu-latest

Expand All @@ -33,23 +33,41 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Black and clang-format

- name: Upgrade pip
run: pip install --upgrade pip

- name: Install and run isort
run: |
pip install isort
isort .

- name: Install and run black
run: |
pip install black
sudo apt-get update && sudo apt-get install -y clang-format
black .

- name: Run black
run: black .
- name: Install and run mypy
run: |
pip install mypy
mypy .

- name: Install and run pylint
run: |
pip install pylint .
pylint power_grid_model
git restore README.md

- name: Run clang-format
run: find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;
- name: Install and run clang-format
run: |
sudo apt-get update && sudo apt-get install -y clang-format
find . -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec clang-format -style=file -i {} \;

- name: If needed raise error
run: |

if [[ `git status --porcelain --untracked-files=no` ]]; then
echo "Formatting not correct! See blow the files which need to be reformatted!"
echo "Formatting not correct! See below the files which need to be reformatted!"
git status --porcelain --untracked-files=no
exit 1
fi
Expand Down
7 changes: 6 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ repos:
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
- id: isort
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
hooks:
- id: mypy
files: ^(src|tests|scripts)/.+\.py$
- repo: local
hooks:
- id: pylint
Expand Down
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ corrections) to your code (style) before each commit. It is up to the developer
use this tool or not. The goal is to make sure that each commit will pass the quality checks in the github actions
workflow. Currently, these hooks are defined in [`.pre-commit-config.yaml`](.pre-commit-config.yaml):
* **reuse**: check if all licence headers and files are in place
* **isort**: sort import statements
* **black**: check and correct code style
* **pylint**: check code style
* **isort**: group and sort import statements
* **black**: check and correct code style in a very strict manner
* **mypy**: checks type hinting and data types in general (static type checker)
* **pylint**: check code style and comments
* **pytest**: run all unit tests

You can manually run pre-commit whenever you like:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-License-Identifier: MPL-2.0
[![PyPI version](https://badge.fury.io/py/power-grid-model.svg)](https://badge.fury.io/py/power-grid-model)
[![License: MIT](https://img.shields.io/badge/License-MPL2.0-informational.svg)](https://github.com/alliander-opensource/power-grid-model/blob/main/LICENSE)
[![Build and Test C++ and Python](https://github.com/alliander-opensource/power-grid-model/actions/workflows/main.yml/badge.svg)](https://github.com/alliander-opensource/power-grid-model/actions/workflows/main.yml)
[![Format Code](https://github.com/alliander-opensource/power-grid-model/actions/workflows/black-and-clang-format.yml/badge.svg)](https://github.com/alliander-opensource/power-grid-model/actions/workflows/black-and-clang-format.yml)
[![Check Code Quality](https://github.com/alliander-opensource/power-grid-model/actions/workflows/check-code-quality.yml/badge.svg)](https://github.com/alliander-opensource/power-grid-model/actions/workflows/check-code-quality.yml)
[![REUSE Compliance Check](https://github.com/alliander-opensource/power-grid-model/actions/workflows/reuse-compliance.yml/badge.svg)](https://github.com/alliander-opensource/power-grid-model/actions/workflows/reuse-compliance.yml)

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=alliander-opensource_power-grid-model&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=alliander-opensource_power-grid-model)
Expand Down
2 changes: 1 addition & 1 deletion docs/python-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The Python API consists of the following components:
This is a pure Python module.
* `power_grid_model.PowerGridModel`: the main class.
This is inside a C++ extension module.
* `power_grid_model.manual_testing`: containing the functions for load and save test dataset.
* `power_grid_model.utils`: containing the functions for load and save test dataset.
See [Make Test Dataset](../examples/Make%20Test%20Dataset.ipynb) for examples of how to make test datasets.
* `power_grid_model.validation`: optional validation and assertion functions.
See [Validation Examples](../examples/Validation%20Examples.ipynb) for more information on how to validate input
Expand Down
8 changes: 4 additions & 4 deletions examples/Make Test Dataset.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@
"source": [
"# Helper Functions to Import and Export\n",
"\n",
"In the module `power_grid_model.manual_testing` we have some helper functions to import a json file to a `power-grid-model` compatible dataset, or the other way around. \n",
"In the module `power_grid_model.utils` we have some helper functions to import a json file to a `power-grid-model` compatible dataset, or the other way around. \n",
"\n",
"Please refer to the [source code](../src/power_grid_model/manual_testing.py) for detailed function signature.\n",
"Please refer to the [source code](../src/power_grid_model/utils.py) for detailed function signature.\n",
"\n",
"In this notebook we export the example network from [Power Flow](./Power%20Flow%20Example.ipynb) to json. "
]
Expand Down Expand Up @@ -422,7 +422,7 @@
"metadata": {},
"outputs": [],
"source": [
"from power_grid_model.manual_testing import export_json_data\n",
"from power_grid_model.utils import export_json_data\n",
"import tempfile\n",
"from pathlib import Path\n",
"\n",
Expand Down Expand Up @@ -560,7 +560,7 @@
"source": [
"# round trip and run power flow\n",
"\n",
"from power_grid_model.manual_testing import import_json_data\n",
"from power_grid_model.utils import import_json_data\n",
"\n",
"imported_data = import_json_data(temp_path / \"input.json\", \"input\")\n",
"\n",
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dynamic = ["version"]
[project.optional-dependencies]
dev = [
"pre-commit",
"pylint",
"pytest",
"pytest-cov",
]
Expand All @@ -69,8 +70,15 @@ line-length = 120
target-version = ['py38']

[tool.isort]
src_paths = ["src", "tests/unit", "scripts"]
profile = "black"
line_length = 120

[tool.pylint]
max-line-length = 120

[tool.mypy]
follow_imports = "silent"
ignore_missing_imports = true
show_column_numbers = true
non_interactive = true
install_types = true
14 changes: 4 additions & 10 deletions scripts/validate_batch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@
# SPDX-License-Identifier: MPL-2.0

from pathlib import Path
from typing import cast

from power_grid_model import CalculationType
from power_grid_model.manual_testing import import_json_data
from power_grid_model.validation import (
InputData,
UpdateData,
errors_to_string,
validate_batch_data,
)
from power_grid_model.utils import import_input_data, import_update_data
from power_grid_model.validation import errors_to_string, validate_batch_data

input_file = Path("../tests/data/power_flow/dummy-test-batch/input.json")
update_file = Path("../tests/data/power_flow/dummy-test-batch/update_batch.json")

input_data = cast(InputData, import_json_data(json_file=input_file, data_type="input"))
update_data = cast(UpdateData, import_json_data(json_file=update_file, data_type="update"))
input_data = import_input_data(json_file=input_file)
update_data = import_update_data(json_file=update_file)

update_errors = validate_batch_data(
input_data=input_data, update_data=update_data, calculation_type=CalculationType.power_flow, symmetric=True
Expand Down
7 changes: 3 additions & 4 deletions scripts/validate_input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
# SPDX-License-Identifier: MPL-2.0

from pathlib import Path
from typing import cast

from power_grid_model import CalculationType
from power_grid_model.manual_testing import import_json_data
from power_grid_model.validation import InputData, errors_to_string, validate_input_data
from power_grid_model.utils import import_input_data
from power_grid_model.validation import errors_to_string, validate_input_data

input_file = Path("../tests/data/state_estimation/dummy-test-sym/input.json")

input_data = cast(InputData, import_json_data(json_file=input_file, data_type="input"))
input_data = import_input_data(json_file=input_file)

input_errors = validate_input_data(
input_data=input_data, calculation_type=CalculationType.state_estimation, symmetric=True
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from itertools import chain
from pathlib import Path
from sysconfig import get_paths
from typing import List

# noinspection PyPackageRequirements
import Cython.Compiler.Main as CythonCompiler
Expand Down Expand Up @@ -88,10 +89,10 @@ def generate_build_ext(pkg_dir: Path, pkg_name: str):
str(pkg_dir / "include"), # The include-folder of the repo self
]
# compiler and link flag
cflags = []
lflags = []
library_dirs = []
libraries = []
cflags: List[str] = []
lflags: List[str] = []
library_dirs: List[str] = []
libraries: List[str] = []
# macro
define_macros = [
("EIGEN_MPL2_ONLY", "1"), # only MPL-2 part of eigen3
Expand Down
4 changes: 2 additions & 2 deletions src/power_grid_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

# pylint: disable=no-name-in-module

from ._power_grid_core import PowerGridModel, initialize_array, power_grid_meta_data
from .enum import (
from power_grid_model._power_grid_core import PowerGridModel, initialize_array, power_grid_meta_data
from power_grid_model.enum import (
BranchSide,
CalculationMethod,
CalculationType,
Expand Down
Loading