diff --git a/fsspec/config.py b/fsspec/config.py index 76d9af14a..19f68071c 100644 --- a/fsspec/config.py +++ b/fsspec/config.py @@ -30,18 +30,18 @@ def set_conf_env(conf_dict, envdict=os.environ): envdict : dict-like(str, str) Source for the values - usually the real environment """ + envdict = dict(envdict) kwarg_keys = [] for key in envdict: if key.startswith("FSSPEC_") and len(key) > 7 and key[7] != "_": + try: + value = json.loads(envdict[key]) + envdict[key] = value + except json.decoder.JSONDecodeError: + value = envdict[key] if key.count("_") > 1: kwarg_keys.append(key) continue - try: - value = json.loads(envdict[key]) - except json.decoder.JSONDecodeError as ex: - warnings.warn( - f"Ignoring environment variable {key} due to a parse failure: {ex}" - ) else: if isinstance(value, dict): _, proto = key.split("_", 1) diff --git a/fsspec/tests/test_config.py b/fsspec/tests/test_config.py index dc251a0d9..84d3e7b09 100644 --- a/fsspec/tests/test_config.py +++ b/fsspec/tests/test_config.py @@ -30,7 +30,7 @@ def test_from_env_ignored(clean_conf): assert "unexpected name" in str(w[0].message) assert "unexpected name" in str(w[1].message) assert "unexpected name" in str(w[2].message) - assert "parse failure" in str(w[3].message) + assert "not being a dict" in str(w[3].message) assert "not being a dict" in str(w[4].message) assert cd == {} @@ -45,7 +45,7 @@ def test_from_env_kwargs(clean_conf): with catch_warnings(record=True) as w: set_conf_env(conf_dict=cd, envdict=env) assert len(w) == 1 - assert "parse failure" in str(w[0].message) + assert "not being a dict" in str(w[0].message) assert cd == {"proto": {"key": "value", "long_key": "othervalue"}} @@ -62,15 +62,13 @@ def test_from_env_protocol_dict(clean_conf): def test_from_env_kwargs_override_protocol_dict(clean_conf): env = { - "FSSPEC_PROTO_LONG_KEY": "override1", + "FSSPEC_PROTO_LONG_KEY": "1", "FSSPEC_PROTO": '{"key": "value1", "long_key": "value2", "otherkey": "value3"}', "FSSPEC_PROTO_KEY": "override2", } cd = {} set_conf_env(conf_dict=cd, envdict=env) - assert cd == { - "proto": {"key": "override2", "long_key": "override1", "otherkey": "value3"} - } + assert cd == {"proto": {"key": "override2", "long_key": 1, "otherkey": "value3"}} def test_from_file_ini(clean_conf, tmpdir):