Skip to content

Commit

Permalink
Move ert.shared.plugins to ert.plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Jul 24, 2024
1 parent 5ed8658 commit 42d6fc3
Show file tree
Hide file tree
Showing 90 changed files with 526 additions and 520 deletions.
2 changes: 1 addition & 1 deletion .mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ strict_equality = True
extra_checks = True


exclude = src/ert/shared/share
exclude = src/ert/resources

[mypy-scipy.*]
ignore_missing_imports = True
Expand Down
2 changes: 1 addition & 1 deletion ci/run_ert_ctests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ build_ert_clib () {
run_ctest () {
enable_environment
pushd ${ERT_SOURCE_ROOT}/build
export ERT_SITE_CONFIG=${ERT_SOURCE_ROOT}/src/ert/shared/share/ert/site-config
export ERT_SITE_CONFIG=${ERT_SOURCE_ROOT}/src/ert/resources/site-config
ctest -j$(nproc) -E Lint --output-on-failure
popd
}
Expand Down
12 changes: 6 additions & 6 deletions docs/getting_started/howto/plugin_system.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ The configuration file needed to use the ``installable_workflow_jobs`` hook must
and specify its arguments.
The built-in internal ``CSV_EXPORT`` workflow job is shown as an example:

.. literalinclude:: ../../../src/ert/shared/share/ert/workflows/jobs/internal-gui/config/CSV_EXPORT
.. literalinclude:: ../../../src/ert/resources/workflows/jobs/internal-gui/config/CSV_EXPORT

Implement the hook specification as follows to register the workflow job ``CSV_EXPORT``:

Expand All @@ -149,7 +149,7 @@ Implement the hook specification as follows to register the workflow job ``CSV_E
The second approach does not require creating a workflow job configuration file up-front,
and allows adding documentation.

.. literalinclude:: ../../../src/ert/shared/plugins/hook_specifications/jobs.py
.. literalinclude:: ../../../src/ert/plugins/hook_specifications/jobs.py
:pyobject: legacy_ertscript_workflow

Minimal example:
Expand Down Expand Up @@ -186,22 +186,22 @@ Full example:
The configuration object and properties are as follows.

.. autofunction:: ert.shared.plugins.hook_specifications.jobs.legacy_ertscript_workflow
.. autofunction:: ert.plugins.hook_specifications.jobs.legacy_ertscript_workflow

.. autoclass:: ert.shared.plugins.workflow_config.WorkflowConfigs
.. autoclass:: ert.plugins.workflow_config.WorkflowConfigs
:members: add_workflow
:undoc-members:


.. autoclass:: ert.shared.plugins.workflow_config.WorkflowConfig
.. autoclass:: ert.plugins.workflow_config.WorkflowConfig
:members:
:undoc-members:

Logging Configuration
~~~~~~~~~~~~~~~~~~~~~
The logging can be configured by plugins to add custom log handlers.

.. autofunction:: ert.shared.plugins.hook_specifications.logging.add_log_handle_to_root
.. autofunction:: ert.plugins.hook_specifications.logging.add_log_handle_to_root

Minimal example to log to a new file:

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def package_files(directory):
"package_dir": {"": "src"},
"package_data": {
"ert": package_files("src/ert/gui/resources/")
+ package_files("src/ert/shared/share/")
+ package_files("src/ert/resources/")
+ ["logging/logger.conf", "logging/storage_log.conf"]
},
"cmake_args": [
Expand Down
2 changes: 1 addition & 1 deletion src/ert/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
WORKFLOW_MODE,
)
from ert.namespace import Namespace
from ert.plugins import ErtPluginContext, ErtPluginManager
from ert.run_models.multiple_data_assimilation import MultipleDataAssimilation
from ert.services import StorageService, WebvizErt
from ert.shared.feature_toggling import FeatureScheduler
from ert.shared.plugins.plugin_manager import ErtPluginContext, ErtPluginManager
from ert.shared.storage.command import add_parser_options as ert_api_add_parser_options
from ert.validation import (
IntegerArgument,
Expand Down
2 changes: 1 addition & 1 deletion src/ert/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
WORKFLOW_MODE,
)
from ert.namespace import Namespace
from ert.plugins import ErtPluginManager
from ert.run_models.base_run_model import StatusEvents
from ert.run_models.model_factory import create_model
from ert.shared.plugins import ErtPluginManager
from ert.storage import open_storage
from ert.storage.local_storage import local_storage_set_ert_config

Expand Down
5 changes: 2 additions & 3 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from typing_extensions import Self

from ert.config.gen_data_config import GenDataConfig
from ert.shared.plugins import ErtPluginManager
from ert.plugins import ErtPluginManager
from ert.substitution_list import SubstitutionList

from ._get_num_cpu import get_num_cpu_from_data_file
Expand Down Expand Up @@ -75,8 +75,7 @@ def site_config_location() -> str:
if "ERT_SITE_CONFIG" in os.environ:
return os.environ["ERT_SITE_CONFIG"]
return str(
Path(importlib.util.find_spec("ert.shared").origin).parent
/ "share/ert/site-config"
Path(importlib.util.find_spec("ert").origin).parent / "resources/site-config"
)


Expand Down
2 changes: 1 addition & 1 deletion src/ert/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
from ert.gui.tools.workflows import WorkflowsTool
from ert.libres_facade import LibresFacade
from ert.namespace import Namespace
from ert.plugins import ErtPluginManager
from ert.services import StorageService
from ert.shared.plugins.plugin_manager import ErtPluginManager
from ert.storage import Storage, open_storage
from ert.storage.local_storage import local_storage_set_ert_config

Expand Down
2 changes: 1 addition & 1 deletion src/ert/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ert.gui.about_dialog import AboutDialog
from ert.gui.ertnotifier import ErtNotifier
from ert.gui.find_ert_info import find_ert_info
from ert.shared.plugins import ErtPluginManager
from ert.plugins import ErtPluginManager

if TYPE_CHECKING:
from ert.gui.tools import Tool
Expand Down
2 changes: 1 addition & 1 deletion src/ert/libres_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from ert.storage import Ensemble

from .enkf_main import ensemble_context
from .shared.plugins import ErtPluginContext
from .plugins import ErtPluginContext

_logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/ert/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import argparse
from typing import Callable, Optional

from ert.shared.plugins.plugin_manager import ErtPluginManager
from ert.plugins.plugin_manager import ErtPluginManager


class Namespace(argparse.Namespace):
Expand Down
11 changes: 8 additions & 3 deletions src/ert/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@

from typing_extensions import Any, ParamSpec

from ert.shared.plugins.plugin_manager import hook_implementation
from ert.shared.plugins.plugin_response import PluginMetadata, PluginResponse
from .plugin_manager import (
ErtPluginContext,
ErtPluginManager,
JobDoc,
hook_implementation,
)
from .plugin_response import PluginMetadata, PluginResponse

P = ParamSpec("P")

Expand Down Expand Up @@ -41,4 +46,4 @@ def inner(*args: P.args, **kwargs: P.kwargs) -> Any:
return wrapper


__all__ = ["plugin"]
__all__ = ["plugin", "ErtPluginManager", "ErtPluginContext", "JobDoc"]
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/shell_scripts/careful_copy_file.py"
/ "../../../resources/shell_scripts/careful_copy_file.py"
).resolve()
),
"<FROM>",
Expand Down Expand Up @@ -57,7 +57,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/shell_scripts/copy_directory.py"
/ "../../../resources/shell_scripts/copy_directory.py"
).resolve()
),
"<FROM>",
Expand Down Expand Up @@ -91,7 +91,7 @@ def __init__(self) -> None:
command=[
str(
(
Path(__file__) / "../../share/ert/shell_scripts/copy_file.py"
Path(__file__) / "../../../resources/shell_scripts/copy_file.py"
).resolve()
),
"<FROM>",
Expand Down Expand Up @@ -125,7 +125,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/shell_scripts/delete_directory.py"
/ "../../../resources/shell_scripts/delete_directory.py"
).resolve()
),
"<DIRECTORY>",
Expand Down Expand Up @@ -166,7 +166,8 @@ def __init__(self) -> None:
command=[
str(
(
Path(__file__) / "../../share/ert/shell_scripts/delete_file.py"
Path(__file__)
/ "../../../resources/shell_scripts/delete_file.py"
).resolve()
),
"<FILES>",
Expand Down Expand Up @@ -200,7 +201,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/forward-models/res/script/ecl100.py"
/ "../../../resources/forward-models/res/script/ecl100.py"
).resolve()
),
"<ECLBASE>",
Expand Down Expand Up @@ -250,7 +251,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/forward-models/res/script/ecl300.py"
/ "../../../resources/forward-models/res/script/ecl300.py"
).resolve()
),
"<ECLBASE>",
Expand Down Expand Up @@ -289,7 +290,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/forward-models/res/script/flow.py"
/ "../../../resources/forward-models/res/script/flow.py"
).resolve()
),
"<ECLBASE>",
Expand Down Expand Up @@ -335,7 +336,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/shell_scripts/make_directory.py"
/ "../../../resources/shell_scripts/make_directory.py"
).resolve()
),
"<DIRECTORY>",
Expand Down Expand Up @@ -365,7 +366,7 @@ def __init__(self) -> None:
command=[
str(
(
Path(__file__) / "../../share/ert/shell_scripts/symlink.py"
Path(__file__) / "../../../resources/shell_scripts/symlink.py"
).resolve()
),
"<TARGET>",
Expand Down Expand Up @@ -396,7 +397,7 @@ def __init__(self) -> None:
command=[
str(
(
Path(__file__) / "../../share/ert/shell_scripts/move_file.py"
Path(__file__) / "../../../resources/shell_scripts/move_file.py"
).resolve()
),
"<FROM>",
Expand Down Expand Up @@ -428,7 +429,7 @@ def __init__(self) -> None:
command=[
str(
(
Path(__file__) / "../../share/ert/shell_scripts/symlink.py"
Path(__file__) / "../../../resources/shell_scripts/symlink.py"
).resolve()
),
"<TARGET>",
Expand Down Expand Up @@ -460,7 +461,7 @@ def __init__(self) -> None:
str(
(
Path(__file__)
/ "../../share/ert/forward-models/templating/script/template_render.py"
/ "../../../resources/forward-models/templating/script/template_render.py"
).resolve()
),
"-i",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import importlib.util
import os
from pathlib import Path
from typing import Dict, List

from jinja2 import Template

import ert


def _resolve_ert_share_path() -> str:
spec = importlib.util.find_spec("ert.shared")
assert spec, "Could not find ert.shared in import path"
assert spec.has_location
spec_origin = spec.origin
assert spec_origin
return str(Path(spec_origin).parent / "share/ert")
from ert.shared import ert_share_path


def _get_jobs_from_directories(directories: List[str]) -> Dict[str, str]:
share_path = _resolve_ert_share_path()
share_path = ert_share_path()
directories = [
Template(directory).render(ERT_SHARE_PATH=share_path, ERT_UI_MODE="gui")
for directory in directories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from typing import TYPE_CHECKING

from ert.shared.plugins.plugin_manager import hook_specification
from ert.plugins.plugin_manager import hook_specification

if TYPE_CHECKING:
from ert.shared.plugins.plugin_response import PluginResponse
from ert.plugins.plugin_response import PluginResponse


@hook_specification(firstresult=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from typing import TYPE_CHECKING, List, Type, no_type_check

from ert.shared.plugins.plugin_manager import hook_specification
from ert.plugins.plugin_manager import hook_specification

if TYPE_CHECKING:
from ert.config import ForwardModelStepPlugin
from ert.shared.plugins.plugin_response import PluginResponse
from ert.plugins.plugin_response import PluginResponse


@no_type_check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from typing import TYPE_CHECKING, Dict

from ert.shared.plugins.plugin_manager import hook_specification
from ert.plugins.plugin_manager import hook_specification

if TYPE_CHECKING:
from ert.shared.plugins.plugin_response import PluginResponse
from ert.plugins.plugin_response import PluginResponse


@hook_specification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

from typing import TYPE_CHECKING, Dict, Optional, no_type_check

from ert.shared.plugins.plugin_manager import hook_specification
from ert.plugins.plugin_manager import hook_specification

if TYPE_CHECKING:
from ert.shared.plugins.plugin_response import PluginResponse
from ert.shared.plugins.workflow_config import WorkflowConfigs
from ert.plugins.plugin_response import PluginResponse
from ert.plugins.workflow_config import WorkflowConfigs


@no_type_check
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from ert.shared.plugins.plugin_manager import hook_specification
from ert.plugins.plugin_manager import hook_specification


@hook_specification
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List

from ert.shared.plugins.plugin_manager import hook_specification
from ert.plugins.plugin_manager import hook_specification


@hook_specification
Expand Down
Loading

0 comments on commit 42d6fc3

Please sign in to comment.