openepd 4.2.0__py3-none-any.whl → 4.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openepd/__version__.py +1 -1
- openepd/model/lcia.py +1 -0
- openepd/mypy/__init__.py +15 -0
- openepd/mypy/custom_pydantic_plugin.py +91 -0
- {openepd-4.2.0.dist-info → openepd-4.4.0.dist-info}/METADATA +8 -1
- {openepd-4.2.0.dist-info → openepd-4.4.0.dist-info}/RECORD +8 -6
- {openepd-4.2.0.dist-info → openepd-4.4.0.dist-info}/LICENSE +0 -0
- {openepd-4.2.0.dist-info → openepd-4.4.0.dist-info}/WHEEL +0 -0
openepd/__version__.py
CHANGED
openepd/model/lcia.py
CHANGED
openepd/mypy/__init__.py
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2024 by C Change Labs Inc. www.c-change-labs.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2024 by C Change Labs Inc. www.c-change-labs.com
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
from collections.abc import Callable
|
18
|
+
|
19
|
+
from mypy.nodes import AssignmentStmt, CallExpr, MemberExpr, TypeInfo
|
20
|
+
from mypy.plugin import ClassDefContext
|
21
|
+
import pydantic.mypy
|
22
|
+
from pydantic.mypy import (
|
23
|
+
MODEL_METACLASS_FULLNAME,
|
24
|
+
ModelConfigData,
|
25
|
+
PydanticModelClassVar,
|
26
|
+
PydanticModelField,
|
27
|
+
PydanticModelTransformer,
|
28
|
+
PydanticPlugin,
|
29
|
+
)
|
30
|
+
|
31
|
+
# Using this plugin fixes the issue.
|
32
|
+
|
33
|
+
CUSTOM_OPENEPD_MODEL_METACLASS_FULLNAME = "openepd.model.base.PydanticClassAttributeExposeModelMetaclass"
|
34
|
+
MODEL_METACLASSES_FULL_NAMES = (MODEL_METACLASS_FULLNAME, CUSTOM_OPENEPD_MODEL_METACLASS_FULLNAME)
|
35
|
+
|
36
|
+
DECORATOR_FULLNAMES = pydantic.mypy.DECORATOR_FULLNAMES | {
|
37
|
+
"pydantic.v1.class_validators.validator",
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
class CustomPydanticModelTransformer(PydanticModelTransformer):
|
42
|
+
"""Extension of the mypy/pydantic model transformer which also understands validator definitions via v1 compat."""
|
43
|
+
|
44
|
+
def collect_field_or_class_var_from_stmt(
|
45
|
+
self, stmt: AssignmentStmt, model_config: ModelConfigData, class_vars: dict[str, PydanticModelClassVar]
|
46
|
+
) -> PydanticModelField | PydanticModelClassVar | None:
|
47
|
+
"""Extend implementation of the original Pydantic method with one more case for validator."""
|
48
|
+
if not stmt.new_syntax and (
|
49
|
+
isinstance(stmt.rvalue, CallExpr)
|
50
|
+
and isinstance(stmt.rvalue.callee, CallExpr)
|
51
|
+
and isinstance(stmt.rvalue.callee.callee, MemberExpr)
|
52
|
+
and stmt.rvalue.callee.callee.fullname in DECORATOR_FULLNAMES
|
53
|
+
):
|
54
|
+
# Required to detect compat-imported v1 validators and not treat them as fields.
|
55
|
+
return None
|
56
|
+
return super().collect_field_or_class_var_from_stmt(stmt, model_config, class_vars)
|
57
|
+
|
58
|
+
|
59
|
+
class CustomMetaclassPydanticPlugin(PydanticPlugin):
|
60
|
+
"""
|
61
|
+
Custom metaclass pydantic plugin.
|
62
|
+
|
63
|
+
Extends a standard pydantic mypy plugin, and adds certain behaviours required for us:
|
64
|
+
1. Support for a non-standard metaclass for pydantic models. We use it allow for access via Class.field notation
|
65
|
+
2. Support for our modified compat import of pydantic v1 when using this metaclass.
|
66
|
+
"""
|
67
|
+
|
68
|
+
def get_metaclass_hook(self, fullname: str) -> Callable[[ClassDefContext], None] | None:
|
69
|
+
"""Update Pydantic `ModelMetaclass` definition."""
|
70
|
+
if fullname in MODEL_METACLASSES_FULL_NAMES:
|
71
|
+
return self._pydantic_model_metaclass_marker_callback
|
72
|
+
return None
|
73
|
+
|
74
|
+
def get_base_class_hook(self, fullname: str) -> Callable[[ClassDefContext], bool] | None: # type: ignore
|
75
|
+
"""Update Pydantic model class."""
|
76
|
+
sym = self.lookup_fully_qualified(fullname)
|
77
|
+
if sym and isinstance(sym.node, TypeInfo): # pragma: no branch
|
78
|
+
# No branching may occur if the mypy cache has not been cleared
|
79
|
+
if any(base.fullname in ["pydantic.main.BaseModel", "pydantic.v1.main.BaseModel"] for base in sym.node.mro):
|
80
|
+
return self._pydantic_model_class_maker_callback
|
81
|
+
return None
|
82
|
+
|
83
|
+
def _pydantic_model_class_maker_callback(self, ctx: ClassDefContext) -> bool:
|
84
|
+
# extended to replace the mypy-pydantic transformer with our custom transformer - see validator note.
|
85
|
+
transformer = CustomPydanticModelTransformer(ctx.cls, ctx.reason, ctx.api, self.plugin_config)
|
86
|
+
return transformer.transform()
|
87
|
+
|
88
|
+
|
89
|
+
def plugin(version: str):
|
90
|
+
"""Entry point to the mypy plugin."""
|
91
|
+
return CustomMetaclassPydanticPlugin
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: openepd
|
3
|
-
Version: 4.
|
3
|
+
Version: 4.4.0
|
4
4
|
Summary: Python library to work with OpenEPD format
|
5
5
|
Home-page: https://github.com/cchangelabs/openepd
|
6
6
|
License: Apache-2.0
|
@@ -144,6 +144,13 @@ with DefaultBundleWriter("my-bundle.epb") as writer, open("test-pcr.pdf", "rb")
|
|
144
144
|
writer.write_blob_asset(pcr_pdf_file, "application/pdf", pcr_asset, RelType.Pdf)
|
145
145
|
```
|
146
146
|
|
147
|
+
### Mypy
|
148
|
+
|
149
|
+
OpenEPD uses a small modification to standard pydantic models (see PydanticClassAttributeExposeModelMetaclass). Mypy,
|
150
|
+
in order to work correctly, requires a modified pydantic plugin. To enable it, add an
|
151
|
+
`openepd.mypy.custom_pydantic_plugin` to list of mypy plugins in your `pyproject.toml` or other mypy-related config
|
152
|
+
file. See [Mypy configuration](https://mypy.readthedocs.io/en/stable/extending_mypy.html)
|
153
|
+
|
147
154
|
# Credits
|
148
155
|
|
149
156
|
This library has been written and maintained by [C-Change Labs](https://c-change-labs.com/).
|
@@ -1,5 +1,5 @@
|
|
1
1
|
openepd/__init__.py,sha256=UGmZGEyMnASrYwEBPHuXmVzHiuCUskUsJEPoHTIo-lg,620
|
2
|
-
openepd/__version__.py,sha256=
|
2
|
+
openepd/__version__.py,sha256=8oxCZtughIDK-iiG2jwUL1oA4HclG-SZymHOYT1nbtE,638
|
3
3
|
openepd/api/__init__.py,sha256=UGmZGEyMnASrYwEBPHuXmVzHiuCUskUsJEPoHTIo-lg,620
|
4
4
|
openepd/api/base_sync_client.py,sha256=jviqtQgsOVdRq5x7_Yh_Tg8zIdWtVTIUqNCgebf6YDg,20925
|
5
5
|
openepd/api/category/__init__.py,sha256=UGmZGEyMnASrYwEBPHuXmVzHiuCUskUsJEPoHTIo-lg,620
|
@@ -35,7 +35,7 @@ openepd/model/category.py,sha256=IQXNGQFQmFZ_H9PRONloX_UOSf1sTMDq1rM1yz8JR0Y,163
|
|
35
35
|
openepd/model/common.py,sha256=aa_bfotPybPoYyzHtwj5E5X1T-fCEyznMfVUWvpUhiM,5460
|
36
36
|
openepd/model/epd.py,sha256=_PyVM3cKrOBS2vgLLPBZzKkNfiBEtp2rECP0imp49bc,14082
|
37
37
|
openepd/model/factory.py,sha256=i45ZXG5RIMKrXvVH1li0ZlUwcBpSl5gEctcLc1MBM7M,1701
|
38
|
-
openepd/model/lcia.py,sha256
|
38
|
+
openepd/model/lcia.py,sha256=-5bMz5ZyoZJnggp66v9upTT0yhcyIZYlwfFh83-4ZvY,16968
|
39
39
|
openepd/model/org.py,sha256=FHcYh2WOOQrCMyzm0Ow-iP79jMTBPcneidjH6NXIklA,3760
|
40
40
|
openepd/model/pcr.py,sha256=SwqLWMj9k_jqIzxz5mh6ttqvtLCspKSpywF5YTBOMsA,5397
|
41
41
|
openepd/model/specs/README.md,sha256=W5LSMpZuW5x36cKS4HRfeFsClsRf8J9yHMMICghdc0s,862
|
@@ -86,8 +86,10 @@ openepd/model/validation/common.py,sha256=FLYqK8gYFagx08LCkS0jy3qo4-Zq9VAv5i8ZwF
|
|
86
86
|
openepd/model/validation/numbers.py,sha256=tgirqrDGgrSo6APGlW1ozNuVV8mJz_4HCAXS2OUENq0,888
|
87
87
|
openepd/model/validation/quantity.py,sha256=kzug0MZ3Ao0zeVzN-aleyxUg5hA_7D5tNOOerverfRQ,7415
|
88
88
|
openepd/model/versioning.py,sha256=R_zm6rCrgF3vlJQYbpyWhirdS_Oek16cv_mvZmpuE8I,4473
|
89
|
+
openepd/mypy/__init__.py,sha256=UGmZGEyMnASrYwEBPHuXmVzHiuCUskUsJEPoHTIo-lg,620
|
90
|
+
openepd/mypy/custom_pydantic_plugin.py,sha256=JpfQHAmqS95lKm68tTlQ12RFO_O2tvd4ZM_DFBNUa8s,4034
|
89
91
|
openepd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
90
|
-
openepd-4.
|
91
|
-
openepd-4.
|
92
|
-
openepd-4.
|
93
|
-
openepd-4.
|
92
|
+
openepd-4.4.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
93
|
+
openepd-4.4.0.dist-info/METADATA,sha256=monlkvm4yIu0TbpTtV0iMUdxBGohmD-zBk5PSdPNc8o,8212
|
94
|
+
openepd-4.4.0.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
95
|
+
openepd-4.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|