Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 3 additions & 4 deletions .github/workflows/_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ on:
type: boolean
default: false
description: for debug purposes only - if true skip all scons quality checks
# Python version. Nothing is 3.10 specific yet as far as I know
_PYTHON_VERSION:
type: string
default: "3.10" # Weirdly enough, trailing 0 are removed if this string is not quoted.
default: "3.11" # Weirdly enough, trailing 0 are removed if this string is not quoted.
description: Version of python used to run tests
secrets:
PYCGMES_PYPI_TOKEN:
Expand All @@ -37,7 +36,7 @@ jobs:
show-progress: false # very verbose for not much

- name: Setup python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "${{ inputs._PYTHON_VERSION }}"
architecture: "x64" # default
Expand All @@ -46,7 +45,7 @@ jobs:

- name: Poetry caching
id: poetry-cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: .cache/pypoetry # NOT $HOME/.cache, which only caches the downloads, before building.
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
Expand Down
72 changes: 50 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SPDX-License-Identifier: Apache-2.0
- [SHACL files](#shacl-files)
- [V3 source zip](#v3-source-zip)
- [Dataclasses](#dataclasses)
- [Library build, CI, CD...](#library-build-ci-cd)
- [Library build, CI, CD](#library-build-ci-cd)
- [CI](#ci)
- [CD](#cd)
- [License](#license)
Expand Down Expand Up @@ -76,26 +76,33 @@ class higher in the hierarchy (for instance `Equipment`) there is a lot more wor
class CustomBay(Bay):
colour: str = Field(
default="Red",
in_profiles=[
Profile.EQ,
],
json_schema_extra={
"in_profiles": [
Profile.EQ,
],
"is_used": True,
"is_class_attribute": False,
"is_enum_attribute": False,
"is_list_attribute": False,
"is_primitive_attribute": True,
},
)
```

### Create a new profile

This approach is cleaner and more standard compliant: the official CGMES profiles stay untouched, while a new additional profile contains your customisations.

You can do this by extending the `BaseProfile`` Enum in [profile.py](./pycgmes/utils/profile.py).
You can do this by extending the `BaseProfile` Enum in [profile.py](./pycgmes/utils/profile.py).

While in Python it is not possible to extend or compose Enums which already have fields, you can create your own:

```python
from pycgmes.utils.profile import BaseProfile

class CustomProfile(BaseProfile):
CUS="Tom"
FRO="Mage"
CUS = "Tom"
FRO = "Mage"
```

And use it everywhere you would use a profile:
Expand All @@ -109,11 +116,18 @@ class CustomBayAttr(Bay):
"in_profiles": [
CustomProfile.CUS,
],
}
"is_used": True,
"is_class_attribute": False,
"is_enum_attribute": False,
"is_list_attribute": False,
"is_primitive_attribute": True,
"namespace": "custom",
},
)

# And for instance:
custom_attrs = CustomBayAttr(colour="purple").cgmes_attributes_in_profile(CustomProfile.CUS)
custom_attr = CustomBayAttr(colour="purple")
attr_dict = custom_attr.cgmes_attributes_in_profile(CustomProfile.CUS)
```

### Implementation details
Expand All @@ -128,11 +142,10 @@ from pydantic.dataclasses import dataclass

from pycgmes.resources.ACLineSegment import ACLineSegment


@dataclass
class ACLineSegmentCustom(ACLineSegment):
@classmethod
def apparent_name(cls):
def apparent_name(cls) -> str:
return "ACLineSegment"
```

Expand All @@ -144,6 +157,14 @@ The default class (or resource) namespace is `http://iec.ch/TC57/CIM100#`.

You can override it when you create a custom resource by just redefining the property `namespace`:

```python
@dataclass
class ACLineSegmentCustom(ACLineSegment):
@property
def namespace(self) -> str:
return "custom ns class"
```

##### Attribute namespace

In the serialisation, the namespace of all attributes is `http://iec.ch/TC57/CIM100#` by default.
Expand All @@ -155,20 +176,23 @@ The namespace of an attribute is the first value found:
- namespace of the first parent defining one. The top parent (`Base`) defined `cim`.

```python
from pydantic.dataclasses import dataclass
from pydantic import Field
from pydantic.dataclasses import dataclass

from pycgmes.resources import ACLineSegment

from pycgmes.resources.ACLineSegment import ACLineSegment

@dataclass
class ACLineSegmentCustom(ACLineSegment):
colour: str = Field(
default="Red",
json_schema_extra={
"in_profiles": [
Profile.EQ, # Do not do this, see chapter "create a new profile"
],
Profile.EQ, # Do not do this, see chapter "Create a new profile" ],
"is_used": True,
"is_class_attribute": False,
"is_enum_attribute": False,
"is_list_attribute": False,
"is_primitive_attribute": True,
"namespace": "custom",
},
)
Expand All @@ -177,17 +201,21 @@ class ACLineSegmentCustom(ACLineSegment):
default="Big",
json_schema_extra={
"in_profiles": [
Profile.EQ, # Do not do this, see chapter "create a new profile"
],
}
Profile.EQ, # Do not do this, see chapter "Create a new profile" ],
"is_used": True,
"is_class_attribute": False,
"is_enum_attribute": False,
"is_list_attribute": False,
"is_primitive_attribute": True,
},
)

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

@classmethod
def apparent_name(cls):
def apparent_name(cls) -> str:
return "ACLineSegment"
```

Expand Down Expand Up @@ -224,7 +252,7 @@ files (those extracted and mentioned above) but is usually not needed.

Generated from the modernpython serialisation of [cimgen](https://github.com/sogno-platform/cimgen).

## Library build, CI, CD...
## Library build, CI, CD

### CI

Expand All @@ -246,7 +274,7 @@ Please read [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md), [CONTRIBUTING.md](./CONT

## Contact

Please read [SUPPORT.md](./SUPPORT.md)for how to connect and get into contact with the project.
Please read [SUPPORT.md](./SUPPORT.md) for how to connect and get into contact with the project.

## Attribution

Expand Down
Loading
Loading