[yt-svn] commit/yt: ngoldbaum: Merged in qobilidop/yt (pull request #2415)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Oct 17 14:20:51 PDT 2016


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/2e22db274f5d/
Changeset:   2e22db274f5d
Branch:      yt
User:        ngoldbaum
Date:        2016-10-17 21:20:26+00:00
Summary:     Merged in qobilidop/yt (pull request #2415)

Expand `~` and environment variables in the config file parameters
Affected #:  3 files

diff -r 362ac1f1f4b6a08dae5c4463ee20d5f5215cf639 -r 2e22db274f5d828ac7ab9ee0a6d92bfaa4adfca1 yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -117,12 +117,17 @@
     with open(CURRENT_CONFIG_FILE, 'w') as new_cfg:
         cp.write(new_cfg)
 
-class YTConfigParser(configparser.ConfigParser):
+class YTConfigParser(configparser.ConfigParser, object):
     def __setitem__(self, key, val):
         self.set(key[0], key[1], val)
+
     def __getitem__(self, key):
         self.get(key[0], key[1])
 
+    def get(self, section, option, *args, **kwargs):
+        val = super(YTConfigParser, self).get(section, option, *args, **kwargs)
+        return os.path.expanduser(os.path.expandvars(val))
+
 ytcfg = YTConfigParser(ytcfg_defaults)
 ytcfg.read([_OLD_CONFIG_FILE, CURRENT_CONFIG_FILE, 'yt.cfg'])
 if not ytcfg.has_section("yt"):

diff -r 362ac1f1f4b6a08dae5c4463ee20d5f5215cf639 -r 2e22db274f5d828ac7ab9ee0a6d92bfaa4adfca1 yt/utilities/configure.py
--- a/yt/utilities/configure.py
+++ b/yt/utilities/configure.py
@@ -11,10 +11,9 @@
 import shutil
 import sys
 import argparse
-from yt.config import CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE
-from yt.extern.six.moves import configparser
+from yt.config import CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE, YTConfigParser
 
-CONFIG = configparser.SafeConfigParser()
+CONFIG = YTConfigParser()
 CONFIG.read([CURRENT_CONFIG_FILE])
 
 

diff -r 362ac1f1f4b6a08dae5c4463ee20d5f5215cf639 -r 2e22db274f5d828ac7ab9ee0a6d92bfaa4adfca1 yt/utilities/tests/test_config.py
--- a/yt/utilities/tests/test_config.py
+++ b/yt/utilities/tests/test_config.py
@@ -21,9 +21,9 @@
 import yt.utilities.command_line
 import yt.config
 from yt.config import \
-    CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE, CONFIG_DIR
+    CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE, CONFIG_DIR, YTConfigParser
 from yt.extern.six import StringIO
-from yt.extern.six.moves.configparser import NoOptionError, SafeConfigParser
+from yt.extern.six.moves.configparser import NoOptionError
 from yt.fields.tests.test_fields_plugins import TEST_PLUGIN_FILE
 
 _TEST_PLUGIN = '_test_plugin.py'
@@ -53,7 +53,7 @@
             os.rename(cfgfile, cfgfile + '.bak_test')
 
             if cfgfile == CURRENT_CONFIG_FILE:
-                yt.utilities.configure.CONFIG = SafeConfigParser()
+                yt.utilities.configure.CONFIG = YTConfigParser()
                 if not yt.utilities.configure.CONFIG.has_section('yt'):
                     yt.utilities.configure.CONFIG.add_section('yt')
 
@@ -83,6 +83,17 @@
             'stderr': output[1]
         }
 
+    def _testKeyValue(self, key, val_set, val_get):
+        info = self._runYTConfig(['set', 'yt', key, val_set])
+        self.assertEqual(info['rc'], 0)
+
+        info = self._runYTConfig(['get', 'yt', key])
+        self.assertEqual(info['rc'], 0)
+        self.assertEqual(info['stdout'].strip(), val_get)
+
+        info = self._runYTConfig(['rm', 'yt', key])
+        self.assertEqual(info['rc'], 0)
+
 class TestYTConfigCommands(TestYTConfig):
     def testConfigCommands(self):
         # stub out test if mock isn't installed in Python2
@@ -101,15 +112,11 @@
         self.assertEqual(info['rc'], 0)
         self.assertIn('[yt]', info['stdout'])
 
-        info = self._runYTConfig(['set', 'yt', '__parallel', 'True'])
-        self.assertEqual(info['rc'], 0)
-
-        info = self._runYTConfig(['get', 'yt', '__parallel'])
-        self.assertEqual(info['rc'], 0)
-        self.assertEqual(info['stdout'].strip(), 'True')
-
-        info = self._runYTConfig(['rm', 'yt', '__parallel'])
-        self.assertEqual(info['rc'], 0)
+        self._testKeyValue('__parallel', 'True', 'True')
+        self._testKeyValue('test_data_dir', '~/yt-data',
+                           os.path.expanduser('~/yt-data'))
+        self._testKeyValue('test_data_dir', '$HOME/yt-data',
+                           os.path.expandvars('$HOME/yt-data'))
 
         with self.assertRaises(NoOptionError):
             self._runYTConfig(['get', 'yt', 'foo'])

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the yt-svn mailing list