[med-svn] [python-mne] 01/01: Imported Upstream version 0.7.3

Alexandre Gramfort agramfort-guest at moszumanska.debian.org
Sat Jan 18 20:41:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

agramfort-guest pushed a commit to branch upstream
in repository python-mne.

commit ad96eb94f81a12b296bcbc9a106e8b3f05c73cfd
Author: Alexandre Gramfort <alexandre.gramfort at m4x.org>
Date:   Sat Jan 18 21:27:52 2014 +0100

    Imported Upstream version 0.7.3
---
 mne/tests/test_utils.py | 10 +++++-----
 mne/utils.py            | 34 +++++++++++++++++++++++-----------
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/mne/tests/test_utils.py b/mne/tests/test_utils.py
index 201a6a0..080295e 100644
--- a/mne/tests/test_utils.py
+++ b/mne/tests/test_utils.py
@@ -122,14 +122,14 @@ def test_config():
     del os.environ[key]
     # catch the warning about it being a non-standard config key
     with warnings.catch_warnings(True) as w:
-        set_config(key, None)
+        set_config(key, None, home_dir=tempdir)
         assert_true(len(w) == 1)
-    assert_true(get_config(key) is None)
+    assert_true(get_config(key, home_dir=tempdir) is None)
     assert_raises(KeyError, get_config, key, raise_error=True)
     with warnings.catch_warnings(True):
-        set_config(key, value)
-        assert_true(get_config(key) == value)
-        set_config(key, None)
+        set_config(key, value, home_dir=tempdir)
+        assert_true(get_config(key, home_dir=tempdir) == value)
+        set_config(key, None, home_dir=tempdir)
     if old_val is not None:
         os.environ[key] = old_val
 
diff --git a/mne/utils.py b/mne/utils.py
index 7c1b97f..54488cd 100644
--- a/mne/utils.py
+++ b/mne/utils.py
@@ -708,9 +708,15 @@ def get_subjects_dir(subjects_dir=None, raise_error=False):
     return subjects_dir
 
 
-def get_config_path():
+def get_config_path(home_dir=None):
     """Get path to standard mne-python config file
 
+    Parameters
+    ----------
+    home_dir : str | None
+        The folder that contains the .mne config folder.
+        If None, it is found automatically.
+
     Returns
     -------
     config_path : str
@@ -718,16 +724,17 @@ def get_config_path():
         will be '%APPDATA%\.mne\mne-python.json'. On every other
         system, this will be $HOME/.mne/mne-python.json.
     """
+    if home_dir is None:
+        # this has been checked on OSX64, Linux64, and Win32
+        home_dir = os.getenv('APPDATA' if 'nt' == os.name.lower() else 'HOME',
+                             None)
 
-    # this has been checked on OSX64, Linux64, and Win32
-    val = os.getenv('APPDATA' if 'nt' == os.name.lower() else 'HOME', None)
-    if val is None:
+    if home_dir is None:
         raise ValueError('mne-python config file path could '
                          'not be determined, please report this '
                          'error to mne-python developers')
 
-    val = op.join(val, '.mne', 'mne-python.json')
-    return val
+    return op.join(home_dir, '.mne', 'mne-python.json')
 
 
 def set_cache_dir(cache_dir):
@@ -791,7 +798,7 @@ known_config_wildcards = [
     ]
 
 
-def get_config(key, default=None, raise_error=False):
+def get_config(key, default=None, raise_error=False, home_dir=None):
     """Read mne(-python) preference from env, then mne-python config
 
     Parameters
@@ -804,6 +811,9 @@ def get_config(key, default=None, raise_error=False):
     raise_error : bool
         If True, raise an error if the key is not found (instead of returning
         default).
+    home_dir : str | None
+        The folder that contains the .mne config folder.
+        If None, it is found automatically.
 
     Returns
     -------
@@ -819,7 +829,7 @@ def get_config(key, default=None, raise_error=False):
         return os.environ[key]
 
     # second, look for it in mne-python config file
-    config_path = get_config_path()
+    config_path = get_config_path(home_dir=home_dir)
     if not op.isfile(config_path):
         key_found = False
         val = default
@@ -842,7 +852,7 @@ def get_config(key, default=None, raise_error=False):
     return val
 
 
-def set_config(key, value):
+def set_config(key, value, home_dir=None):
     """Set mne-python preference in config
 
     Parameters
@@ -852,8 +862,10 @@ def set_config(key, value):
     value : str |  None
         The value to assign to the preference key. If None, the key is
         deleted.
+    home_dir : str | None
+        The folder that contains the .mne config folder.
+        If None, it is found automatically.
     """
-
     if not isinstance(key, basestring):
         raise ValueError('key must be a string')
     # While JSON allow non-string types, we allow users to override config
@@ -865,7 +877,7 @@ def set_config(key, value):
         warnings.warn('Setting non-standard config type: "%s"' % key)
 
     # Read all previous values
-    config_path = get_config_path()
+    config_path = get_config_path(home_dir=home_dir)
     if op.isfile(config_path):
         with open(config_path, 'r') as fid:
             config = json.load(fid)

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git



More information about the debian-med-commit mailing list