parsing: make imports lazy (#5225)

* parsing: make imports lazy

* Locally declare default params file
This commit is contained in:
Saugat Pachhai
2021-01-07 15:00:54 +05:45
committed by GitHub
parent a9ccf70439
commit 40122cefa5
3 changed files with 7 additions and 5 deletions
+1 -2
View File
@@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Any, Dict, NamedTuple, Union
from funcy import cached_property, collecting, first, isa, join, reraise
from dvc.dependency.param import ParamsDependency
from dvc.exceptions import DvcException
from dvc.parsing.interpolate import ParseError
from dvc.path_info import PathInfo
@@ -34,11 +33,11 @@ logger = logging.getLogger(__name__)
STAGES_KWD = "stages"
VARS_KWD = "vars"
WDIR_KWD = "wdir"
DEFAULT_PARAMS_FILE = ParamsDependency.DEFAULT_PARAMS_FILE
PARAMS_KWD = "params"
FOREACH_KWD = "foreach"
DO_KWD = "do"
DEFAULT_PARAMS_FILE = "params.yaml"
DEFAULT_SENTINEL = object()
JOIN = "@"
+4 -2
View File
@@ -21,8 +21,6 @@ from dvc.parsing.interpolate import (
)
from dvc.path_info import PathInfo
from dvc.utils import relpath
from dvc.utils.humanize import join
from dvc.utils.serialize import LOADERS
logger = logging.getLogger(__name__)
SeqOrMap = Union[Sequence, Mapping]
@@ -34,6 +32,8 @@ class ContextError(DvcException):
class ReservedKeyError(ContextError):
def __init__(self, keys, path=None):
from dvc.utils.humanize import join
self.keys = keys
self.path = path
@@ -347,6 +347,8 @@ class Context(CtxDict):
@classmethod
def load_from(cls, tree, path: PathInfo, select_keys=None) -> "Context":
from dvc.utils.serialize import LOADERS
file = relpath(path)
if not tree.exists(path):
raise ParamsLoadError(f"'{file}' does not exist")
+2 -1
View File
@@ -6,7 +6,6 @@ from functools import singledispatch
from funcy import memoize, rpartial
from dvc.exceptions import DvcException
from dvc.utils import colorize
if typing.TYPE_CHECKING:
from typing import List, Match
@@ -84,6 +83,8 @@ def _(obj: bool):
def _format_exc_msg(exc: "ParseException"):
from pyparsing import ParseException
from dvc.utils import colorize
exc.loc += 2 # 2 because we append `${` at the start of expr below
expr = exc.pstr