openepd 6.23.0__py3-none-any.whl → 6.25.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 CHANGED
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
  #
16
- VERSION = "6.23.0"
16
+ VERSION = "6.25.0"
openepd/model/lcia.py CHANGED
@@ -504,10 +504,12 @@ class LCIAMethod(StrEnum):
504
504
  """A list of available LCA methods."""
505
505
 
506
506
  UNKNOWN = "Unknown LCIA"
507
+ TRACI_2_2 = "TRACI 2.2"
507
508
  TRACI_2_1 = "TRACI 2.1"
508
509
  TRACI_2_0 = "TRACI 2.0"
509
510
  TRACI_1_0 = "TRACI 1.0"
510
511
  IPCC_AR5 = "IPCC AR5"
512
+ IPCC_AR6 = "IPCC AR6"
511
513
  EF_3_0 = "EF 3.0"
512
514
  EF_3_1 = "EF 3.1"
513
515
  EF_2_0 = "EF 2.0"
@@ -22,8 +22,6 @@ from collections.abc import Sequence
22
22
  import types
23
23
  from typing import Any, ClassVar, TypeVar
24
24
 
25
- from pydantic.v1.fields import FieldInfo
26
-
27
25
  from openepd.compat.pydantic import pyd
28
26
  from openepd.model.specs.base import BaseOpenEpdHierarchicalSpec
29
27
  from openepd.model.specs.singular.accessories import AccessoriesV1
@@ -208,9 +206,9 @@ class Specs(BaseOpenEpdHierarchicalSpec):
208
206
  """
209
207
  klass = self.__class__
210
208
 
211
- fields: dict[str, FieldInfo] = klass.__fields__ # type: ignore[assignment]
209
+ fields: dict[str, pyd.fields.FieldInfo] = klass.__fields__ # type: ignore[assignment]
212
210
 
213
- field: FieldInfo | None
211
+ field: pyd.fields.FieldInfo | None
214
212
  for i, key in enumerate(keys, start=1):
215
213
  field = fields.get(key)
216
214
  if field is None:
@@ -0,0 +1,15 @@
1
+ #
2
+ # Copyright 2025 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,15 @@
1
+ #
2
+ # Copyright 2025 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,192 @@
1
+ #
2
+ # Copyright 2025 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
+ __all__ = (
17
+ "BaseDataMapper",
18
+ "KeyValueMapper",
19
+ "ReferenceMapper",
20
+ "RegexMapper",
21
+ "SimpleDataMapper",
22
+ )
23
+
24
+ import abc
25
+ from collections.abc import Mapping
26
+ import re
27
+ from typing import Generic, TypeAlias, TypeVar, assert_never, cast
28
+
29
+ T = TypeVar("T")
30
+ K = TypeVar("K")
31
+
32
+
33
+ class BaseDataMapper(Generic[T, K], abc.ABC):
34
+ """
35
+ Base class for all data mappers.
36
+
37
+ Data mappers are objects used to map some input values to output values of different types.
38
+
39
+ Typical use case is mapping between different aliases of impact names with OpenEpd naming conventions.
40
+ """
41
+
42
+ @abc.abstractmethod
43
+ def map(self, input_value: T, default_value: K | None, *, raise_if_missing: bool = False) -> K | None:
44
+ """
45
+ Map the input value to the output value.
46
+
47
+ :param input_value: The input value to map.
48
+ :param default_value: The default value to return if there is no mapping for the input value.
49
+ :param raise_if_missing: Whether to raise an exception if there is no mapping for the input value.
50
+
51
+ :raise ValueError: If there is no mapping for the input value and raise_if_missing is True.
52
+ """
53
+ pass
54
+
55
+
56
+ class SimpleDataMapper(BaseDataMapper[T, T], Generic[T]):
57
+ """A data mapper that does not change the type of the input value."""
58
+
59
+ DATABASE: Mapping[T, T] = {}
60
+
61
+ def map(self, input_value: T, default_value: T | None, *, raise_if_missing: bool = False) -> T | None:
62
+ """
63
+ Map the input value to the output value.
64
+
65
+ :param input_value: The input value to map.
66
+ :param default_value: The default value to return if there is no mapping for the input value.
67
+ :param raise_if_missing: Whether to raise an exception if there is no mapping for the input value.
68
+
69
+ :raise ValueError: If there is no mapping for the input value and raise_if_missing is True.
70
+ """
71
+ if raise_if_missing and input_value not in self.DATABASE:
72
+ msg = f"No mapping for input value: {input_value}"
73
+ raise ValueError(msg)
74
+
75
+ return self.DATABASE.get(input_value, default_value)
76
+
77
+
78
+ class KeyValueMapper(BaseDataMapper[str, T], Generic[T]):
79
+ """
80
+ A data mapper that maps input values to output values using keywords.
81
+
82
+ List of values is expected to be a list string object or a list of objects easily castable to string.
83
+ """
84
+
85
+ KV: Mapping[str, list[T]] = {}
86
+
87
+ def map(self, input_value: str, default_value: T | None, *, raise_if_missing: bool = False) -> T | None:
88
+ """
89
+ Map the input value to the output value using keywords.
90
+
91
+ :param input_value: The input value to map.
92
+ :param default_value: The default value to return if there is no mapping for input value.
93
+ :param raise_if_missing: Whether to raise an exception if there is no mapping for the input value.
94
+
95
+ :raise ValueError: If there is no mapping for the input value and raise_if_missing is True.
96
+ """
97
+ for impact_name, keywords in self.KV.items():
98
+ for keyword in keywords:
99
+ if str(keyword).strip().lower() in input_value.strip().lower():
100
+ return cast(T, impact_name)
101
+
102
+ if raise_if_missing:
103
+ msg = f"No mapping for input value: {input_value}"
104
+ raise ValueError(msg)
105
+
106
+ return default_value
107
+
108
+
109
+ class RegexMapper(BaseDataMapper[str, T], Generic[T]):
110
+ """A data mapper that maps input values to output values using regex."""
111
+
112
+ PATTERNS: dict[str, str] = {}
113
+ _compiled_patterns: dict[str, re.Pattern]
114
+
115
+ def __init__(self) -> None:
116
+ self._compiled_patterns: dict[str, re.Pattern] = {
117
+ key: re.compile(pattern, re.IGNORECASE) for key, pattern in self.PATTERNS.items()
118
+ }
119
+
120
+ def map(self, input_value: str, default_value: T | None, *, raise_if_missing: bool = False) -> T | None:
121
+ """
122
+ Map the input value to the output value using regex.
123
+
124
+ :param input_value: The input value to map.
125
+ :param default_value: The default value to return if there is no mapping for an input value.
126
+
127
+ :param raise_if_missing: Whether to raise an exception if there is no mapping for the input value.
128
+
129
+ :raise ValueError: If there is no mapping for the input value and raise_if_missing is True.
130
+ """
131
+ for impact_name, pattern in self._compiled_patterns.items():
132
+ if pattern.search(input_value.strip().lower()):
133
+ return cast(T, impact_name)
134
+
135
+ if raise_if_missing:
136
+ msg = f"No mapping for input value: {input_value}"
137
+ raise ValueError(msg)
138
+
139
+ return default_value
140
+
141
+
142
+ _TRmRules: TypeAlias = str | re.Pattern | list[str | re.Pattern]
143
+
144
+
145
+ class ReferenceMapper(BaseDataMapper[str, _TRmRules]):
146
+ """
147
+ A mapper that maps input values of any form to the expected value format.
148
+
149
+ Expected values may be a value or a list of values. Values are expected to be a string object, regular expressions,
150
+ or objects easily castable to string.
151
+ """
152
+
153
+ def map(self, input_value: str, default_value: str | None, *, raise_if_missing: bool = False) -> str | None: # type: ignore[override]
154
+ """
155
+ Return specified key as a value if any of the values in the list matches the input value.
156
+
157
+ :param input_value: value to be checked against the list of specified rules
158
+ :param default_value: default value to return if no match is found
159
+ :param raise_if_missing: whether to raise an exception if no match is found
160
+
161
+ :return: mapped value if find any match, else default value
162
+
163
+ :raise ValueError: if no match is found and raise_if_missing is True
164
+ """
165
+ for key, value in self.MAPPING.items():
166
+ if not self._is_applied(input_value, value):
167
+ continue
168
+ return key
169
+
170
+ if raise_if_missing:
171
+ msg = f"No mapping for input value: {input_value}"
172
+ raise ValueError(msg)
173
+
174
+ return default_value
175
+
176
+ def _is_applied(self, input_value: str, rules: _TRmRules) -> bool:
177
+ if isinstance(rules, str | re.Pattern):
178
+ return self._is_applied_to_item(input_value, rules)
179
+ elif isinstance(rules, list):
180
+ return any(self._is_applied_to_item(input_value, rule) for rule in rules)
181
+ else:
182
+ assert_never(rules)
183
+
184
+ def _is_applied_to_item(self, input_value: str, rule: str | re.Pattern) -> bool:
185
+ if isinstance(rule, str):
186
+ return input_value.strip().lower() == rule.strip().lower()
187
+ elif isinstance(rule, re.Pattern):
188
+ return bool(rule.search(input_value.strip().lower()))
189
+ else:
190
+ assert_never(rule)
191
+
192
+ MAPPING: Mapping[str, _TRmRules] = {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: openepd
3
- Version: 6.23.0
3
+ Version: 6.25.0
4
4
  Summary: Python library to work with OpenEPD format
5
5
  License: Apache-2.0
6
6
  Author: C-Change Labs
@@ -1,5 +1,5 @@
1
1
  openepd/__init__.py,sha256=fhxfEyEurLvSfvQci-vb3njzl_lvhcLXiZrecCOaMU8,794
2
- openepd/__version__.py,sha256=A1F4vtJZdjbFr6F3h4QgKFJUwgpNFQInneIXVmg2Vj8,639
2
+ openepd/__version__.py,sha256=hDgSAJf2ChxmeWlgYCHYlntPXqIh3A42Hhy4RbDRnLc,639
3
3
  openepd/api/__init__.py,sha256=9THJcV3LT7JDBOMz1px-QFf_sdJ0LOqJ5dmA9Dvvtd4,620
4
4
  openepd/api/average_dataset/__init__.py,sha256=9THJcV3LT7JDBOMz1px-QFf_sdJ0LOqJ5dmA9Dvvtd4,620
5
5
  openepd/api/average_dataset/generic_estimate_sync_api.py,sha256=_eZt_jGVL1a3p9cr-EF39Ve9Vl5sB8zwzTc_slnRL50,7975
@@ -51,7 +51,7 @@ openepd/model/factory.py,sha256=UWSGpfCr3GiMTP4rzBkwqxzbXB6GKZ_5Okb1Dqa_4aA,2701
51
51
  openepd/model/generic_estimate.py,sha256=zLGTyf4Uzmp2C0m-J1ePWItSz2RGdZ0OiGPWC5nhKHk,3992
52
52
  openepd/model/geography.py,sha256=Jx7NIDdk_sIvwyh-7YxnIjAwIHW2HCQK7UtFGM2xKtw,42095
53
53
  openepd/model/industry_epd.py,sha256=QZr7OhgGkzqZ8H5p6dCIVk9zSHEYtK3y9Nk-DvkFMyk,4011
54
- openepd/model/lcia.py,sha256=jgxTVoY2gCgfPCLrV5xRYGHbxntellGTfgLUGU9J22Y,26152
54
+ openepd/model/lcia.py,sha256=5SkiFdJKtza2fc2BBuepbl0TAi-UYsjSDR0ERj9ffmk,26206
55
55
  openepd/model/org.py,sha256=AAyXx42phVn3fZN0_Ga8CJb2iKh_dfVXsvO1lEtDovM,6832
56
56
  openepd/model/pcr.py,sha256=7nf6ATofdrlPt81vdU6p0E8n_ftFEuCEIKxtYlFwclw,5476
57
57
  openepd/model/specs/README.md,sha256=UGhSiFJ9hOxT1mZl-5ZrhkOrPKf1W_gcu5CI9hzV7LU,2430
@@ -98,7 +98,7 @@ openepd/model/specs/range/thermal_moisture_protection.py,sha256=aUpStISG2snc8aZ7
98
98
  openepd/model/specs/range/utility_piping.py,sha256=mQTrKbMTES_0Yta9DBnKehsmA2BAN_zYF_uPZCTKLPo,2665
99
99
  openepd/model/specs/range/wood.py,sha256=ZMStFsFOw5d6tCL2P7kksBnlYhwfvWJBZqoAdqSIUDg,6917
100
100
  openepd/model/specs/range/wood_joists.py,sha256=NCBHL0gdKwdKlGCP6up_Royl9BtWUUeuFfS1r2vIZ30,1785
101
- openepd/model/specs/singular/__init__.py,sha256=JuoXYIhyexFBY6gwCAa823CDT3XISSjjMBjQue7HTvM,11434
101
+ openepd/model/specs/singular/__init__.py,sha256=YaySkDd4qgmHCk58TfMhgsiAnU_IY83xK847NEvOC60,11414
102
102
  openepd/model/specs/singular/accessories.py,sha256=xcuSJrG84oTm_w76_wlv_sItfK36gSyDmUD2TnpZnVE,2013
103
103
  openepd/model/specs/singular/aggregates.py,sha256=oSfArxvLUj63w_U0tZViRyiOpMRRjE72ncy2BimKxco,2934
104
104
  openepd/model/specs/singular/aluminium.py,sha256=7Z3WmuW22o92cPHfR6X_OBSoer0V5llwiNdQmWgKTx8,2408
@@ -150,7 +150,10 @@ openepd/model/validation/quantity.py,sha256=mP4gIkeOGZuHRhprsf_BX11Cic75NssYxOTk
150
150
  openepd/model/versioning.py,sha256=wBZdOVL3ND9FMIRU9PS3vx9M_7MBiO70xYPQvPez6po,4522
151
151
  openepd/patch_pydantic.py,sha256=bO7U5HqthFol0vfycb0a42UAGL3KOQ8-9MW4yCWOFP0,4150
152
152
  openepd/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
153
- openepd-6.23.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
154
- openepd-6.23.0.dist-info/METADATA,sha256=j0XNy77oTEnuCbaEbCxKnmA5INpLme5-OVoILoxKAUE,9827
155
- openepd-6.23.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
156
- openepd-6.23.0.dist-info/RECORD,,
153
+ openepd/utils/__init__.py,sha256=9THJcV3LT7JDBOMz1px-QFf_sdJ0LOqJ5dmA9Dvvtd4,620
154
+ openepd/utils/mapping/__init__.py,sha256=9THJcV3LT7JDBOMz1px-QFf_sdJ0LOqJ5dmA9Dvvtd4,620
155
+ openepd/utils/mapping/common.py,sha256=WphCzwQQlzX11tUk88Ubyq3QPBLvH0tBPSIuH0kmiug,7339
156
+ openepd-6.25.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
157
+ openepd-6.25.0.dist-info/METADATA,sha256=sXZ1WJU-4BzBy9ZSCjbmL_cvd_44recegC2mmALLGlE,9827
158
+ openepd-6.25.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
159
+ openepd-6.25.0.dist-info/RECORD,,