[yt-svn] commit/yt: 7 new changesets

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


7 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/0f4e9feab282/
Changeset:   0f4e9feab282
Branch:      yt
User:        qobilidop
Date:        2016-10-10 20:18:19+00:00
Summary:     Expand dir in the config file
Affected #:  1 file

diff -r 314a02c1f9342ada3ac7f6ae823e264f798a095f -r 0f4e9feab28272acf5a29725a6eb005af06edbe7 yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -128,6 +128,13 @@
 if not ytcfg.has_section("yt"):
     ytcfg.add_section("yt")
 
+# Expand dir so that ~, $HOME and etc. could be used in config files.
+for key, val in ytcfg_defaults.items():
+    if 'dir' in key:
+        expanded_dir = os.path.expanduser(ytcfg.get("yt", key))
+        expanded_dir = os.path.expandvars(expanded_dir)
+        ytcfg.set("yt", key, expanded_dir)
+
 # Now we have parsed the config file.  Overrides come from the command line.
 
 # This should be implemented at some point.  The idea would be to have a set of


https://bitbucket.org/yt_analysis/yt/commits/2c87c0308500/
Changeset:   2c87c0308500
Branch:      yt
User:        qobilidop
Date:        2016-10-11 02:40:58+00:00
Summary:     Define a config interpolation class to expand config parameters
Affected #:  1 file

diff -r 0f4e9feab28272acf5a29725a6eb005af06edbe7 -r 2c87c0308500372736b717aea22131aca19db48b yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -15,6 +15,7 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
+from functools import wraps
 import os
 import warnings
 from yt.extern.six.moves import configparser
@@ -117,7 +118,26 @@
     with open(CURRENT_CONFIG_FILE, 'w') as new_cfg:
         cp.write(new_cfg)
 
+def _expand_dir(get_val):
+    @wraps(get_val)
+    def get_val_and_expand(*arg, **kwargs):
+        val = get_val(*arg, **kwargs)
+        return os.path.expanduser(os.path.expandvars(val))
+    return get_val_and_expand
+
+class _YTInterpolation(configparser.Interpolation):
+    @_expand_dir
+    def before_get(self, parser, section, option, value, defaults):
+        return super(_YTInterpolation, self)\
+               .before_get(parser, section, option, value, defaults)
+
+    @_expand_dir
+    def before_set(self, parser, section, option, value):
+        return super(_YTInterpolation, self)\
+               .before_set(parser, section, option, value)
+
 class YTConfigParser(configparser.ConfigParser):
+    _DEFAULT_INTERPOLATION = _YTInterpolation()
     def __setitem__(self, key, val):
         self.set(key[0], key[1], val)
     def __getitem__(self, key):
@@ -128,13 +148,6 @@
 if not ytcfg.has_section("yt"):
     ytcfg.add_section("yt")
 
-# Expand dir so that ~, $HOME and etc. could be used in config files.
-for key, val in ytcfg_defaults.items():
-    if 'dir' in key:
-        expanded_dir = os.path.expanduser(ytcfg.get("yt", key))
-        expanded_dir = os.path.expandvars(expanded_dir)
-        ytcfg.set("yt", key, expanded_dir)
-
 # Now we have parsed the config file.  Overrides come from the command line.
 
 # This should be implemented at some point.  The idea would be to have a set of


https://bitbucket.org/yt_analysis/yt/commits/b1f28aebd8f5/
Changeset:   b1f28aebd8f5
Branch:      yt
User:        qobilidop
Date:        2016-10-11 02:54:14+00:00
Summary:     Add tests for expanding config parameters and use `YTConfigParser` consistently
Affected #:  2 files

diff -r 2c87c0308500372736b717aea22131aca19db48b -r b1f28aebd8f5e5d623940f7654f8acfeb027f346 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 2c87c0308500372736b717aea22131aca19db48b -r b1f28aebd8f5e5d623940f7654f8acfeb027f346 yt/utilities/tests/test_config.py
--- a/yt/utilities/tests/test_config.py
+++ b/yt/utilities/tests/test_config.py
@@ -15,9 +15,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'
@@ -47,7 +47,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')
 
@@ -77,6 +77,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):
         self.assertFalse(os.path.exists(CURRENT_CONFIG_FILE))
@@ -91,15 +102,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'])


https://bitbucket.org/yt_analysis/yt/commits/dfb8c37e6603/
Changeset:   dfb8c37e6603
Branch:      yt
User:        qobilidop
Date:        2016-10-11 02:58:00+00:00
Summary:     Expand value only before get
Affected #:  1 file

diff -r b1f28aebd8f5e5d623940f7654f8acfeb027f346 -r dfb8c37e660390687127fe59fb1cc143445379af yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -118,23 +118,10 @@
     with open(CURRENT_CONFIG_FILE, 'w') as new_cfg:
         cp.write(new_cfg)
 
-def _expand_dir(get_val):
-    @wraps(get_val)
-    def get_val_and_expand(*arg, **kwargs):
-        val = get_val(*arg, **kwargs)
-        return os.path.expanduser(os.path.expandvars(val))
-    return get_val_and_expand
-
 class _YTInterpolation(configparser.Interpolation):
-    @_expand_dir
     def before_get(self, parser, section, option, value, defaults):
-        return super(_YTInterpolation, self)\
-               .before_get(parser, section, option, value, defaults)
-
-    @_expand_dir
-    def before_set(self, parser, section, option, value):
-        return super(_YTInterpolation, self)\
-               .before_set(parser, section, option, value)
+        # Return the expanded value instead of the original one.
+        return os.path.expanduser(os.path.expandvars(value))
 
 class YTConfigParser(configparser.ConfigParser):
     _DEFAULT_INTERPOLATION = _YTInterpolation()


https://bitbucket.org/yt_analysis/yt/commits/a54016122c48/
Changeset:   a54016122c48
Branch:      yt
User:        qobilidop
Date:        2016-10-11 02:58:56+00:00
Summary:     Remove deprecated import
Affected #:  1 file

diff -r dfb8c37e660390687127fe59fb1cc143445379af -r a54016122c48e47023519b446f8f1804d2900d6b yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -15,7 +15,6 @@
 # The full license is in the file COPYING.txt, distributed with this software.
 #-----------------------------------------------------------------------------
 
-from functools import wraps
 import os
 import warnings
 from yt.extern.six.moves import configparser


https://bitbucket.org/yt_analysis/yt/commits/37c84abaa3f0/
Changeset:   37c84abaa3f0
Branch:      yt
User:        qobilidop
Date:        2016-10-11 05:19:47+00:00
Summary:     Make it work in py2
Affected #:  1 file

diff -r a54016122c48e47023519b446f8f1804d2900d6b -r 37c84abaa3f09c12f4e927b60a1d2791867b68e7 yt/config.py
--- a/yt/config.py
+++ b/yt/config.py
@@ -117,18 +117,17 @@
     with open(CURRENT_CONFIG_FILE, 'w') as new_cfg:
         cp.write(new_cfg)
 
-class _YTInterpolation(configparser.Interpolation):
-    def before_get(self, parser, section, option, value, defaults):
-        # Return the expanded value instead of the original one.
-        return os.path.expanduser(os.path.expandvars(value))
-
-class YTConfigParser(configparser.ConfigParser):
-    _DEFAULT_INTERPOLATION = _YTInterpolation()
+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"):


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