Files
ResInsight/GrpcInterface/Python/rips/__init__.py
T
Kristian Bendiksen 79914f2a00 #13982 Python: Type case API with StrEnum classes for proto enums
The previous commit auto-generated StrEnum classes for caf::AppEnum scriptable
fields, but the hand-written gRPC API in rips.case still accepted bare strings
for proto-backed enums (PropertyType, PropertyDataType, NNCPropertyType) and
the AppEnum-backed PorosityModelType.

Add a new rips.enums module with hand-written StrEnum classes for the three
proto-only enums and reuse the auto-generated PorosityModelType from
resinsight_classes. Re-export the new enums from the rips package and narrow
the parameter type hints across cell_count, cell_info_for_active_cells,
available_properties, active_cell_property, selected_cell_property,
grid_property, set_active_cell_property, set_grid_property,
active_cell_centers, active_cell_corners, set_nnc_connections_values, and
grid_property_for_positions (sync and async variants).

Existing string arguments keep working because StrEnum members are strings
and protobuf's EnumTypeWrapper.Value accepts both. A new
test_10k_grid_property_strenum asserts string and enum forms return the same
data.
2026-05-13 13:47:40 +02:00

59 lines
2.1 KiB
Python

import logging
import os
import sys
from typing import List
# Configure null handler to prevent "No handler found" warnings
logging.getLogger("rips").addHandler(logging.NullHandler())
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "generated"))
from .resinsight_classes import * # noqa: F403, E402
from .case import Case as Case, EclipseCase as EclipseCase, GeoMechCase as GeoMechCase # noqa: E402
from .grid import Grid as Grid # noqa: E402
from .instance import Instance as Instance # noqa: E402
from .view import View as View # noqa: E402
from .project import Project as Project # noqa: E402
from .plot import Plot as Plot, PlotWindow as PlotWindow # noqa: E402
from .contour_map import ( # noqa: E402
EclipseContourMap as EclipseContourMap,
GeoMechContourMap as GeoMechContourMap,
)
from .well_log_plot import WellLogPlot as WellLogPlot # noqa: E402
from .well_path import WellPath as WellPath # noqa: E402
from . import well_log as well_log # noqa: F401, E402
from . import well_path_collection as well_path_collection # noqa: F401, E402
from .simulation_well import SimulationWell as SimulationWell # noqa: E402
from .exception import RipsError as RipsError # noqa: E402
from .surface import RegularSurface as RegularSurface # noqa: E402
from . import well_events as well_events # noqa: F401, E402
from . import category_mapping as category_mapping # noqa: F401, E402
# Enums for proto types not visible to the AppEnum auto-generator.
# PorosityModelType is auto-generated into resinsight_classes (already imported
# above) and intentionally not re-imported here to avoid a duplicate symbol.
from .enums import ( # noqa: E402
PropertyType as PropertyType,
PropertyDataType as PropertyDataType,
NNCPropertyType as NNCPropertyType,
)
__all__: List[str] = []
for key in class_dict(): # noqa: F405
__all__.append(key)
# Add classes not in resinsight_classes
__all__.append("Grid")
__all__.append("Instance")
for _enum_name in (
"PropertyType",
"PropertyDataType",
"NNCPropertyType",
):
if _enum_name not in __all__:
__all__.append(_enum_name)
__all__.sort()