mirror of
https://github.com/OPM/ResInsight.git
synced 2026-08-27 05:37:21 -05:00
Python: Import rips.orion_events explicitly in examples
Roll back the __getattr__ lazy-import hook in rips/__init__.py. The hook existed only so that a plain import rips would expose rips.orion_events as an attribute; that eager exposure is also what triggered runpy's found in sys.modules warning under python -m rips.orion_events. Instead do not auto-expose the submodule from the package and have the two examples import rips.orion_events explicitly, which is idiomatic and warning-free.
This commit is contained in:
@@ -20,6 +20,7 @@ an Eclipse case is already loaded.
|
||||
import os
|
||||
|
||||
import rips
|
||||
import rips.orion_events
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
+1
@@ -22,6 +22,7 @@ works with any project that has at least one well path.
|
||||
"""
|
||||
|
||||
import rips
|
||||
import rips.orion_events
|
||||
|
||||
|
||||
def build_orion_text(well_name):
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from types import ModuleType
|
||||
from typing import List
|
||||
|
||||
# Configure null handler to prevent "No handler found" warnings
|
||||
@@ -31,18 +30,6 @@ 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
|
||||
|
||||
|
||||
def __getattr__(name: str) -> ModuleType:
|
||||
# Lazy import (PEP 562) so `python -m rips.orion_events` does not trigger
|
||||
# runpy's "found in sys.modules after import of package" warning while
|
||||
# `rips.orion_events` still resolves after a plain `import rips`.
|
||||
if name == "orion_events":
|
||||
import importlib
|
||||
|
||||
return importlib.import_module(".orion_events", __name__)
|
||||
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
||||
|
||||
|
||||
__all__: List[str] = []
|
||||
for key in class_dict(): # noqa: F405
|
||||
__all__.append(key)
|
||||
|
||||
Reference in New Issue
Block a user