Skip to content

Commit

Permalink
move HydraContext to hydra.types
Browse files Browse the repository at this point in the history
  • Loading branch information
jieru-hu committed Apr 29, 2021
1 parent 265feaf commit 3e674d8
Show file tree
Hide file tree
Showing 21 changed files with 41 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pathlib import Path
from typing import Optional, Sequence

from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.core.config_store import ConfigStore
from hydra.core.singleton import Singleton
from hydra.core.utils import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from typing import Any, Iterable, List, Optional, Sequence

from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.core.config_store import ConfigStore
from hydra.core.override_parser.overrides_parser import OverridesParser
from hydra.core.plugins import Plugins
Expand Down
3 changes: 1 addition & 2 deletions hydra/_internal/core_plugins/basic_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

from hydra.core.config_store import ConfigStore
from hydra.core.utils import (
HydraContext,
JobReturn,
configure_log,
filter_overrides,
run_job,
setup_globals,
)
from hydra.plugins.launcher import Launcher
from hydra.types import TaskFunction
from hydra.types import HydraContext, TaskFunction

log = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions hydra/_internal/core_plugins/basic_sweeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
from hydra.core.config_store import ConfigStore
from hydra.core.override_parser.overrides_parser import OverridesParser
from hydra.core.override_parser.types import Override
from hydra.core.utils import HydraContext, JobReturn
from hydra.core.utils import JobReturn
from hydra.errors import HydraException
from hydra.plugins.launcher import Launcher
from hydra.plugins.sweeper import Sweeper
from hydra.types import TaskFunction
from hydra.types import HydraContext, TaskFunction


@dataclass
Expand Down
3 changes: 1 addition & 2 deletions hydra/_internal/hydra.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from hydra.core.config_search_path import ConfigSearchPath
from hydra.core.plugins import Plugins
from hydra.core.utils import (
HydraContext,
JobReturn,
JobRuntime,
configure_log,
Expand All @@ -27,7 +26,7 @@
from hydra.plugins.launcher import Launcher
from hydra.plugins.search_path_plugin import SearchPathPlugin
from hydra.plugins.sweeper import Sweeper
from hydra.types import RunMode, TaskFunction
from hydra.types import HydraContext, RunMode, TaskFunction

from ..core.default_element import DefaultsTreeNode, InputDefault
from .callbacks import Callbacks
Expand Down
3 changes: 1 addition & 2 deletions hydra/core/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@

from hydra._internal.sources_registry import SourcesRegistry
from hydra.core.singleton import Singleton
from hydra.core.utils import HydraContext
from hydra.plugins.completion_plugin import CompletionPlugin
from hydra.plugins.config_source import ConfigSource
from hydra.plugins.launcher import Launcher
from hydra.plugins.plugin import Plugin
from hydra.plugins.search_path_plugin import SearchPathPlugin
from hydra.plugins.sweeper import Sweeper
from hydra.types import TaskFunction
from hydra.types import HydraContext, TaskFunction
from hydra.utils import instantiate


Expand Down
11 changes: 1 addition & 10 deletions hydra/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@
from hydra.core.hydra_config import HydraConfig
from hydra.core.singleton import Singleton
from hydra.errors import HydraJobException
from hydra.types import TaskFunction

if TYPE_CHECKING:
from hydra._internal.callbacks import Callbacks
from hydra.types import HydraContext, TaskFunction

log = logging.getLogger(__name__)


@dataclass
class HydraContext:
config_loader: ConfigLoader
callbacks: "Callbacks"


def simple_stdout_log_config(level: int = logging.INFO) -> None:
root = logging.getLogger()
root.setLevel(level)
Expand Down
5 changes: 3 additions & 2 deletions hydra/plugins/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

from omegaconf import DictConfig

from hydra.core.utils import JobReturn, HydraContext
from hydra.types import TaskFunction
from hydra.core.utils import JobReturn

from hydra.types import TaskFunction, HydraContext

from .plugin import Plugin

Expand Down
2 changes: 1 addition & 1 deletion hydra/plugins/sweeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .launcher import Launcher

from .plugin import Plugin
from hydra.core.utils import HydraContext
from hydra.types import HydraContext


class Sweeper(Plugin):
Expand Down
13 changes: 12 additions & 1 deletion hydra/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@
import warnings
from dataclasses import dataclass
from enum import Enum
from typing import Any, Callable
from typing import TYPE_CHECKING, Any, Callable

from omegaconf import MISSING

TaskFunction = Callable[[Any], Any]


if TYPE_CHECKING:
from hydra._internal.callbacks import Callbacks
from hydra.core.config_loader import ConfigLoader


@dataclass
class HydraContext:
config_loader: "ConfigLoader"
callbacks: "Callbacks"


@dataclass
class TargetConf:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from hydra.core.override_parser.overrides_parser import OverridesParser
from hydra.core.override_parser.types import IntervalSweep, Override, Transformer
from hydra.core.plugins import Plugins
from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.plugins.launcher import Launcher
from hydra.plugins.sweeper import Sweeper
from hydra.types import TaskFunction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import List, Optional

from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.plugins.sweeper import Sweeper
from hydra.types import TaskFunction
from omegaconf import DictConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
from typing import Any, Optional, Sequence

from hydra.core.utils import HydraContext, JobReturn
from hydra.core.utils import JobReturn
from hydra.types import HydraContext
from hydra.plugins.launcher import Launcher
from hydra.types import TaskFunction
from omegaconf import DictConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Transformer,
)
from hydra.core.plugins import Plugins
from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.plugins.launcher import Launcher
from hydra.plugins.sweeper import Sweeper
from hydra.types import TaskFunction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List, Optional

from hydra import TaskFunction
from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.plugins.sweeper import Sweeper
from omegaconf import DictConfig

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Transformer,
)
from hydra.core.plugins import Plugins
from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.plugins.sweeper import Sweeper
from hydra.types import TaskFunction
from omegaconf import DictConfig, OmegaConf
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import Any, List, Optional

from hydra.core.utils import HydraContext
from hydra.types import HydraContext
from hydra.plugins.sweeper import Sweeper
from hydra.types import TaskFunction
from omegaconf import DictConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import ray
from hydra.core.hydra_config import HydraConfig
from hydra.core.singleton import Singleton
from hydra.core.utils import HydraContext, JobReturn, run_job, setup_globals
from hydra.core.utils import JobReturn, run_job, setup_globals
from hydra.types import HydraContext

from hydra.types import TaskFunction
from omegaconf import DictConfig, OmegaConf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
from typing import Optional, Sequence

from hydra.core.utils import HydraContext, JobReturn
from hydra.core.utils import JobReturn
from hydra.types import HydraContext
from hydra.plugins.launcher import Launcher
from hydra.types import TaskFunction
from omegaconf import DictConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
from typing import Optional, Sequence

from hydra.core.utils import HydraContext, JobReturn
from hydra.core.utils import JobReturn
from hydra.types import HydraContext
from hydra.plugins.launcher import Launcher
from hydra.types import TaskFunction
from omegaconf import DictConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import logging
from typing import Any, Optional, Sequence

from hydra.core.utils import HydraContext, JobReturn
from hydra.core.utils import JobReturn
from hydra.types import HydraContext
from hydra.plugins.launcher import Launcher
from hydra.types import TaskFunction
from omegaconf import DictConfig, OmegaConf
Expand Down

0 comments on commit 3e674d8

Please sign in to comment.