Skip to content

Commit

Permalink
Merge branch 'alliander-opensource:main' into Add-attribution-to-READ…
Browse files Browse the repository at this point in the history
…ME.md
  • Loading branch information
Jonasvdbo authored Nov 22, 2023
2 parents 16f533e + f6bd88c commit 4c36d8c
Show file tree
Hide file tree
Showing 538 changed files with 20,424 additions and 13,942 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,9 @@ jobs:
- name: scons ruff
if: ${{ ! inputs._SKIP_QUALITY }}
run: poetry run scons ruff check
- name: scons pylint
- name: scons type
if: ${{ ! inputs._SKIP_QUALITY }}
run: poetry run scons pylint
- name: scons mypy
if: ${{ ! inputs._SKIP_QUALITY }}
run: poetry run scons mypy
run: poetry run scons type
- name: scons tests
if: ${{ ! inputs._SKIP_QUALITY }}
run: poetry run scons tests
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ the work. For more information see the Code review guideline.

## Style guide

We use black, pylint, ruff, mypy, pytest and coverage to enforce good quality.
We use black, ruff, pyright, pytest and coverage to enforce good quality.
They are all checked via Github actions, and can be run locally (after installing the
dev dependency of the project) with `scons all`. Look at the [workflow](.github/workflows/_core.yaml) to see the specific steps.

Expand Down
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ If this is a leaf node (for instance `ACLineSegment`), it "just works". If you w
class higher in the hierarchy (for instance `Equipment`) there is a lot more work to do.

```python
@dataclass(config=DataclassConfig)
@dataclass
class CustomBay(Bay):
colour: str = Field(
default="Red",
Expand Down Expand Up @@ -98,15 +98,15 @@ class CustomProfile(BaseProfile):
And use it everywhere you would use a profile:

```python
from pycgmes.utils.dataclassconfig import DataclassConfig

@dataclass(config=DataclassConfig)
@dataclass
class CustomBayAttr(Bay):
colour: str = Field(
default="Red",
in_profiles=[
CustomProfile.CUS,
],
json_schema_extra={
"in_profiles": [
CustomProfile.CUS,
],
}
)

# And for instance:
Expand All @@ -124,10 +124,9 @@ In the case of a custom attribute defined via a sub class, the result would be:
from pydantic.dataclasses import dataclass

from pycgmes.resources.ACLineSegment import ACLineSegment
from pycgmes.utils.dataclassconfig import DataclassConfig


@dataclass(config=DataclassConfig)
@dataclass
class ACLineSegmentCustom(ACLineSegment):
@classmethod
def apparent_name(cls):
Expand Down Expand Up @@ -157,28 +156,31 @@ from pydantic.dataclasses import dataclass
from pydantic import Field

from pycgmes.resources import ACLineSegment
from pycgmes.resources.Base import DataclassConfig, Profile


@dataclass(config=DataclassConfig)
@dataclass
class ACLineSegmentCustom(ACLineSegment):
colour: str = Field(
default="Red",
in_profiles=[
Profile.EQ, # Do not do this, see chapter "create a new profile"
],
namespace="custom",
json_schema_extra={
"in_profiles": [
Profile.EQ, # Do not do this, see chapter "create a new profile"
],
"namespace": "custom",
},
)

size: str = Field(
default="Big",
in_profiles=[
Profile.EQ, # Do not do this, see chapter "create a new profile"
],
json_schema_extra={
"in_profiles": [
Profile.EQ, # Do not do this, see chapter "create a new profile"
],
}
)

@property
def namesapce(self) -> str:
def namespace(self) -> str:
return "custom ns class"

@classmethod
Expand Down Expand Up @@ -225,7 +227,7 @@ Generated from the modernpython serialisation of [cimgen](https://github.com/sog

The CI happens in GitHub actions.

The standard black/mypy/autoflake/isort/pylint/ruff/mypy are run there, via scons.
The standard black/pyright/ruff are run there, via scons.

### CD

Expand Down
22 changes: 11 additions & 11 deletions SConstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# SPDX-License-Identifier: Apache-2.0

import os
import subprocess # nosec
import sys
from typing import Mapping
Expand Down Expand Up @@ -39,7 +40,7 @@ def _exec(command: str, env: Mapping | None = None) -> int:
COMMAND_LINE_TARGETS += ["black", "ruff"]

if "quality" in COMMAND_LINE_TARGETS:
COMMAND_LINE_TARGETS += ["ruff", "lock", "pylint", "mypy", "test", "coverage", "license"]
COMMAND_LINE_TARGETS += ["ruff", "lock", "type", "test", "coverage", "license"]

# Formatting targets, which might change files. Let's run them *before* the linters and friends.
# This is why ruff is the first of the quality target, as it fixes things as well.
Expand All @@ -57,28 +58,25 @@ def _exec(command: str, env: Mapping | None = None) -> int:
# A lot are adding during generation because due to comments, some lines can be too long. They do not all
# end up being too long, so let's clean up the not relevant one.
cmd = f"ruff {_SUBJECT} {param}"
# Tries to fix what it can, forget about the rest.
cmd_test = f"ruff {_TEST_SUBJECT} --fix-only"
if _CHECK_ONLY:
cmd += " --no-fix"
cmd_test += " --no-fix"
else:
cmd += " --fix"
_exec(cmd)
_exec(cmd, env=os.environ)
_exec(cmd_test, env=os.environ)


if "lock" in COMMAND_LINE_TARGETS:
_exec("poetry check --lock")

if "pylint" in COMMAND_LINE_TARGETS or "lint" in COMMAND_LINE_TARGETS:
_exec(f"pylint --rcfile=pyproject.toml {_SUBJECT}")


if "mypy" in COMMAND_LINE_TARGETS:
# https://mypy.readthedocs.io/en/stable/running_mypy.html#library-stubs-not-installed
_exec(f"mypy {_SUBJECT}")
if "type" in COMMAND_LINE_TARGETS or "pyright" in COMMAND_LINE_TARGETS:
_exec("pyright", env=os.environ)
_target_found = True

if "bandit" in COMMAND_LINE_TARGETS:
# B101: assert_used
_exec(f"bandit --recursive --configfile pyproject.toml .")

if "test" in COMMAND_LINE_TARGETS or "tests" in COMMAND_LINE_TARGETS:
# Running tests via coverage to only report when asking for coverage
Expand All @@ -94,6 +92,8 @@ def _exec(command: str, env: Mapping | None = None) -> int:
_exec("coverage report --show-missing")

if "license" in COMMAND_LINE_TARGETS or "licence" in COMMAND_LINE_TARGETS:
# To fix:
# reuse annotate --copyright="Alliander" --license=Apache-2.0 --recursive pycgmes/{resources,utils}
_exec("reuse lint")

if not _target_found:
Expand Down
Loading

0 comments on commit 4c36d8c

Please sign in to comment.