From d818e70bf3d2312b54c0eed4c779d8e4d10b2cd4 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Wed, 26 May 2021 17:43:51 +0545 Subject: [PATCH] output/dep: specify schema as a dictionary (#6061) --- dvc/dependency/__init__.py | 15 +++++++-------- dvc/output.py | 28 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/dvc/dependency/__init__.py b/dvc/dependency/__init__.py index f3578c0fa..7e73d49ec 100644 --- a/dvc/dependency/__init__.py +++ b/dvc/dependency/__init__.py @@ -1,7 +1,7 @@ from collections import defaultdict +from typing import Any, Mapping -import dvc.output as output -from dvc.output import Output +from dvc.output import ARTIFACT_SCHEMA, Output from .base import Dependency from .param import ParamsDependency @@ -11,12 +11,11 @@ from .repo import RepoDependency # without output-specific entries like 'cache' (whether or not output is # cached, see -o and -O flags for `dvc run`) and 'metric' (whether or not # output is a metrics file and how to parse it, see `-M` flag for `dvc run`). -SCHEMA = output.SCHEMA.copy() -del SCHEMA[Output.PARAM_CACHE] -del SCHEMA[Output.PARAM_METRIC] -del SCHEMA[Output.PARAM_DESC] -SCHEMA.update(RepoDependency.REPO_SCHEMA) -SCHEMA.update(ParamsDependency.PARAM_SCHEMA) +SCHEMA: Mapping[str, Any] = { + **ARTIFACT_SCHEMA, + **RepoDependency.REPO_SCHEMA, + **ParamsDependency.PARAM_SCHEMA, +} def _get(stage, p, info): diff --git a/dvc/output.py b/dvc/output.py index ad6c00d2e..e411779b3 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -976,14 +976,20 @@ class Output: return self.path_info.fspath -SCHEMA = CHECKSUMS_SCHEMA.copy() -SCHEMA[Required(Output.PARAM_PATH)] = str -SCHEMA[Output.PARAM_CACHE] = bool -SCHEMA[Output.PARAM_METRIC] = Output.METRIC_SCHEMA -SCHEMA[Output.PARAM_PLOT] = bool -SCHEMA[Output.PARAM_PERSIST] = bool -SCHEMA[Output.PARAM_CHECKPOINT] = bool -SCHEMA[HashInfo.PARAM_SIZE] = int -SCHEMA[HashInfo.PARAM_NFILES] = int -SCHEMA[Output.PARAM_DESC] = str -SCHEMA[Output.PARAM_ISEXEC] = bool +ARTIFACT_SCHEMA = { + **CHECKSUMS_SCHEMA, + Required(Output.PARAM_PATH): str, + Output.PARAM_PLOT: bool, + Output.PARAM_PERSIST: bool, + Output.PARAM_CHECKPOINT: bool, + HashInfo.PARAM_SIZE: int, + HashInfo.PARAM_NFILES: int, + Output.PARAM_ISEXEC: bool, +} + +SCHEMA = { + **ARTIFACT_SCHEMA, + Output.PARAM_CACHE: bool, + Output.PARAM_METRIC: Output.METRIC_SCHEMA, + Output.PARAM_DESC: str, +}