config: ignore unspecified keys from feature section (#9153)

A warning is shown to the user for the unsupported/ignored keys, and then ignored.
The warning is raised only once per interpreter session.
This commit is contained in:
skshetry
2023-03-10 21:52:05 +05:45
committed by GitHub
parent 2a40a55bb4
commit aaa825a9a8
3 changed files with 63 additions and 9 deletions
+42 -8
View File
@@ -1,8 +1,21 @@
import logging
import os
from urllib.parse import urlparse
from funcy import walk_values
from voluptuous import All, Any, Coerce, Invalid, Lower, Optional, Range, Schema
from funcy import once, walk_values
from voluptuous import (
REMOVE_EXTRA,
All,
Any,
Coerce,
Invalid,
Lower,
Optional,
Range,
Schema,
)
logger = logging.getLogger(__name__)
Bool = All(
Lower,
@@ -65,6 +78,27 @@ class RelPath(str):
pass
class FeatureSchema(Schema):
def __init__(self, schema, required=False):
super().__init__(schema, required=required, extra=REMOVE_EXTRA)
@staticmethod
@once
def _log_deprecated(keys):
# only run this once per session
message = "%s config option%s unsupported"
paths = ", ".join(f"'feature.{key}'" for key in keys)
pluralize = " is" if len(keys) == 1 else "s are"
logger.warning(message, paths, pluralize)
def __call__(self, data):
ret = super().__call__(data)
extra_keys = data.keys() - ret.keys()
if extra_keys:
self._log_deprecated(sorted(extra_keys))
return ret
REMOTE_COMMON = {
"url": str,
"checksum_jobs": All(Coerce(int), Range(1)),
@@ -262,12 +296,12 @@ SCHEMA = {
},
},
# section for experimental features
"feature": {
Optional("machine", default=False): Bool,
# enabled by default. It's of no use, kept for backward compatibility.
Optional("data_index_cache", default=False): Bool,
Optional("parametrization", default=True): Bool,
},
# only specified keys are validated, others get logged and then ignored/removed
"feature": FeatureSchema(
{
Optional("machine", default=False): Bool,
},
),
"plots": {
"html_template": str,
Optional("auto_open", default=False): Bool,
+1 -1
View File
@@ -121,7 +121,7 @@ def _get_cloud_fs(repo_config, **kwargs):
remote_conf = get_fs_config(repo_config, **kwargs)
try:
remote_conf = SCHEMA["remote"][str](remote_conf)
remote_conf = SCHEMA["remote"][str](remote_conf) # type: ignore[index]
except Invalid as exc:
raise RepoConfigError(str(exc)) from None
+20
View File
@@ -1,3 +1,4 @@
import logging
import os
import textwrap
@@ -94,3 +95,22 @@ def test_load_configob_error(tmp_dir, dvc, mocker):
with pytest.raises(ConfigError):
with config.edit():
pass
def test_feature_section_supports_arbitrary_values(caplog):
with caplog.at_level(logging.WARNING, logger="dvc.config_schema"):
data = Config.validate(
{
"feature": {
"random_key_1": "random_value_1",
"random_key_2": 42,
}
}
)
assert "random_key_1" not in data
assert "random_key_2" not in data
assert (
"'feature.random_key_1', 'feature.random_key_2' "
"config options are unsupported"
) in caplog.text