temporary support for deprecated api arguments #4531

This commit is contained in:
Andrej730
2024-04-08 15:47:31 +05:00
parent d24e5df7c1
commit d764c0af23
4 changed files with 121 additions and 4 deletions
@@ -24,12 +24,37 @@ import importlib
import ifcopenshell
import ifcopenshell.api
from typing import Callable, Any, Optional
from functools import partial
pre_listeners = {}
post_listeners = {}
def batching_argument_deprecation(usecase_path: str, settings: dict, prev_argument: str, new_argument: str) -> dict:
if prev_argument in settings:
print(
f"WARNING. `{prev_argument}` argument is deprecated for API method "
f'"{usecase_path}" and should be replaced with `{new_argument}`.'
)
settings = settings | {new_argument: [settings[prev_argument]]}
settings.pop(prev_argument)
return settings
ARGUMENTS_DEPRECATION = {
"spatial.assign_container": partial(
batching_argument_deprecation, prev_argument="product", new_argument="products"
),
"spatial.unassign_container": partial(
batching_argument_deprecation, prev_argument="product", new_argument="products"
),
"group.unassign_group": partial(batching_argument_deprecation, prev_argument="product", new_argument="products"),
"layer.assign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
"layer.unassign_layer": partial(batching_argument_deprecation, prev_argument="item", new_argument="items"),
}
def run(
usecase_path: str,
ifc_file: Optional[ifcopenshell.file] = None,
@@ -40,6 +65,10 @@ def run(
for listener in pre_listeners.get(usecase_path, {}).values():
listener(usecase_path, ifc_file, settings)
# see #4531
if usecase_path in ARGUMENTS_DEPRECATION:
settings = ARGUMENTS_DEPRECATION[usecase_path](usecase_path, settings)
# TODO: settings serialization for client-server systems
# def serialise_entity_instance(entity):
# return {"cast_type": "entity_instance", "value": entity.id(), "Name": getattr(entity, "Name", None)}