From a2ee4c8fefa11a8b81fc2da595da9f26acb79bcb Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 21 Jan 2021 10:45:37 +0100 Subject: [PATCH] Add a new pass-through module for resinsight_classes.py to aid documentation --- ApplicationExeCode/CMakeLists.txt | 6 ++-- GrpcInterface/Python/rips/__init__.py | 2 +- GrpcInterface/Python/rips/case.py | 10 +++--- GrpcInterface/Python/rips/contour_map.py | 2 +- GrpcInterface/Python/rips/gridcasegroup.py | 14 ++++---- GrpcInterface/Python/rips/pdmobject.py | 18 +++++----- GrpcInterface/Python/rips/plot.py | 4 +-- GrpcInterface/Python/rips/project.py | 34 +++++++++---------- .../Python/rips/resinsight_classes.py | 1 + GrpcInterface/Python/rips/simulation_well.py | 2 +- GrpcInterface/Python/rips/view.py | 2 +- GrpcInterface/Python/rips/well_log_plot.py | 2 +- 12 files changed, 50 insertions(+), 47 deletions(-) create mode 100644 GrpcInterface/Python/rips/resinsight_classes.py diff --git a/ApplicationExeCode/CMakeLists.txt b/ApplicationExeCode/CMakeLists.txt index eada749c1b..7aa27f668e 100644 --- a/ApplicationExeCode/CMakeLists.txt +++ b/ApplicationExeCode/CMakeLists.txt @@ -355,7 +355,7 @@ endforeach() # Generate Python code in a target that is part of ALL_BUILD and depends on # ResInsight if(RESINSIGHT_ENABLE_GRPC) - set(GENERATED_CLASSES_FILE ${CMAKE_SOURCE_DIR}/GrpcInterface/Python/rips/generated/resinsight_classes.py) + set(GENERATED_CLASSES_FILE ${CMAKE_SOURCE_DIR}/GrpcInterface/Python/rips/generated/generated_classes.py) add_custom_command( OUTPUT ${GENERATED_CLASSES_FILE} @@ -548,7 +548,7 @@ if(RESINSIGHT_PRIVATE_INSTALL) DESTINATION ${RESINSIGHT_INSTALL_FOLDER}) endif() - # install GRPC-related DLLs and resinsight_classes.py + # install GRPC-related DLLs and generated_classes.py if(RESINSIGHT_ENABLE_GRPC) set(ZLIB_DLL "$,zlibd1,zlib1>") set(PROTOBUF_DLL "$,libprotobufd,libprotobuf>") @@ -559,7 +559,7 @@ if(RESINSIGHT_PRIVATE_INSTALL) endforeach(dllname ${GRPC_DLL_NAMES}) install( FILES - ${CMAKE_SOURCE_DIR}/GrpcInterface/Python/rips/generated/resinsight_classes.py + ${CMAKE_SOURCE_DIR}/GrpcInterface/Python/rips/generated/generated_classes.py DESTINATION ${RESINSIGHT_INSTALL_FOLDER}/Python/rips/generated) endif() diff --git a/GrpcInterface/Python/rips/__init__.py b/GrpcInterface/Python/rips/__init__.py index 48ecc963e6..9220d3dc67 100644 --- a/GrpcInterface/Python/rips/__init__.py +++ b/GrpcInterface/Python/rips/__init__.py @@ -4,7 +4,7 @@ import os import sys sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated')) -from resinsight_classes import * +from .resinsight_classes import * from .case import Case, EclipseCase, GeoMechCase from .grid import Grid diff --git a/GrpcInterface/Python/rips/case.py b/GrpcInterface/Python/rips/case.py index 4d48c17575..c1e65e7861 100644 --- a/GrpcInterface/Python/rips/case.py +++ b/GrpcInterface/Python/rips/case.py @@ -58,7 +58,7 @@ import Properties_pb2 import Properties_pb2_grpc import NNCProperties_pb2 import NNCProperties_pb2_grpc -from resinsight_classes import Case, EclipseCase, GeoMechCase, WellBoreStabilityPlot, WbsParameters +from .resinsight_classes import Case, EclipseCase, GeoMechCase, WellBoreStabilityPlot, WbsParameters from .grid import Grid from .pdmobject import add_method @@ -321,7 +321,7 @@ def view(self, view_id): view_id(int): view id Returns: - :class:`rips.generated.resinsight_classes.View` + :class:`rips.generated.generated_classes.View` """ views = self.views() for view_object in views: @@ -335,7 +335,7 @@ def create_view(self): """Create a new view in the current case Returns: - :class:`rips.generated.resinsight_classes.View` + :class:`rips.generated.generated_classes.View` """ return self.view( self._execute_command(createView=Cmd.CreateViewRequest( @@ -924,7 +924,7 @@ def create_well_bore_stability_plot(self, well_path, time_step, parameters=None) time_step(int): time step Returns: - :class:`rips.generated.resinsight_classes.WellBoreStabilityPlot` + :class:`rips.generated.generated_classes.WellBoreStabilityPlot` """ pb2_parameters = None if parameters is not None: @@ -962,7 +962,7 @@ def simulation_wells(self): """Get a list of all simulation wells for a case Returns: - :class:`rips.generated.resinsight_classes.SimulationWell` + :class:`rips.generated.generated_classes.SimulationWell` """ wells = self.descendants(SimulationWell) diff --git a/GrpcInterface/Python/rips/contour_map.py b/GrpcInterface/Python/rips/contour_map.py index 0e2f6b87ea..f3f3816319 100644 --- a/GrpcInterface/Python/rips/contour_map.py +++ b/GrpcInterface/Python/rips/contour_map.py @@ -5,7 +5,7 @@ import Commands_pb2 from .pdmobject import add_method from .view import View -from resinsight_classes import EclipseContourMap, GeoMechContourMap +from .resinsight_classes import EclipseContourMap, GeoMechContourMap @add_method(EclipseContourMap) diff --git a/GrpcInterface/Python/rips/gridcasegroup.py b/GrpcInterface/Python/rips/gridcasegroup.py index bebcc13a67..3373ffbebb 100644 --- a/GrpcInterface/Python/rips/gridcasegroup.py +++ b/GrpcInterface/Python/rips/gridcasegroup.py @@ -7,7 +7,7 @@ from .view import View from .case import Case import Commands_pb2 -from resinsight_classes import GridCaseGroup +from .resinsight_classes import GridCaseGroup @add_method(GridCaseGroup) @@ -15,7 +15,7 @@ def create_statistics_case(self): """Create a Statistics case in the Grid Case Group Returns: - :class:`rips.generated.resinsight_classes.EclipseCase` + :class:`rips.generated.generated_classes.EclipseCase` """ command_reply = self._execute_command( createStatisticsCase=Commands_pb2.CreateStatisticsCaseRequest( @@ -29,7 +29,7 @@ def statistics_cases(self): """Get a list of all statistics cases in the Grid Case Group Returns: - List of :class:`rips.generated.resinsight_classes.EclipseCase` + List of :class:`rips.generated.generated_classes.EclipseCase` """ stat_case_collection = self.children("StatisticsCaseCollection")[0] @@ -41,12 +41,12 @@ def views(self): """Get a list of views belonging to a grid case group Returns: - List of :class:`rips.generated.resinsight_classes.EclipseView` + List of :class:`rips.generated.generated_classes.EclipseView` """ - resinsight_classes = self.descendants(EclipseView) + generated_classes = self.descendants(EclipseView) view_list = [] - for pdm_object in resinsight_classes: + for pdm_object in generated_classes: view_list.append(pdm_object) return view_list @@ -58,7 +58,7 @@ def view(self, view_id): id(int): view id Returns: - List of :class:`rips.generated.resinsight_classes.EclipseView` + List of :class:`rips.generated.generated_classes.EclipseView` """ views = self.views() diff --git a/GrpcInterface/Python/rips/pdmobject.py b/GrpcInterface/Python/rips/pdmobject.py index c30d8351fa..9991152947 100644 --- a/GrpcInterface/Python/rips/pdmobject.py +++ b/GrpcInterface/Python/rips/pdmobject.py @@ -15,8 +15,6 @@ import PdmObject_pb2 import PdmObject_pb2_grpc import Commands_pb2 import Commands_pb2_grpc -import resinsight_classes as ClassList - def camel_to_snake(name): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) @@ -214,10 +212,11 @@ class PdmObjectBase: values.append(self.__convert_from_grpc_value(string)) return values - def __from_pb2_to_resinsight_classes(self, pb2_object_list, super_class_definition): + def __from_pb2_to_generated_classes(self, pb2_object_list, super_class_definition): pdm_object_list = [] + from .generated.generated_classes import class_from_keyword for pb2_object in pb2_object_list: - child_class_definition = ClassList.class_from_keyword(pb2_object.class_keyword) + child_class_definition = class_from_keyword(pb2_object.class_keyword) if child_class_definition is None: child_class_definition = super_class_definition @@ -241,7 +240,7 @@ class PdmObjectBase: object=self._pb2_object, child_keyword=class_keyword) object_list = self._pdm_object_stub.GetDescendantPdmObjects( request).objects - return self.__from_pb2_to_resinsight_classes(object_list, class_definition) + return self.__from_pb2_to_generated_classes(object_list, class_definition) except grpc.RpcError as e: if e.code() == grpc.StatusCode.NOT_FOUND: return [] # Valid empty result @@ -258,7 +257,7 @@ class PdmObjectBase: child_field=child_field) try: object_list = self._pdm_object_stub.GetChildPdmObjects(request).objects - return self.__from_pb2_to_resinsight_classes(object_list, class_definition) + return self.__from_pb2_to_generated_classes(object_list, class_definition) except grpc.RpcError as e: if e.code() == grpc.StatusCode.NOT_FOUND: return [] @@ -272,12 +271,13 @@ class PdmObjectBase: assert(inspect.isclass(class_definition)) class_keyword = class_definition.__name__ + from .generated.generated_classes import class_from_keyword request = PdmObject_pb2.PdmParentObjectRequest( object=self._pb2_object, parent_keyword=class_keyword) try: pb2_object = self._pdm_object_stub.GetAncestorPdmObject(request) - child_class_definition = ClassList.class_from_keyword(pb2_object.class_keyword) + child_class_definition = class_from_keyword(pb2_object.class_keyword) if child_class_definition is None: child_class_definition = class_definition @@ -351,7 +351,9 @@ class PdmObjectBase: pb2_object = self._pdm_object_stub.CallPdmObjectMethod(request) - child_class_definition = ClassList.class_from_keyword(pb2_object.class_keyword) + from .generated.generated_classes import class_from_keyword + + child_class_definition = class_from_keyword(pb2_object.class_keyword) if child_class_definition is None: return None diff --git a/GrpcInterface/Python/rips/plot.py b/GrpcInterface/Python/rips/plot.py index c2a64d19ed..2ab6b5bd66 100644 --- a/GrpcInterface/Python/rips/plot.py +++ b/GrpcInterface/Python/rips/plot.py @@ -3,8 +3,8 @@ ResInsight 2d plot module """ import Commands_pb2 -from .pdmobject import PdmObjectBase, add_method -from resinsight_classes import PlotWindow, Plot +from .pdmobject import add_method +from .resinsight_classes import PlotWindow, Plot @add_method(PlotWindow) diff --git a/GrpcInterface/Python/rips/project.py b/GrpcInterface/Python/rips/project.py index 7462ec1813..ee9752e3a0 100644 --- a/GrpcInterface/Python/rips/project.py +++ b/GrpcInterface/Python/rips/project.py @@ -17,7 +17,7 @@ from Definitions_pb2 import Empty import Project_pb2_grpc import Project_pb2 import PdmObject_pb2 -from resinsight_classes import Project, PlotWindow, WellPath, SummaryCase +from .resinsight_classes import Project, PlotWindow, WellPath, SummaryCase @add_method(Project) @@ -68,7 +68,7 @@ def load_case(self, path): Arguments: path(str): file path to case Returns: - :class:`rips.generated.resinsight_classes.Case` + :class:`rips.generated.generated_classes.Case` """ command_reply = self._execute_command(loadCase=Commands_pb2.FilePathRequest( path=path)) @@ -80,7 +80,7 @@ def selected_cases(self): """Get a list of all grid cases selected in the project tree Returns: - A list of :class:`rips.generated.resinsight_classes.Case` + A list of :class:`rips.generated.generated_classes.Case` """ case_infos = self._project_stub.GetSelectedCases(Empty()) cases = [] @@ -94,7 +94,7 @@ def cases(self): """Get a list of all grid cases in the project Returns: - A list of :class:`rips.generated.resinsight_classes.Case` + A list of :class:`rips.generated.generated_classes.Case` """ return self.descendants(Case) @@ -106,7 +106,7 @@ def case(self, case_id): Arguments: id(int): case id Returns: - :class:`rips.generated.resinsight_classes.Case` + :class:`rips.generated.generated_classes.Case` """ allCases = self.cases() for case in allCases: @@ -135,7 +135,7 @@ def create_grid_case_group(self, case_paths): Arguments: case_paths (list): list of file path strings Returns: - :class:`rips.generated.resinsight_classes.GridCaseGroup` + :class:`rips.generated.generated_classes.GridCaseGroup` """ command_reply = self._execute_command( createGridCaseGroup=Commands_pb2.CreateGridCaseGroupRequest( @@ -147,7 +147,7 @@ def create_grid_case_group(self, case_paths): def summary_cases(self): """Get a list of all summary cases in the Project - Returns: A list of :class:`rips.generated.resinsight_classes.SummaryCase` + Returns: A list of :class:`rips.generated.generated_classes.SummaryCase` """ return self.descendants(SummaryCase) @@ -164,7 +164,7 @@ def view(self, view_id): Arguments: view_id(int): view id Returns: - :class:`rips.generated.resinsight_classes.View` + :class:`rips.generated.generated_classes.View` """ views = self.views() for view_object in views: @@ -178,11 +178,11 @@ def plots(self): """Get a list of all plots belonging to a project Returns: - List of :class:`rips.generated.resinsight_classes.Plot` + List of :class:`rips.generated.generated_classes.Plot` """ - resinsight_classes = self.descendants(PlotWindow) + generated_classes = self.descendants(PlotWindow) plot_list = [] - for pdm_object in resinsight_classes: + for pdm_object in generated_classes: if pdm_object.id != -1: plot_list.append(pdm_object) return plot_list @@ -196,7 +196,7 @@ def plot(self, view_id): view_id(int): view id Returns: - :class:`rips.generated.resinsight_classes.Plot` + :class:`rips.generated.generated_classes.Plot` """ plots = self.plots() for plot_object in plots: @@ -210,7 +210,7 @@ def grid_case_groups(self): """Get a list of all grid case groups in the project Returns: - List of :class:`rips.generated.resinsight_classes.GridCaseGroup` + List of :class:`rips.generated.generated_classes.GridCaseGroup` """ case_groups = self.descendants(GridCaseGroup) @@ -225,7 +225,7 @@ def grid_case_group(self, group_id): groupId(int): group id Returns: - :class:`rips.generated.resinsight_classes.GridCaseGroup` + :class:`rips.generated.generated_classes.GridCaseGroup` """ case_groups = self.grid_case_groups() for case_group in case_groups: @@ -320,7 +320,7 @@ def import_well_paths(self, well_path_files=None, well_path_folder=''): well_path_folder(str): A folder path containing files to import Returns: - List of :class:`rips.generated.resinsight_classes.WellPath` + List of :class:`rips.generated.generated_classes.WellPath` """ if well_path_files is None: well_path_files = [] @@ -338,7 +338,7 @@ def well_paths(self): """Get a list of all well paths in the project Returns: - List of :class:`rips.generated.resinsight_classes.WellPath` + List of :class:`rips.generated.generated_classes.WellPath` """ return self.descendants(WellPath) @@ -348,7 +348,7 @@ def well_path_by_name(self, well_path_name): """Get a specific well path by name from the project Returns: - :class:`rips.generated.resinsight_classes.WellPath` + :class:`rips.generated.generated_classes.WellPath` """ all_well_paths = self.well_paths() for well_path in all_well_paths: diff --git a/GrpcInterface/Python/rips/resinsight_classes.py b/GrpcInterface/Python/rips/resinsight_classes.py new file mode 100644 index 0000000000..846a021405 --- /dev/null +++ b/GrpcInterface/Python/rips/resinsight_classes.py @@ -0,0 +1 @@ +from .generated.generated_classes import * diff --git a/GrpcInterface/Python/rips/simulation_well.py b/GrpcInterface/Python/rips/simulation_well.py index aafc3d7ec0..b6bf09c18d 100644 --- a/GrpcInterface/Python/rips/simulation_well.py +++ b/GrpcInterface/Python/rips/simulation_well.py @@ -9,7 +9,7 @@ import SimulationWell_pb2_grpc import Properties_pb2 import Properties_pb2_grpc -from resinsight_classes import SimulationWell +from .resinsight_classes import SimulationWell from .pdmobject import PdmObjectBase, add_method diff --git a/GrpcInterface/Python/rips/view.py b/GrpcInterface/Python/rips/view.py index 60dd2ab76e..a3120b996d 100644 --- a/GrpcInterface/Python/rips/view.py +++ b/GrpcInterface/Python/rips/view.py @@ -7,7 +7,7 @@ import Commands_pb2 as Cmd import rips.case # Circular import of Case, which already imports View. Use full name. from .pdmobject import add_method -from resinsight_classes import View, ViewWindow, EclipseView, GeoMechView +from .resinsight_classes import View, ViewWindow, EclipseView, GeoMechView @add_method(View) diff --git a/GrpcInterface/Python/rips/well_log_plot.py b/GrpcInterface/Python/rips/well_log_plot.py index f457450fa4..2186445c47 100644 --- a/GrpcInterface/Python/rips/well_log_plot.py +++ b/GrpcInterface/Python/rips/well_log_plot.py @@ -6,7 +6,7 @@ import Commands_pb2 from .plot import Plot from .pdmobject import PdmObjectBase, add_method -from resinsight_classes import WellLogPlot +from .resinsight_classes import WellLogPlot @add_method(WellLogPlot)