Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance API:mne.get_config to return config dict when called wthout para... #1135

Merged
merged 4 commits into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this returns None for some reason in Python 3.3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not able to figure this one out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, python3.3 seems to check if key is in os.environ : https://travis-ci.org/mne-tools/mne-python/jobs/19015348#L2301

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this, was too trivial, don't know how I missed.



def test_show_fiff():
Expand Down
15 changes: 11 additions & 4 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Period at the end of the line

default : str | None
Value to return if the key is not found.
raise_error : bool
Expand All @@ -904,11 +905,11 @@ def get_config(key, default=None, raise_error=False, home_dir=None):

Returns
-------
value : str | None
value : str | None | dict
The preference key value.
"""

if not isinstance(key, string_types):
if key and not isinstance(key, string_types):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer if key is not None to if key (more explicit)

raise ValueError('key must be a string')

# first, check to see if key is in env
Expand All @@ -923,6 +924,12 @@ 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 not key:
#json object is returned as Unicode encoded
#encode it to byte-oriented representation
#config = {key.encode("utf-8"): value.encode("utf-8")
# for key, value in config.iteritems()}
return config
key_found = True if key in config else False
val = config.get(key, default)

Expand Down