Skip to content

Commit 4bd0653

Browse files
authored
conf should attempt types (#2004)
* conf should attempt types * fix tests
1 parent 463a1f0 commit 4bd0653

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

fsspec/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ def set_conf_env(conf_dict, envdict=os.environ):
3030
envdict : dict-like(str, str)
3131
Source for the values - usually the real environment
3232
"""
33+
envdict = dict(envdict)
3334
kwarg_keys = []
3435
for key in envdict:
3536
if key.startswith("FSSPEC_") and len(key) > 7 and key[7] != "_":
37+
try:
38+
value = json.loads(envdict[key])
39+
envdict[key] = value
40+
except json.decoder.JSONDecodeError:
41+
value = envdict[key]
3642
if key.count("_") > 1:
3743
kwarg_keys.append(key)
3844
continue
39-
try:
40-
value = json.loads(envdict[key])
41-
except json.decoder.JSONDecodeError as ex:
42-
warnings.warn(
43-
f"Ignoring environment variable {key} due to a parse failure: {ex}"
44-
)
4545
else:
4646
if isinstance(value, dict):
4747
_, proto = key.split("_", 1)

fsspec/tests/test_config.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_from_env_ignored(clean_conf):
3030
assert "unexpected name" in str(w[0].message)
3131
assert "unexpected name" in str(w[1].message)
3232
assert "unexpected name" in str(w[2].message)
33-
assert "parse failure" in str(w[3].message)
33+
assert "not being a dict" in str(w[3].message)
3434
assert "not being a dict" in str(w[4].message)
3535
assert cd == {}
3636

@@ -45,7 +45,7 @@ def test_from_env_kwargs(clean_conf):
4545
with catch_warnings(record=True) as w:
4646
set_conf_env(conf_dict=cd, envdict=env)
4747
assert len(w) == 1
48-
assert "parse failure" in str(w[0].message)
48+
assert "not being a dict" in str(w[0].message)
4949
assert cd == {"proto": {"key": "value", "long_key": "othervalue"}}
5050

5151

@@ -62,15 +62,13 @@ def test_from_env_protocol_dict(clean_conf):
6262

6363
def test_from_env_kwargs_override_protocol_dict(clean_conf):
6464
env = {
65-
"FSSPEC_PROTO_LONG_KEY": "override1",
65+
"FSSPEC_PROTO_LONG_KEY": "1",
6666
"FSSPEC_PROTO": '{"key": "value1", "long_key": "value2", "otherkey": "value3"}',
6767
"FSSPEC_PROTO_KEY": "override2",
6868
}
6969
cd = {}
7070
set_conf_env(conf_dict=cd, envdict=env)
71-
assert cd == {
72-
"proto": {"key": "override2", "long_key": "override1", "otherkey": "value3"}
73-
}
71+
assert cd == {"proto": {"key": "override2", "long_key": 1, "otherkey": "value3"}}
7472

7573

7674
def test_from_file_ini(clean_conf, tmpdir):

0 commit comments

Comments
 (0)