openepd 7.1.0__py3-none-any.whl → 7.3.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/api/average_dataset/generic_estimate_sync_api.py +2 -1
- openepd/api/average_dataset/industry_epd_sync_api.py +2 -1
- openepd/api/base_sync_client.py +10 -8
- openepd/api/common.py +17 -11
- openepd/api/dto/common.py +1 -1
- openepd/api/epd/sync_api.py +2 -1
- openepd/api/org/__init__.py +15 -0
- openepd/api/org/sync_api.py +79 -0
- openepd/api/pcr/sync_api.py +35 -0
- openepd/api/plant/__init__.py +15 -0
- openepd/api/plant/sync_api.py +79 -0
- openepd/api/standard/__init__.py +15 -0
- openepd/api/standard/sync_api.py +79 -0
- openepd/api/sync_client.py +27 -0
- openepd/bundle/base.py +47 -6
- openepd/bundle/model.py +1 -0
- openepd/bundle/reader.py +35 -10
- openepd/bundle/writer.py +21 -12
- openepd/m49/__init__.py +2 -0
- openepd/m49/const.py +1 -1
- openepd/m49/utils.py +16 -10
- openepd/model/base.py +20 -15
- openepd/model/common.py +10 -5
- openepd/model/declaration.py +2 -2
- openepd/model/epd.py +2 -1
- openepd/model/factory.py +5 -3
- openepd/model/generic_estimate.py +4 -0
- openepd/model/lcia.py +10 -10
- openepd/model/org.py +14 -7
- openepd/model/pcr.py +2 -2
- openepd/model/specs/__init__.py +37 -0
- openepd/model/specs/asphalt.py +3 -3
- openepd/model/specs/base.py +2 -1
- openepd/model/specs/enums.py +9 -1
- openepd/model/specs/range/__init__.py +5 -3
- openepd/model/specs/range/accessories.py +1 -1
- openepd/model/specs/range/aluminium.py +1 -1
- openepd/model/specs/range/cladding.py +10 -10
- openepd/model/specs/range/cmu.py +0 -2
- openepd/model/specs/range/concrete.py +25 -2
- openepd/model/specs/range/conveying_equipment.py +2 -2
- openepd/model/specs/range/electrical.py +18 -18
- openepd/model/specs/range/electrical_transmission_and_distribution_equipment.py +1 -1
- openepd/model/specs/range/exterior_improvements.py +47 -0
- openepd/model/specs/range/finishes.py +19 -40
- openepd/model/specs/range/fire_and_smoke_protection.py +3 -3
- openepd/model/specs/range/furnishings.py +7 -7
- openepd/model/specs/range/manufacturing_inputs.py +17 -5
- openepd/model/specs/range/masonry.py +1 -1
- openepd/model/specs/range/mechanical.py +6 -6
- openepd/model/specs/range/mixins/__init__.py +15 -0
- openepd/model/specs/range/mixins/access_flooring_mixin.py +43 -0
- openepd/model/specs/range/network_infrastructure.py +3 -3
- openepd/model/specs/range/openings.py +17 -17
- openepd/model/specs/range/other_materials.py +4 -4
- openepd/model/specs/range/plumbing.py +5 -5
- openepd/model/specs/range/precast_concrete.py +2 -2
- openepd/model/specs/range/steel.py +18 -9
- openepd/model/specs/range/thermal_moisture_protection.py +12 -12
- openepd/model/specs/range/wood.py +4 -6
- openepd/model/specs/singular/__init__.py +119 -2
- openepd/model/specs/singular/aluminium.py +2 -1
- openepd/model/specs/singular/concrete.py +25 -1
- openepd/model/specs/singular/deprecated/__init__.py +1 -1
- openepd/model/specs/singular/exterior_improvements.py +47 -0
- openepd/model/specs/singular/finishes.py +3 -59
- openepd/model/specs/singular/manufacturing_inputs.py +13 -1
- openepd/model/specs/singular/mixins/access_flooring_mixin.py +55 -0
- openepd/model/specs/singular/steel.py +10 -2
- openepd/model/validation/common.py +10 -6
- openepd/model/validation/enum.py +4 -2
- openepd/model/validation/quantity.py +13 -6
- openepd/model/versioning.py +8 -6
- {openepd-7.1.0.dist-info → openepd-7.3.0.dist-info}/METADATA +23 -13
- {openepd-7.1.0.dist-info → openepd-7.3.0.dist-info}/RECORD +78 -67
- {openepd-7.1.0.dist-info → openepd-7.3.0.dist-info}/WHEEL +1 -1
- {openepd-7.1.0.dist-info → openepd-7.3.0.dist-info}/LICENSE +0 -0
openepd/__version__.py
CHANGED
@@ -135,7 +135,8 @@ class GenericEstimateApi(BaseApiMethodGroup):
|
|
135
135
|
"""
|
136
136
|
ge_id = ge.id
|
137
137
|
if not ge_id:
|
138
|
-
|
138
|
+
msg = "The ID must be set to edit a GenericEstimate."
|
139
|
+
raise ValueError(msg)
|
139
140
|
|
140
141
|
response = self._client.do_request(
|
141
142
|
"put",
|
@@ -90,7 +90,8 @@ class IndustryEpdApi(BaseApiMethodGroup):
|
|
90
90
|
"""
|
91
91
|
iepd_id = iepd.id
|
92
92
|
if not iepd_id:
|
93
|
-
|
93
|
+
msg = "The ID must be set to edit a IndustryEpd."
|
94
|
+
raise ValueError(msg)
|
94
95
|
|
95
96
|
response = self._client.do_request(
|
96
97
|
"put",
|
openepd/api/base_sync_client.py
CHANGED
@@ -14,14 +14,15 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
__all__ = (
|
17
|
-
"
|
18
|
-
"
|
17
|
+
"USER_AGENT_DEFAULT",
|
18
|
+
"BaseApiMethodGroup",
|
19
19
|
"DoRequest",
|
20
|
+
"HttpStreamReader",
|
20
21
|
"RetryHandler",
|
21
|
-
"
|
22
|
-
"USER_AGENT_DEFAULT",
|
22
|
+
"SyncHttpClient",
|
23
23
|
)
|
24
24
|
|
25
|
+
from collections.abc import Callable
|
25
26
|
import datetime
|
26
27
|
from functools import partial, wraps
|
27
28
|
from io import IOBase
|
@@ -29,7 +30,7 @@ import logging
|
|
29
30
|
import random
|
30
31
|
import shutil
|
31
32
|
import time
|
32
|
-
from typing import IO, Any, BinaryIO,
|
33
|
+
from typing import IO, Any, BinaryIO, Final, NamedTuple
|
33
34
|
|
34
35
|
import requests
|
35
36
|
from requests import PreparedRequest, Response, Session, Timeout
|
@@ -180,7 +181,7 @@ class SyncHttpClient:
|
|
180
181
|
self._throttler = Throttler(rate_per_sec=requests_per_sec)
|
181
182
|
self._throttle_retry_timeout: float = (
|
182
183
|
float(throttle_retry_timeout)
|
183
|
-
if isinstance(throttle_retry_timeout,
|
184
|
+
if isinstance(throttle_retry_timeout, float | int)
|
184
185
|
else throttle_retry_timeout.total_seconds()
|
185
186
|
)
|
186
187
|
self.user_agent = user_agent
|
@@ -412,7 +413,8 @@ class SyncHttpClient:
|
|
412
413
|
|
413
414
|
response.raise_for_status()
|
414
415
|
# This can't be handled by static checker because of the dynamic nature of the raise_for_status method
|
415
|
-
|
416
|
+
msg = "This line should never be reached"
|
417
|
+
raise RuntimeError(msg)
|
416
418
|
|
417
419
|
def _get_url_for_request(self, path_or_url: str) -> str:
|
418
420
|
"""
|
@@ -471,7 +473,7 @@ class SyncHttpClient:
|
|
471
473
|
exception = e
|
472
474
|
|
473
475
|
if exception or response.status_code == requests_codes.service_unavailable:
|
474
|
-
secs = random.randint(60, 60 * 5)
|
476
|
+
secs = random.randint(60, 60 * 5) # noqa: S311
|
475
477
|
logger.warning(
|
476
478
|
"%s %s is unavailable. Attempts left: %s. Waiting %s seconds...",
|
477
479
|
method,
|
openepd/api/common.py
CHANGED
@@ -13,12 +13,12 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
|
-
from collections.abc import Iterable
|
16
|
+
from collections.abc import Callable, Iterable, Iterator
|
17
17
|
from contextlib import contextmanager
|
18
18
|
from datetime import datetime, timedelta
|
19
19
|
import threading
|
20
20
|
from time import sleep
|
21
|
-
from typing import
|
21
|
+
from typing import Generic, cast
|
22
22
|
|
23
23
|
from requests import Response
|
24
24
|
|
@@ -126,20 +126,26 @@ class StreamingListResponse(Iterable[TOpenEpdObject], Generic[TOpenEpdObject]):
|
|
126
126
|
:return: list of items on the page
|
127
127
|
"""
|
128
128
|
if page_num <= 0:
|
129
|
-
|
129
|
+
msg = "Page number must be positive"
|
130
|
+
raise ValueError(msg)
|
130
131
|
if self.__current_page != page_num or force_reload:
|
131
132
|
self.__recent_response = self.__fetch_handler(page_num, self.__page_size)
|
132
133
|
self.__current_page = page_num
|
133
134
|
if self.__recent_response is None:
|
134
|
-
|
135
|
+
msg = "Response is empty, this should not happen, check if fetch_handler is compatible"
|
136
|
+
raise RuntimeError(msg)
|
135
137
|
if self.__recent_response.payload is None:
|
136
|
-
|
138
|
+
msg = "Response does not contain payload"
|
139
|
+
raise ValueError(msg)
|
137
140
|
if not isinstance(self.__recent_response.payload, list):
|
138
|
-
|
141
|
+
msg = "Response does not contain a list"
|
142
|
+
raise ValueError(msg)
|
139
143
|
if self.__recent_response.meta is None:
|
140
|
-
|
144
|
+
msg = "Response does not contain meta"
|
145
|
+
raise ValueError(msg)
|
141
146
|
if not isinstance(self.__recent_response.meta, PagingMetaMixin):
|
142
|
-
|
147
|
+
msg = "Response does not contain paging meta"
|
148
|
+
raise ValueError(msg)
|
143
149
|
return self.__recent_response.payload
|
144
150
|
|
145
151
|
def get_paging_meta(self) -> PagingMeta:
|
@@ -152,7 +158,8 @@ class StreamingListResponse(Iterable[TOpenEpdObject], Generic[TOpenEpdObject]):
|
|
152
158
|
"""
|
153
159
|
paging_meta = cast(PagingMetaMixin, self.get_meta()).paging
|
154
160
|
if paging_meta is None:
|
155
|
-
|
161
|
+
msg = "Response does not contain paging meta"
|
162
|
+
raise ValueError(msg)
|
156
163
|
return paging_meta
|
157
164
|
|
158
165
|
def get_meta(self) -> MetaCollectionDto:
|
@@ -206,8 +213,7 @@ class StreamingListResponse(Iterable[TOpenEpdObject], Generic[TOpenEpdObject]):
|
|
206
213
|
self.goto_page(start_from_page)
|
207
214
|
while True:
|
208
215
|
items = self.goto_page(self.current_page)
|
209
|
-
|
210
|
-
yield x
|
216
|
+
yield from items
|
211
217
|
if not self.has_next_page():
|
212
218
|
return # no more pages
|
213
219
|
else:
|
openepd/api/dto/common.py
CHANGED
@@ -63,7 +63,7 @@ TMetaExtension = TypeVar("TMetaExtension", bound=MetaExtensionBase)
|
|
63
63
|
|
64
64
|
class MetaCollectionDto(BaseOpenEpdApiModel, Generic[TMetaExtension]):
|
65
65
|
"""
|
66
|
-
|
66
|
+
Use this class as a container for different meta objects.
|
67
67
|
|
68
68
|
From a specific controller, you should return a specific subclass of MetaCollectionDto and appropriate mixins. This
|
69
69
|
would allow to retain type information to generate schema for meta section of response.
|
openepd/api/epd/sync_api.py
CHANGED
@@ -173,7 +173,8 @@ class EpdApi(BaseApiMethodGroup):
|
|
173
173
|
"""
|
174
174
|
epd_id = epd.id
|
175
175
|
if not epd_id:
|
176
|
-
|
176
|
+
msg = "The EPD ID must be set to edit an EPD."
|
177
|
+
raise ValueError(msg)
|
177
178
|
response = self._client.do_request(
|
178
179
|
"put",
|
179
180
|
f"/epds/{encode_path_param(epd_id)}",
|
@@ -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,79 @@
|
|
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
|
+
from typing import Literal, overload
|
17
|
+
|
18
|
+
from requests import Response
|
19
|
+
|
20
|
+
from openepd.api.base_sync_client import BaseApiMethodGroup
|
21
|
+
from openepd.api.utils import encode_path_param
|
22
|
+
from openepd.model.org import Org, OrgRef
|
23
|
+
|
24
|
+
|
25
|
+
class OrgApi(BaseApiMethodGroup):
|
26
|
+
"""API methods for Orgs."""
|
27
|
+
|
28
|
+
@overload
|
29
|
+
def create(self, to_create: Org, with_response: Literal[True]) -> tuple[OrgRef, Response]: ...
|
30
|
+
|
31
|
+
@overload
|
32
|
+
def create(self, to_create: Org, with_response: Literal[False] = False) -> OrgRef: ...
|
33
|
+
|
34
|
+
def create(self, to_create: Org, with_response: bool = False) -> OrgRef | tuple[OrgRef, Response]:
|
35
|
+
"""
|
36
|
+
Create a new organization.
|
37
|
+
|
38
|
+
:param to_create: Organization to create
|
39
|
+
:param with_response: if True, return a tuple of (OrgRef, Response), otherwise return only OrgRef
|
40
|
+
:return: Organization reference or Organization reference with HTTP Response object depending on parameter
|
41
|
+
:raise ValidationError: if given object Org is invalid
|
42
|
+
"""
|
43
|
+
response = self._client.do_request("post", "/orgs", json=to_create.to_serializable())
|
44
|
+
content = response.json()
|
45
|
+
ref = OrgRef.model_validate(content)
|
46
|
+
if with_response:
|
47
|
+
return ref, response
|
48
|
+
return ref
|
49
|
+
|
50
|
+
@overload
|
51
|
+
def edit(self, to_edit: Org, with_response: Literal[True]) -> tuple[OrgRef, Response]: ...
|
52
|
+
|
53
|
+
@overload
|
54
|
+
def edit(self, to_edit: Org, with_response: Literal[False] = False) -> OrgRef: ...
|
55
|
+
|
56
|
+
def edit(self, to_edit: Org, with_response: bool = False) -> OrgRef | tuple[OrgRef, Response]:
|
57
|
+
"""
|
58
|
+
Edit an organization.
|
59
|
+
|
60
|
+
:param to_edit: Organization to edit
|
61
|
+
:param with_response: if True, return a tuple of (OrgRef, Response), otherwise return only Org
|
62
|
+
:return: Organization reference or Organization reference with HTTP Response object depending on parameter
|
63
|
+
:raise ValueError: if the organization web_domain is not set
|
64
|
+
"""
|
65
|
+
entity_id = to_edit.web_domain
|
66
|
+
if not entity_id:
|
67
|
+
msg = "The organization web_domain must be set to edit an organization."
|
68
|
+
raise ValueError(msg)
|
69
|
+
response = self._client.do_request(
|
70
|
+
"put",
|
71
|
+
f"/orgs/{encode_path_param(entity_id)}",
|
72
|
+
json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
|
73
|
+
)
|
74
|
+
response.raise_for_status()
|
75
|
+
content = response.json()
|
76
|
+
ref = OrgRef.model_validate(content)
|
77
|
+
if with_response:
|
78
|
+
return ref, response
|
79
|
+
return ref
|
openepd/api/pcr/sync_api.py
CHANGED
@@ -13,7 +13,12 @@
|
|
13
13
|
# See the License for the specific language governing permissions and
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
|
+
from typing import Literal, overload
|
17
|
+
|
18
|
+
from requests import Response
|
19
|
+
|
16
20
|
from openepd.api.base_sync_client import BaseApiMethodGroup
|
21
|
+
from openepd.api.utils import encode_path_param
|
17
22
|
from openepd.model.pcr import Pcr, PcrRef
|
18
23
|
|
19
24
|
|
@@ -42,3 +47,33 @@ class PcrApi(BaseApiMethodGroup):
|
|
42
47
|
"""
|
43
48
|
pcr_ref_obj = self._client.do_request("post", "/pcrs", json=pcr.to_serializable()).json()
|
44
49
|
return PcrRef.model_validate(pcr_ref_obj)
|
50
|
+
|
51
|
+
@overload
|
52
|
+
def edit(self, to_edit: Pcr, with_response: Literal[True]) -> tuple[PcrRef, Response]: ...
|
53
|
+
|
54
|
+
@overload
|
55
|
+
def edit(self, to_edit: Pcr, with_response: Literal[False] = False) -> PcrRef: ...
|
56
|
+
|
57
|
+
def edit(self, to_edit: Pcr, with_response: bool = False) -> PcrRef | tuple[PcrRef, Response]:
|
58
|
+
"""
|
59
|
+
Edit a pcr.
|
60
|
+
|
61
|
+
:param to_edit: Pcr to edit
|
62
|
+
:param with_response: if True, return a tuple of (PcrRef, Response), otherwise return only PcrRef
|
63
|
+
:return: Pcr reference or Pcr reference with HTTP Response object depending on parameter
|
64
|
+
:raise ValueError: if the pcr ID is not set
|
65
|
+
"""
|
66
|
+
entity_id = to_edit.id
|
67
|
+
if not entity_id:
|
68
|
+
msg = "The pcr ID must be set to edit a pcr."
|
69
|
+
raise ValueError(msg)
|
70
|
+
response = self._client.do_request(
|
71
|
+
"put",
|
72
|
+
f"/pcrs/{encode_path_param(entity_id)}",
|
73
|
+
json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
|
74
|
+
)
|
75
|
+
content = response.json()
|
76
|
+
ref = PcrRef.model_validate(content)
|
77
|
+
if with_response:
|
78
|
+
return ref, response
|
79
|
+
return ref
|
@@ -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,79 @@
|
|
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
|
+
from typing import Literal, overload
|
17
|
+
|
18
|
+
from requests import Response
|
19
|
+
|
20
|
+
from openepd.api.base_sync_client import BaseApiMethodGroup
|
21
|
+
from openepd.api.utils import encode_path_param
|
22
|
+
from openepd.model.org import Plant, PlantRef
|
23
|
+
|
24
|
+
|
25
|
+
class PlantApi(BaseApiMethodGroup):
|
26
|
+
"""API methods for Plants."""
|
27
|
+
|
28
|
+
@overload
|
29
|
+
def create(self, to_create: Plant, with_response: Literal[True]) -> tuple[PlantRef, Response]: ...
|
30
|
+
|
31
|
+
@overload
|
32
|
+
def create(self, to_create: Plant, with_response: Literal[False] = False) -> PlantRef: ...
|
33
|
+
|
34
|
+
def create(self, to_create: Plant, with_response: bool = False) -> PlantRef | tuple[PlantRef, Response]:
|
35
|
+
"""
|
36
|
+
Create a new plant.
|
37
|
+
|
38
|
+
:param to_create: Plant to create
|
39
|
+
:param with_response: if True, return a tuple of (PlantRef, Response), otherwise return only PlantRef
|
40
|
+
:return: Plant reference or Plant reference with HTTP Response object depending on parameter
|
41
|
+
:raise ValidationError: if given object Plant is invalid
|
42
|
+
"""
|
43
|
+
response = self._client.do_request("post", "/plants", json=to_create.to_serializable())
|
44
|
+
content = response.json()
|
45
|
+
ref = PlantRef.model_validate(content)
|
46
|
+
if with_response:
|
47
|
+
return ref, response
|
48
|
+
return ref
|
49
|
+
|
50
|
+
@overload
|
51
|
+
def edit(self, to_edit: Plant, with_response: Literal[True]) -> tuple[PlantRef, Response]: ...
|
52
|
+
|
53
|
+
@overload
|
54
|
+
def edit(self, to_edit: Plant, with_response: Literal[False] = False) -> PlantRef: ...
|
55
|
+
|
56
|
+
def edit(self, to_edit: Plant, with_response: bool = False) -> PlantRef | tuple[PlantRef, Response]:
|
57
|
+
"""
|
58
|
+
Edit a plant.
|
59
|
+
|
60
|
+
:param to_edit: Plant to edit
|
61
|
+
:param with_response: if True, return a tuple of (PlantRef, Response), otherwise return only PlantRef
|
62
|
+
:return: Plant reference or Plant reference with HTTP Response object depending on parameter
|
63
|
+
:raise ValueError: if the plant ID is not set
|
64
|
+
"""
|
65
|
+
entity_id = to_edit.id
|
66
|
+
if not entity_id:
|
67
|
+
msg = "The plant ID must be set to edit a plant."
|
68
|
+
raise ValueError(msg)
|
69
|
+
response = self._client.do_request(
|
70
|
+
"put",
|
71
|
+
f"/plants/{encode_path_param(entity_id)}",
|
72
|
+
json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
|
73
|
+
)
|
74
|
+
response.raise_for_status()
|
75
|
+
content = response.json()
|
76
|
+
ref = PlantRef.model_validate(content)
|
77
|
+
if with_response:
|
78
|
+
return ref, response
|
79
|
+
return ref
|
@@ -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,79 @@
|
|
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
|
+
from typing import Literal, overload
|
17
|
+
|
18
|
+
from requests import Response
|
19
|
+
|
20
|
+
from openepd.api.base_sync_client import BaseApiMethodGroup
|
21
|
+
from openepd.api.utils import encode_path_param
|
22
|
+
from openepd.model.standard import Standard, StandardRef
|
23
|
+
|
24
|
+
|
25
|
+
class StandardApi(BaseApiMethodGroup):
|
26
|
+
"""API methods for Standards."""
|
27
|
+
|
28
|
+
@overload
|
29
|
+
def create(self, to_create: Standard, with_response: Literal[True]) -> tuple[StandardRef, Response]: ...
|
30
|
+
|
31
|
+
@overload
|
32
|
+
def create(self, to_create: Standard, with_response: Literal[False] = False) -> StandardRef: ...
|
33
|
+
|
34
|
+
def create(self, to_create: Standard, with_response: bool = False) -> StandardRef | tuple[StandardRef, Response]:
|
35
|
+
"""
|
36
|
+
Create a new standard.
|
37
|
+
|
38
|
+
:param to_create: Standard to create
|
39
|
+
:param with_response: if True, return a tuple of (StandardRef, Response), otherwise return only StandardRef
|
40
|
+
:return: Standard reference or Standard reference with HTTP Response object depending on parameter
|
41
|
+
:raise ValidationError: if given object Standard is invalid
|
42
|
+
"""
|
43
|
+
response = self._client.do_request("post", "/standards", json=to_create.to_serializable())
|
44
|
+
content = response.json()
|
45
|
+
ref = StandardRef.model_validate(content)
|
46
|
+
if with_response:
|
47
|
+
return ref, response
|
48
|
+
return ref
|
49
|
+
|
50
|
+
@overload
|
51
|
+
def edit(self, to_edit: Standard, with_response: Literal[True]) -> tuple[StandardRef, Response]: ...
|
52
|
+
|
53
|
+
@overload
|
54
|
+
def edit(self, to_edit: Standard, with_response: Literal[False] = False) -> StandardRef: ...
|
55
|
+
|
56
|
+
def edit(self, to_edit: Standard, with_response: bool = False) -> StandardRef | tuple[StandardRef, Response]:
|
57
|
+
"""
|
58
|
+
Edit a standard.
|
59
|
+
|
60
|
+
:param to_edit: Standard to edit
|
61
|
+
:param with_response: if True, return a tuple of (StandardRef, Response), otherwise return only StandardRef
|
62
|
+
:return: Standard reference or Standard reference with HTTP Response object depending on parameter
|
63
|
+
:raise ValueError: if the standard short_name is not set
|
64
|
+
"""
|
65
|
+
entity_id = to_edit.short_name
|
66
|
+
if not entity_id:
|
67
|
+
msg = "The standard short_name must be set to edit a standard."
|
68
|
+
raise ValueError(msg)
|
69
|
+
response = self._client.do_request(
|
70
|
+
"put",
|
71
|
+
f"/standards/{encode_path_param(entity_id)}",
|
72
|
+
json=to_edit.to_serializable(exclude_unset=True, exclude_defaults=True, by_alias=True),
|
73
|
+
)
|
74
|
+
response.raise_for_status()
|
75
|
+
content = response.json()
|
76
|
+
ref = StandardRef.model_validate(content)
|
77
|
+
if with_response:
|
78
|
+
return ref, response
|
79
|
+
return ref
|
openepd/api/sync_client.py
CHANGED
@@ -22,7 +22,10 @@ from openepd.api.average_dataset.industry_epd_sync_api import IndustryEpdApi
|
|
22
22
|
from openepd.api.base_sync_client import SyncHttpClient, TokenAuth
|
23
23
|
from openepd.api.category.sync_api import CategoryApi
|
24
24
|
from openepd.api.epd.sync_api import EpdApi
|
25
|
+
from openepd.api.org.sync_api import OrgApi
|
25
26
|
from openepd.api.pcr.sync_api import PcrApi
|
27
|
+
from openepd.api.plant.sync_api import PlantApi
|
28
|
+
from openepd.api.standard.sync_api import StandardApi
|
26
29
|
|
27
30
|
|
28
31
|
class OpenEpdApiClientSync:
|
@@ -41,6 +44,9 @@ class OpenEpdApiClientSync:
|
|
41
44
|
self._http_client = SyncHttpClient(base_url, auth=auth, **kwargs)
|
42
45
|
self.__epd_api: EpdApi | None = None
|
43
46
|
self.__pcr_api: PcrApi | None = None
|
47
|
+
self.__org_api: OrgApi | None = None
|
48
|
+
self.__plant_api: PlantApi | None = None
|
49
|
+
self.__standard_api: StandardApi | None = None
|
44
50
|
self.__category_api: CategoryApi | None = None
|
45
51
|
self.__generic_estimate_api: GenericEstimateApi | None = None
|
46
52
|
self.__industry_epd_api: IndustryEpdApi | None = None
|
@@ -59,6 +65,27 @@ class OpenEpdApiClientSync:
|
|
59
65
|
self.__pcr_api = PcrApi(self._http_client)
|
60
66
|
return self.__pcr_api
|
61
67
|
|
68
|
+
@property
|
69
|
+
def orgs(self) -> OrgApi:
|
70
|
+
"""Get the Org API."""
|
71
|
+
if self.__org_api is None:
|
72
|
+
self.__org_api = OrgApi(self._http_client)
|
73
|
+
return self.__org_api
|
74
|
+
|
75
|
+
@property
|
76
|
+
def plants(self) -> PlantApi:
|
77
|
+
"""Get the Plant API."""
|
78
|
+
if self.__plant_api is None:
|
79
|
+
self.__plant_api = PlantApi(self._http_client)
|
80
|
+
return self.__plant_api
|
81
|
+
|
82
|
+
@property
|
83
|
+
def standards(self) -> StandardApi:
|
84
|
+
"""Get the Standard API."""
|
85
|
+
if self.__standard_api is None:
|
86
|
+
self.__standard_api = StandardApi(self._http_client)
|
87
|
+
return self.__standard_api
|
88
|
+
|
62
89
|
@property
|
63
90
|
def categories(self) -> CategoryApi:
|
64
91
|
"""Get the Category API."""
|
openepd/bundle/base.py
CHANGED
@@ -14,8 +14,9 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
import abc
|
17
|
+
from collections.abc import Callable, Iterator, Sequence
|
17
18
|
import csv
|
18
|
-
from typing import IO,
|
19
|
+
from typing import IO, Self
|
19
20
|
|
20
21
|
from openepd.bundle.model import AssetInfo, AssetType, BundleManifest, RelType
|
21
22
|
from openepd.model.base import TOpenEpdObject
|
@@ -63,6 +64,46 @@ class BundleMixin:
|
|
63
64
|
else:
|
64
65
|
return asset_ref
|
65
66
|
|
67
|
+
@classmethod
|
68
|
+
def _asset_refs_to_str(cls, asset_refs: AssetRef | list[AssetRef] | None) -> list[str] | str | None:
|
69
|
+
"""Convert single or multiple asset references to strings."""
|
70
|
+
if asset_refs is None:
|
71
|
+
return None
|
72
|
+
if isinstance(asset_refs, list):
|
73
|
+
return [cls._asset_ref_to_str(asset_ref) for asset_ref in asset_refs]
|
74
|
+
else:
|
75
|
+
return cls._asset_ref_to_str(asset_refs)
|
76
|
+
|
77
|
+
@classmethod
|
78
|
+
def _serialize_rel_asset_for_csv(cls, rel_asset: list[str] | str | None) -> str | None:
|
79
|
+
"""
|
80
|
+
Serialize rel_asset for CSV storage.
|
81
|
+
|
82
|
+
Multiple assets are joined with semicolons.
|
83
|
+
"""
|
84
|
+
if rel_asset is None:
|
85
|
+
return None
|
86
|
+
if isinstance(rel_asset, list):
|
87
|
+
# For empty list, return None. For non-empty list, join with semicolons
|
88
|
+
return ";".join(rel_asset) if rel_asset else None
|
89
|
+
else:
|
90
|
+
# Single asset - return as string
|
91
|
+
return str(rel_asset)
|
92
|
+
|
93
|
+
@classmethod
|
94
|
+
def _deserialize_rel_asset_from_csv(cls, rel_asset_str: str | None) -> list[str] | str | None:
|
95
|
+
"""
|
96
|
+
Deserialize rel_asset from CSV storage.
|
97
|
+
|
98
|
+
Semicolon-separated values become lists.
|
99
|
+
"""
|
100
|
+
if rel_asset_str is None or rel_asset_str == "":
|
101
|
+
return None
|
102
|
+
if ";" in rel_asset_str:
|
103
|
+
return rel_asset_str.split(";")
|
104
|
+
else:
|
105
|
+
return rel_asset_str
|
106
|
+
|
66
107
|
|
67
108
|
class BaseBundleReader(BundleMixin, metaclass=abc.ABCMeta):
|
68
109
|
"""Base class for bundle readers."""
|
@@ -70,7 +111,7 @@ class BaseBundleReader(BundleMixin, metaclass=abc.ABCMeta):
|
|
70
111
|
def __enter__(self) -> Self:
|
71
112
|
return self
|
72
113
|
|
73
|
-
def __exit__(self, type, value, traceback):
|
114
|
+
def __exit__(self, type, value, traceback): # noqa: A002
|
74
115
|
self.close()
|
75
116
|
|
76
117
|
@abc.abstractmethod
|
@@ -133,7 +174,7 @@ class BaseBundleReader(BundleMixin, metaclass=abc.ABCMeta):
|
|
133
174
|
pass
|
134
175
|
|
135
176
|
@abc.abstractmethod
|
136
|
-
def read_object_asset(self, obj_class:
|
177
|
+
def read_object_asset(self, obj_class: type[TOpenEpdObject], asset_ref: AssetRef) -> TOpenEpdObject:
|
137
178
|
"""Read an object asset by given reference."""
|
138
179
|
pass
|
139
180
|
|
@@ -171,7 +212,7 @@ class BaseBundleWriter(BundleMixin, metaclass=abc.ABCMeta):
|
|
171
212
|
def __enter__(self) -> Self:
|
172
213
|
return self
|
173
214
|
|
174
|
-
def __exit__(self, type, value, traceback):
|
215
|
+
def __exit__(self, type, value, traceback): # noqa: A002
|
175
216
|
self.close()
|
176
217
|
|
177
218
|
@abc.abstractmethod
|
@@ -179,7 +220,7 @@ class BaseBundleWriter(BundleMixin, metaclass=abc.ABCMeta):
|
|
179
220
|
self,
|
180
221
|
data: IO[bytes],
|
181
222
|
content_type: str | None,
|
182
|
-
rel_asset: AssetRef | None = None,
|
223
|
+
rel_asset: AssetRef | list[AssetRef] | None = None,
|
183
224
|
rel_type: str | None = None,
|
184
225
|
file_name: str | None = None,
|
185
226
|
name: str | None = None,
|
@@ -195,7 +236,7 @@ class BaseBundleWriter(BundleMixin, metaclass=abc.ABCMeta):
|
|
195
236
|
def write_object_asset(
|
196
237
|
self,
|
197
238
|
obj: TOpenEpdObject,
|
198
|
-
rel_asset: AssetRef | None = None,
|
239
|
+
rel_asset: AssetRef | list[AssetRef] | None = None,
|
199
240
|
rel_type: str | None = None,
|
200
241
|
file_name: str | None = None,
|
201
242
|
name: str | None = None,
|
openepd/bundle/model.py
CHANGED
@@ -80,6 +80,7 @@ class AssetInfo(BaseOpenEpdSchema):
|
|
80
80
|
"""The language of the asset."""
|
81
81
|
rel_type: str | None
|
82
82
|
rel_asset: str | None
|
83
|
+
"""The related asset reference (serialized as semicolon-separated for multiple assets)."""
|
83
84
|
comment: str | None = pydantic.Field(default=None)
|
84
85
|
content_type: str | None = pydantic.Field(default=None)
|
85
86
|
size: int | None = pydantic.Field(default=None)
|