Skip to content

Commit

Permalink
Merge pull request #1135 from saketkc/issue#1112
Browse files Browse the repository at this point in the history
Enhance API:mne.get_config to return config dict when called wthout para...
  • Loading branch information
Denis A. Engemann committed Feb 17, 2014
2 parents 0beb58d + 370c84c commit a470847
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions mne/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def test_config():
set_config(key, None, home_dir=tempdir)
if old_val is not None:
os.environ[key] = old_val
# Check if get_config with no input returns all config
key = 'MNE_PYTHON_TESTING_KEY'
config = {key: value}
set_config(key, value, home_dir=tempdir)
assert_equal(get_config(home_dir=tempdir), config)


def test_show_fiff():
Expand Down
13 changes: 8 additions & 5 deletions mne/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,14 +885,15 @@ def set_memmap_min_size(memmap_min_size):
]


def get_config(key, default=None, raise_error=False, home_dir=None):
def get_config(key=None, default=None, raise_error=False, home_dir=None):
"""Read mne(-python) preference from env, then mne-python config
Parameters
----------
key : str
key : None | str
The preference key to look for. The os evironment is searched first,
then the mne-python config file is parsed.
If None, all the config parameters present in the path are returned.
default : str | None
Value to return if the key is not found.
raise_error : bool
Expand All @@ -904,15 +905,15 @@ def get_config(key, default=None, raise_error=False, home_dir=None):
Returns
-------
value : str | None
value : dict | str | None
The preference key value.
"""

if not isinstance(key, string_types):
if key is not None and not isinstance(key, string_types):
raise ValueError('key must be a string')

# first, check to see if key is in env
if key in os.environ:
if key is not None and key in os.environ:
return os.environ[key]

# second, look for it in mne-python config file
Expand All @@ -923,6 +924,8 @@ def get_config(key, default=None, raise_error=False, home_dir=None):
else:
with open(config_path, 'r') as fid:
config = json.load(fid)
if key is None:
return config
key_found = True if key in config else False
val = config.get(key, default)

Expand Down

0 comments on commit a470847

Please sign in to comment.