Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions fsspec/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions fsspec/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == {}

Expand All @@ -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"}}


Expand All @@ -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):
Expand Down
Loading