|
26 | 26 | from libecalc.presentation.yaml.yaml_models.exceptions import DuplicateKeyError, FileContext, YamlError |
27 | 27 | from libecalc.presentation.yaml.yaml_models.yaml_model import YamlConfiguration, YamlValidator |
28 | 28 | from libecalc.presentation.yaml.yaml_node import YamlDict, YamlList |
29 | | -from libecalc.presentation.yaml.yaml_types.components.yaml_asset import YamlAsset |
| 29 | +from libecalc.presentation.yaml.yaml_types.components.yaml_asset import YamlAsset, YamlDefinitions |
30 | 30 | from libecalc.presentation.yaml.yaml_types.components.yaml_installation import YamlInstallation |
31 | 31 | from libecalc.presentation.yaml.yaml_types.facility_model.yaml_facility_model import YamlFacilityModel |
32 | 32 | from libecalc.presentation.yaml.yaml_types.fuel_type.yaml_fuel_type import YamlFuelType |
|
46 | 46 | from libecalc.presentation.yaml.yaml_validation_context import YamlModelValidationContext |
47 | 47 |
|
48 | 48 | # Top-level YAML keywords used only by experimental/new sections |
| 49 | +_DEFINITIONS_KEY = "DEFINITIONS" |
49 | 50 | _PROCESS_UNITS_KEY = "PROCESS_UNITS" |
50 | 51 | _PROCESS_PIPELINES_KEY = "PROCESS_PIPELINES" |
51 | 52 | _INLET_STREAMS_KEY = "INLET_STREAMS" |
|
54 | 55 | _ECALC_EVENTS_KEY = "ECALC_EVENTS" |
55 | 56 | _PROCESS_EVENTS_KEY = "PROCESS_EVENTS" |
56 | 57 | _PUMP_PROCESS_SIMULATIONS_KEY = "PUMP_PROCESS_SIMULATIONS" |
57 | | -_NEW_SECTIONS_WITH_FILE_REFS: tuple[str, ...] = ( |
58 | | - "PROCESS_UNITS", |
59 | | - "PROCESS_PIPELINES", |
60 | | -) |
61 | 58 | dt_adapter = TypeAdapter(datetime.datetime) |
62 | 59 |
|
63 | 60 |
|
@@ -323,8 +320,14 @@ def facility_resource_names(self) -> list[str]: |
323 | 320 | data.get(EcalcYamlKeywords.file) for data in resource_data if data.get(EcalcYamlKeywords.file) is not None |
324 | 321 | ] |
325 | 322 |
|
326 | | - # Pick up FILE references nested in the new YAML sections (PROCESS_UNITS, PROCESS_PIPELINES, ...). |
327 | | - for section in _NEW_SECTIONS_WITH_FILE_REFS: |
| 323 | + # Pick up FILE references nested in the new YAML sections (DEFINITIONS.PROCESS_UNITS, PROCESS_PIPELINES, ...). |
| 324 | + definitions = ( |
| 325 | + self._internal_datamodel.get(_DEFINITIONS_KEY, {}) if isinstance(self._internal_datamodel, dict) else {} |
| 326 | + ) |
| 327 | + if isinstance(definitions, dict): |
| 328 | + for section in ("PROCESS_UNITS",): |
| 329 | + resource_names.extend(_find_file_references(definitions.get(section))) |
| 330 | + for section in ("PROCESS_PIPELINES",): |
328 | 331 | resource_names.extend(_find_file_references(self._internal_datamodel.get(section))) |
329 | 332 |
|
330 | 333 | # Dedup while preserving order — the same CSV may be referenced by multiple charts. |
@@ -451,16 +454,19 @@ def fluid_models(self) -> dict[str, YamlFluidModel]: |
451 | 454 | return fluid_models |
452 | 455 |
|
453 | 456 | @property |
454 | | - def process_units(self) -> dict[str, YamlProcessUnitDefinition]: |
| 457 | + def definitions(self) -> YamlDefinitions: |
455 | 458 | process_units: dict[str, YamlProcessUnitDefinition] = {} |
456 | | - raw = self._get_yaml_dict_or_empty(_PROCESS_UNITS_KEY) |
| 459 | + definitions = ( |
| 460 | + self._internal_datamodel.get(_DEFINITIONS_KEY, {}) if isinstance(self._internal_datamodel, dict) else {} |
| 461 | + ) |
| 462 | + raw = definitions.get(_PROCESS_UNITS_KEY, {}) if isinstance(definitions, dict) else {} |
457 | 463 |
|
458 | 464 | for name, unit_data in raw.items(): |
459 | 465 | try: |
460 | 466 | process_units[name] = TypeAdapter(YamlProcessUnitDefinition).validate_python(unit_data) |
461 | 467 | except PydanticValidationError: |
462 | 468 | pass |
463 | | - return process_units |
| 469 | + return YamlDefinitions(process_units=process_units) |
464 | 470 |
|
465 | 471 | @property |
466 | 472 | def process_pipelines(self) -> dict[str, YamlProcessPipeline]: |
|
0 commit comments