#13982 Python: Tighten Instance.launch/find return type and drop dead None checks

Instance.launch and Instance.find now always either return a connected
Instance or raise RipsError, so their return type narrows from
Optional[Instance] to Instance. In launch(), the unreachable `if pid:`
guard around the Popen result and the trailing `return None` are
removed; the only failure paths raise RipsError.

Update the PythonExamples that previously branched on a None return:
- Drop `if resinsight is None: exit(1)` style guards and `if resinsight
  is not None:` wrappers; dedent the body where applicable.
- export_corner_point_grid.py used the None check as a fallback to
  launch ResInsight; rewrite as try/except rips.RipsError so the
  fallback still works.
- instance_example.py is repurposed as a try/except example for
  reporting connection failure.
This commit is contained in:
Kristian Bendiksen committed 2026-05-13 13:47:40 +02:00
1 parent 1424a6dc53
commit e7608536cf
18 files changed
+262 -285

No files matched your search

@@ -8,32 +8,32 @@ import rips
# Connect to ResInsight
resinsight = rips.Instance.find()
if resinsight is not None:
# Get a list of all cases
cases = resinsight.project.cases()
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print("Case id: " + str(case.id))
print("Case name: " + case.name)
print("Case type: " + case.__class__.__name__)
print("Case file name: " + case.file_path)
print("Case reservoir bounding box:", case.reservoir_boundingbox())
# Get a list of all cases
cases = resinsight.project.cases()
timesteps = case.time_steps()
for t in timesteps:
print("Year: " + str(t.year))
print("Month: " + str(t.month))
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print("Case id: " + str(case.id))
print("Case name: " + case.name)
print("Case type: " + case.__class__.__name__)
print("Case file name: " + case.file_path)
print("Case reservoir bounding box:", case.reservoir_boundingbox())
if isinstance(case, rips.EclipseCase):
print("Getting coarsening info for case: ", case.name, case.id)
coarsening_info = case.coarsening_info()
if coarsening_info:
print("Coarsening information:")
timesteps = case.time_steps()
for t in timesteps:
print("Year: " + str(t.year))
print("Month: " + str(t.month))
for c in coarsening_info:
print(
"[{}, {}, {}] - [{}, {}, {}]".format(
c.min.x, c.min.y, c.min.z, c.max.x, c.max.y, c.max.z
)
if isinstance(case, rips.EclipseCase):
print("Getting coarsening info for case: ", case.name, case.id)
coarsening_info = case.coarsening_info()
if coarsening_info:
print("Coarsening information:")
for c in coarsening_info:
print(
"[{}, {}, {}] - [{}, {}, {}]".format(
c.min.x, c.min.y, c.min.z, c.max.x, c.max.y, c.max.z
)
)
@@ -3,9 +3,8 @@
#######################################
import rips
resinsight = rips.Instance.find()
if resinsight is None:
print("ERROR: could not find ResInsight")
else:
try:
resinsight = rips.Instance.find()
print("Successfully connected to ResInsight")
except rips.RipsError as e:
print(f"ERROR: could not find ResInsight: {e}")
@@ -8,11 +8,10 @@
import rips
resinsight = rips.Instance.find()
if resinsight is not None:
cases = resinsight.project.selected_cases()
cases = resinsight.project.selected_cases()
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print(case.name)
for property in case.available_properties(rips.PropertyType.DYNAMIC_NATIVE):
print(property)
print("Got " + str(len(cases)) + " cases: ")
for case in cases:
print(case.name)
for property in case.available_properties(rips.PropertyType.DYNAMIC_NATIVE):
print(property)