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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Sep 7 11:20:48 PDT 2016


6 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/ffc751876bbf/
Changeset:   ffc751876bbf
Branch:      yt
User:        xarthisius
Date:        2016-08-17 19:41:50+00:00
Summary:     Use LocalFieldInfoContainer to initialize my_plugins_fields
Affected #:  1 file

diff -r e01aafd56e018aae048126104705318316daee70 -r ffc751876bbf603c4dbd7f5a8709f1225d4a0a2a yt/fields/my_plugin_fields.py
--- a/yt/fields/my_plugin_fields.py
+++ b/yt/fields/my_plugin_fields.py
@@ -16,11 +16,11 @@
 from .field_plugin_registry import \
     register_field_plugin
 
-from .field_info_container import \
-    FieldInfoContainer
+from .local_fields import \
+    LocalFieldInfoContainer
 
 # Empty FieldInfoContainer
-my_plugins_fields = FieldInfoContainer(None, [], None)
+my_plugins_fields = LocalFieldInfoContainer(None, [], None)
 
 @register_field_plugin
 def setup_my_plugins_fields(registry, ftype="gas", slice_info=None):


https://bitbucket.org/yt_analysis/yt/commits/b136bf236429/
Changeset:   b136bf236429
Branch:      yt
User:        xarthisius
Date:        2016-08-17 19:51:17+00:00
Summary:     Issue deprecation warning for 'pluginfilename' located in /home/xarth/.yt Read the plugin file from CONFIG_DIR
Affected #:  2 files

diff -r ffc751876bbf603c4dbd7f5a8709f1225d4a0a2a -r b136bf2364299c163007cdda1a2b8889c0e5ceef doc/source/reference/configuration.rst
--- a/doc/source/reference/configuration.rst
+++ b/doc/source/reference/configuration.rst
@@ -5,7 +5,7 @@
 how much output it displays, loading custom fields, loading custom colormaps,
 accessing test datasets regardless of where you are in the file system, etc.
 This customization is done through :ref:`configuration-file` and
-:ref:`plugin-file` both of which exist in your ``$HOME/.yt`` directory.
+:ref:`plugin-file` both of which exist in your ``$HOME/.config/yt`` directory.
 
 .. _configuration-file:
 
@@ -149,9 +149,10 @@
 Plugin File Format
 ^^^^^^^^^^^^^^^^^^
 
-yt will look for and recognize the file ``$HOME/.yt/my_plugins.py`` as a plugin
-file, which should contain python code.  If accessing yt functions and classes
-they will not require the ``yt.`` prefix, because of how they are loaded.
+yt will look for and recognize the file ``$HOME/.config/yt/my_plugins.py`` as a
+plugin file, which should contain python code.  If accessing yt functions and
+classes they will not require the ``yt.`` prefix, because of how they are
+loaded.
 
 For example, if I created a plugin file containing:
 

diff -r ffc751876bbf603c4dbd7f5a8709f1225d4a0a2a -r b136bf2364299c163007cdda1a2b8889c0e5ceef yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -854,21 +854,32 @@
     data objects, colormaps, and other code classes and objects to be used
     in yt scripts without modifying the yt source directly.
 
-    The file must be located at ``$HOME/.yt/my_plugins.py``.
+    The file must be located at ``$HOME/.config/yt/my_plugins.py``.
 
     Warning: when you use this function, your script will only be reproducible
     if you also provide the ``my_plugins.py`` file.
     """
     import yt
     from yt.fields.my_plugin_fields import my_plugins_fields
-    from yt.config import ytcfg
-    my_plugin_name = ytcfg.get("yt","pluginfilename")
-    # We assume that it is with respect to the $HOME/.yt directory
-    if os.path.isfile(my_plugin_name):
-        _fn = my_plugin_name
-    else:
-        _fn = os.path.expanduser("~/.yt/%s" % my_plugin_name)
-    if os.path.isfile(_fn):
+    from yt.config import ytcfg, CONFIG_DIR
+    my_plugin_name = ytcfg.get("yt", "pluginfilename")
+
+    # In the following order if pluginfilename is: an absolute path, located in
+    # the CONFIG_DIR, located in an obsolete config dir.
+    _fn = None
+    old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+    for base_prefix in ('', CONFIG_DIR, old_config_dir):
+        if os.path.isfile(os.path.join(base_prefix, my_plugin_name)):
+            _fn = os.path.join(base_prefix, my_plugin_name)
+            break
+
+    if _fn is not None and os.path.isfile(_fn):
+        if _fn.startswith(old_config_dir):
+            mylog.warn(
+                'Your plugin file is located in a deprecated directory. '
+                'Please move it from %s to %s',
+                os.path.join(old_config_dir, my_plugin_name),
+                os.path.join(CONFIG_DIR, my_plugin_name))
         mylog.info("Loading plugins from %s", _fn)
         execdict = yt.__dict__.copy()
         execdict['add_field'] = my_plugins_fields.add_field


https://bitbucket.org/yt_analysis/yt/commits/2457a9c05fea/
Changeset:   2457a9c05fea
Branch:      yt
User:        xarthisius
Date:        2016-08-17 20:43:15+00:00
Summary:     Add basic test for plugin file
Affected #:  2 files

diff -r b136bf2364299c163007cdda1a2b8889c0e5ceef -r 2457a9c05fea8bc5b52296b44cf216983f27162c doc/source/reference/configuration.rst
--- a/doc/source/reference/configuration.rst
+++ b/doc/source/reference/configuration.rst
@@ -160,7 +160,8 @@
 
    def _myfunc(field, data):
        return np.random.random(data["density"].shape)
-   add_field("random", function=_myfunc, units='auto')
+   add_field('random', function=_myfunc,
+             dimensions='dimensionless', units='auto')
 
 then all of my data objects would have access to the field ``random``.
 

diff -r b136bf2364299c163007cdda1a2b8889c0e5ceef -r 2457a9c05fea8bc5b52296b44cf216983f27162c yt/fields/tests/test_fields_plugins.py
--- /dev/null
+++ b/yt/fields/tests/test_fields_plugins.py
@@ -0,0 +1,65 @@
+# -*- coding: UTF-8 -*-
+#-----------------------------------------------------------------------------
+# Copyright (c) 2016, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+import os
+import unittest
+import yt
+from yt.config import ytcfg, CONFIG_DIR
+from yt.testing import fake_random_ds
+
+TEST_PLUGIN_FILE = '''def _myfunc(field, data):
+    return np.random.random(data['density'].shape)
+add_field('random', dimensions='dimensionless',
+          function=_myfunc, units='auto')'''
+
+
+def setUpModule():
+    my_plugin_name = ytcfg.get('yt', 'pluginfilename')
+    # In the following order if pluginfilename is: an absolute path, located in
+    # the CONFIG_DIR, located in an obsolete config dir.
+    old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+    for base_prefix in ('', CONFIG_DIR, old_config_dir):
+        potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+        if os.path.isfile(potential_plugin_file):
+            os.rename(potential_plugin_file,
+                      potential_plugin_file + '.bak_test')
+
+    plugin_file = os.path.join(CONFIG_DIR, my_plugin_name)
+    with open(plugin_file, 'w') as fh:
+        fh.write(TEST_PLUGIN_FILE)
+
+
+def tearDownModule():
+    my_plugin_name = ytcfg.get('yt', 'pluginfilename')
+    plugin_file = os.path.join(CONFIG_DIR, my_plugin_name)
+    os.remove(plugin_file)
+
+    old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+    for base_prefix in ('', CONFIG_DIR, old_config_dir):
+        potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+        if os.path.isfile(potential_plugin_file + '.bak_test'):
+            os.rename(potential_plugin_file + '.bak_test',
+                      potential_plugin_file)
+
+
+class TestPluginFile(unittest.TestCase):
+
+    def testCustomField(self):
+        plugin_file = os.path.join(
+            CONFIG_DIR, ytcfg.get('yt', 'pluginfilename'))
+        msg = 'INFO:yt:Loading plugins from %s' % plugin_file
+
+        with self.assertLogs('yt', level='INFO') as cm:
+            yt.enable_plugins()
+            self.assertEqual(cm.output, [msg])
+
+        ds = fake_random_ds(16)
+        dd = ds.all_data()
+        self.assertEqual(str(dd['random'].units), 'dimensionless')
+        self.assertEqual(dd['random'].shape, dd['density'].shape)


https://bitbucket.org/yt_analysis/yt/commits/ddd7580e54bf/
Changeset:   ddd7580e54bf
Branch:      yt
User:        xarthisius
Date:        2016-08-18 00:37:53+00:00
Summary:     Don't assert logs for python<3.4
Affected #:  1 file

diff -r 2457a9c05fea8bc5b52296b44cf216983f27162c -r ddd7580e54bf117e9bf31b9e6fa9e3d0a923c964 yt/fields/tests/test_fields_plugins.py
--- a/yt/fields/tests/test_fields_plugins.py
+++ b/yt/fields/tests/test_fields_plugins.py
@@ -8,6 +8,7 @@
 #-----------------------------------------------------------------------------
 
 import os
+import sys
 import unittest
 import yt
 from yt.config import ytcfg, CONFIG_DIR
@@ -55,9 +56,12 @@
             CONFIG_DIR, ytcfg.get('yt', 'pluginfilename'))
         msg = 'INFO:yt:Loading plugins from %s' % plugin_file
 
-        with self.assertLogs('yt', level='INFO') as cm:
+        if sys.version_info >= (3, 4, 0):
+            with self.assertLogs('yt', level='INFO') as cm:
+                yt.enable_plugins()
+                self.assertEqual(cm.output, [msg])
+        else:
             yt.enable_plugins()
-            self.assertEqual(cm.output, [msg])
 
         ds = fake_random_ds(16)
         dd = ds.all_data()


https://bitbucket.org/yt_analysis/yt/commits/2d405d897205/
Changeset:   2d405d897205
Branch:      yt
User:        xarthisius
Date:        2016-08-24 19:19:28+00:00
Summary:     Automigrate plugin file with 'yt config migrate'
Affected #:  2 files

diff -r ddd7580e54bf117e9bf31b9e6fa9e3d0a923c964 -r 2d405d897205905abad849de861c72d131c17906 yt/utilities/configure.py
--- a/yt/utilities/configure.py
+++ b/yt/utilities/configure.py
@@ -8,6 +8,7 @@
 #-----------------------------------------------------------------------------
 
 import os
+import shutil
 import sys
 import argparse
 from yt.config import CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE
@@ -37,14 +38,26 @@
 
 def migrate_config():
     if not os.path.exists(_OLD_CONFIG_FILE):
-        print("Old config not found.")
+        print('Old config not found.')
         sys.exit()
     CONFIG.read(_OLD_CONFIG_FILE)
-    print("Writing a new config file to: {}".format(CURRENT_CONFIG_FILE))
+    print('Writing a new config file to: {}'.format(CURRENT_CONFIG_FILE))
     write_config()
-    print("Backing up the old config file: {}.bak".format(_OLD_CONFIG_FILE))
+    print('Backing up the old config file: {}.bak'.format(_OLD_CONFIG_FILE))
     os.rename(_OLD_CONFIG_FILE, _OLD_CONFIG_FILE + '.bak')
 
+    old_config_dir = os.path.dirname(_OLD_CONFIG_FILE)
+    plugin_file = CONFIG.get('yt', 'pluginfilename')
+    if plugin_file and \
+            os.path.exists(os.path.join(old_config_dir, plugin_file)):
+        print('Migrating plugin file {} to new location'.format(plugin_file))
+        shutil.copyfile(
+            os.path.join(old_config_dir, plugin_file),
+            os.path.join(os.path.dirname(CURRENT_CONFIG_FILE), plugin_file))
+        print('Backing up the old plugin file: {}.bak'.format(_OLD_CONFIG_FILE))
+        plugin_file = os.path.join(old_config_dir, plugin_file)
+        os.rename(plugin_file, plugin_file + '.bak')
+
 
 def rm_config(section, option):
     CONFIG.remove_option(section, option)

diff -r ddd7580e54bf117e9bf31b9e6fa9e3d0a923c964 -r 2d405d897205905abad849de861c72d131c17906 yt/utilities/tests/test_config.py
--- a/yt/utilities/tests/test_config.py
+++ b/yt/utilities/tests/test_config.py
@@ -15,12 +15,13 @@
 import yt.utilities.command_line
 import yt.config
 from yt.config import \
-    CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE
+    CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE, CONFIG_DIR
 from yt.extern.six import StringIO
 from yt.extern.six.moves.configparser import NoOptionError, SafeConfigParser
+from yt.fields.tests.test_fields_plugins import TEST_PLUGIN_FILE
 
-
-_DUMMY_CFG = ['[yt]', 'loglevel = 49']
+_TEST_PLUGIN = '_test_plugin.py'
+_DUMMY_CFG = ['[yt]', 'loglevel = 49', 'pluginfilename = ' + _TEST_PLUGIN]
 
 
 @contextlib.contextmanager
@@ -112,23 +113,51 @@
     def setUp(self):
         if not os.path.exists(os.path.dirname(_OLD_CONFIG_FILE)):
             os.makedirs(os.path.dirname(_OLD_CONFIG_FILE))
-
+        
         with open(_OLD_CONFIG_FILE, 'w') as fh:
             for line in _DUMMY_CFG:
                 fh.write('{}\n'.format(line))
         
         if os.path.exists(CURRENT_CONFIG_FILE):
             os.remove(CURRENT_CONFIG_FILE)
+    
+        my_plugin_name = _TEST_PLUGIN
+        old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+        for base_prefix in ('', CONFIG_DIR, old_config_dir):
+            potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+            if os.path.isfile(potential_plugin_file):
+                os.rename(potential_plugin_file,
+                          potential_plugin_file + '.bak_test')
+
+        plugin_file = os.path.join(old_config_dir, my_plugin_name)
+        with open(plugin_file, 'w') as fh:
+            fh.write(TEST_PLUGIN_FILE)
 
     def tearDown(self):
         if os.path.exists(CURRENT_CONFIG_FILE):
             os.remove(CURRENT_CONFIG_FILE)
         if os.path.exists(_OLD_CONFIG_FILE + '.bak'):
             os.remove(_OLD_CONFIG_FILE + '.bak')
+        
+        my_plugin_name = _TEST_PLUGIN
+        plugin_file = os.path.join(CONFIG_DIR, my_plugin_name)
+        os.remove(plugin_file)
+
+        old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+        for base_prefix in ('', CONFIG_DIR, old_config_dir):
+            potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+            if os.path.isfile(potential_plugin_file + '.bak_test'):
+                os.rename(potential_plugin_file + '.bak_test',
+                          potential_plugin_file)
 
     def testConfigMigration(self):
+        old_config_dir = os.path.dirname(_OLD_CONFIG_FILE)
+        new_config_dir = os.path.dirname(CURRENT_CONFIG_FILE)
+
         self.assertFalse(os.path.exists(CURRENT_CONFIG_FILE))
         self.assertTrue(os.path.exists(_OLD_CONFIG_FILE))
+        self.assertTrue(
+            os.path.exists(os.path.join(old_config_dir, _TEST_PLUGIN)))
         
         info = self._runYTConfig(['migrate'])
         self.assertEqual(info['rc'], 0)
@@ -136,6 +165,11 @@
         self.assertTrue(os.path.exists(CURRENT_CONFIG_FILE))
         self.assertFalse(os.path.exists(_OLD_CONFIG_FILE))
         self.assertTrue(os.path.exists(_OLD_CONFIG_FILE + '.bak'))
+        self.assertTrue(
+            os.path.exists(os.path.join(new_config_dir, _TEST_PLUGIN)))
+        self.assertTrue(
+            os.path.exists(os.path.join(old_config_dir, _TEST_PLUGIN + '.bak'))
+        )
 
         with open(CURRENT_CONFIG_FILE, 'r') as fh:
             new_cfg = ''.join(fh.readlines())


https://bitbucket.org/yt_analysis/yt/commits/bbef88a523bf/
Changeset:   bbef88a523bf
Branch:      yt
User:        ngoldbaum
Date:        2016-09-07 18:20:20+00:00
Summary:     Merged in xarthisius/yt (pull request #2343)

Migrate plugin file to XDG_CONFIG_HOME. Closes issue #1263
Affected #:  6 files

diff -r 2f4fbeb0ac2776ba881aa243e8ce27a75fa2fec1 -r bbef88a523bf205db3cd01a936927d3e82a26507 doc/source/reference/configuration.rst
--- a/doc/source/reference/configuration.rst
+++ b/doc/source/reference/configuration.rst
@@ -5,7 +5,7 @@
 how much output it displays, loading custom fields, loading custom colormaps,
 accessing test datasets regardless of where you are in the file system, etc.
 This customization is done through :ref:`configuration-file` and
-:ref:`plugin-file` both of which exist in your ``$HOME/.yt`` directory.
+:ref:`plugin-file` both of which exist in your ``$HOME/.config/yt`` directory.
 
 .. _configuration-file:
 
@@ -149,9 +149,10 @@
 Plugin File Format
 ^^^^^^^^^^^^^^^^^^
 
-yt will look for and recognize the file ``$HOME/.yt/my_plugins.py`` as a plugin
-file, which should contain python code.  If accessing yt functions and classes
-they will not require the ``yt.`` prefix, because of how they are loaded.
+yt will look for and recognize the file ``$HOME/.config/yt/my_plugins.py`` as a
+plugin file, which should contain python code.  If accessing yt functions and
+classes they will not require the ``yt.`` prefix, because of how they are
+loaded.
 
 For example, if I created a plugin file containing:
 
@@ -159,7 +160,8 @@
 
    def _myfunc(field, data):
        return np.random.random(data["density"].shape)
-   add_field("random", function=_myfunc, units='auto')
+   add_field('random', function=_myfunc,
+             dimensions='dimensionless', units='auto')
 
 then all of my data objects would have access to the field ``random``.
 

diff -r 2f4fbeb0ac2776ba881aa243e8ce27a75fa2fec1 -r bbef88a523bf205db3cd01a936927d3e82a26507 yt/fields/my_plugin_fields.py
--- a/yt/fields/my_plugin_fields.py
+++ b/yt/fields/my_plugin_fields.py
@@ -16,11 +16,11 @@
 from .field_plugin_registry import \
     register_field_plugin
 
-from .field_info_container import \
-    FieldInfoContainer
+from .local_fields import \
+    LocalFieldInfoContainer
 
 # Empty FieldInfoContainer
-my_plugins_fields = FieldInfoContainer(None, [], None)
+my_plugins_fields = LocalFieldInfoContainer(None, [], None)
 
 @register_field_plugin
 def setup_my_plugins_fields(registry, ftype="gas", slice_info=None):

diff -r 2f4fbeb0ac2776ba881aa243e8ce27a75fa2fec1 -r bbef88a523bf205db3cd01a936927d3e82a26507 yt/fields/tests/test_fields_plugins.py
--- /dev/null
+++ b/yt/fields/tests/test_fields_plugins.py
@@ -0,0 +1,69 @@
+# -*- coding: UTF-8 -*-
+#-----------------------------------------------------------------------------
+# Copyright (c) 2016, yt Development Team.
+#
+# Distributed under the terms of the Modified BSD License.
+#
+# The full license is in the file COPYING.txt, distributed with this software.
+#-----------------------------------------------------------------------------
+
+import os
+import sys
+import unittest
+import yt
+from yt.config import ytcfg, CONFIG_DIR
+from yt.testing import fake_random_ds
+
+TEST_PLUGIN_FILE = '''def _myfunc(field, data):
+    return np.random.random(data['density'].shape)
+add_field('random', dimensions='dimensionless',
+          function=_myfunc, units='auto')'''
+
+
+def setUpModule():
+    my_plugin_name = ytcfg.get('yt', 'pluginfilename')
+    # In the following order if pluginfilename is: an absolute path, located in
+    # the CONFIG_DIR, located in an obsolete config dir.
+    old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+    for base_prefix in ('', CONFIG_DIR, old_config_dir):
+        potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+        if os.path.isfile(potential_plugin_file):
+            os.rename(potential_plugin_file,
+                      potential_plugin_file + '.bak_test')
+
+    plugin_file = os.path.join(CONFIG_DIR, my_plugin_name)
+    with open(plugin_file, 'w') as fh:
+        fh.write(TEST_PLUGIN_FILE)
+
+
+def tearDownModule():
+    my_plugin_name = ytcfg.get('yt', 'pluginfilename')
+    plugin_file = os.path.join(CONFIG_DIR, my_plugin_name)
+    os.remove(plugin_file)
+
+    old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+    for base_prefix in ('', CONFIG_DIR, old_config_dir):
+        potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+        if os.path.isfile(potential_plugin_file + '.bak_test'):
+            os.rename(potential_plugin_file + '.bak_test',
+                      potential_plugin_file)
+
+
+class TestPluginFile(unittest.TestCase):
+
+    def testCustomField(self):
+        plugin_file = os.path.join(
+            CONFIG_DIR, ytcfg.get('yt', 'pluginfilename'))
+        msg = 'INFO:yt:Loading plugins from %s' % plugin_file
+
+        if sys.version_info >= (3, 4, 0):
+            with self.assertLogs('yt', level='INFO') as cm:
+                yt.enable_plugins()
+                self.assertEqual(cm.output, [msg])
+        else:
+            yt.enable_plugins()
+
+        ds = fake_random_ds(16)
+        dd = ds.all_data()
+        self.assertEqual(str(dd['random'].units), 'dimensionless')
+        self.assertEqual(dd['random'].shape, dd['density'].shape)

diff -r 2f4fbeb0ac2776ba881aa243e8ce27a75fa2fec1 -r bbef88a523bf205db3cd01a936927d3e82a26507 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -854,21 +854,32 @@
     data objects, colormaps, and other code classes and objects to be used
     in yt scripts without modifying the yt source directly.
 
-    The file must be located at ``$HOME/.yt/my_plugins.py``.
+    The file must be located at ``$HOME/.config/yt/my_plugins.py``.
 
     Warning: when you use this function, your script will only be reproducible
     if you also provide the ``my_plugins.py`` file.
     """
     import yt
     from yt.fields.my_plugin_fields import my_plugins_fields
-    from yt.config import ytcfg
-    my_plugin_name = ytcfg.get("yt","pluginfilename")
-    # We assume that it is with respect to the $HOME/.yt directory
-    if os.path.isfile(my_plugin_name):
-        _fn = my_plugin_name
-    else:
-        _fn = os.path.expanduser("~/.yt/%s" % my_plugin_name)
-    if os.path.isfile(_fn):
+    from yt.config import ytcfg, CONFIG_DIR
+    my_plugin_name = ytcfg.get("yt", "pluginfilename")
+
+    # In the following order if pluginfilename is: an absolute path, located in
+    # the CONFIG_DIR, located in an obsolete config dir.
+    _fn = None
+    old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+    for base_prefix in ('', CONFIG_DIR, old_config_dir):
+        if os.path.isfile(os.path.join(base_prefix, my_plugin_name)):
+            _fn = os.path.join(base_prefix, my_plugin_name)
+            break
+
+    if _fn is not None and os.path.isfile(_fn):
+        if _fn.startswith(old_config_dir):
+            mylog.warn(
+                'Your plugin file is located in a deprecated directory. '
+                'Please move it from %s to %s',
+                os.path.join(old_config_dir, my_plugin_name),
+                os.path.join(CONFIG_DIR, my_plugin_name))
         mylog.info("Loading plugins from %s", _fn)
         execdict = yt.__dict__.copy()
         execdict['add_field'] = my_plugins_fields.add_field

diff -r 2f4fbeb0ac2776ba881aa243e8ce27a75fa2fec1 -r bbef88a523bf205db3cd01a936927d3e82a26507 yt/utilities/configure.py
--- a/yt/utilities/configure.py
+++ b/yt/utilities/configure.py
@@ -8,6 +8,7 @@
 #-----------------------------------------------------------------------------
 
 import os
+import shutil
 import sys
 import argparse
 from yt.config import CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE
@@ -37,14 +38,26 @@
 
 def migrate_config():
     if not os.path.exists(_OLD_CONFIG_FILE):
-        print("Old config not found.")
+        print('Old config not found.')
         sys.exit()
     CONFIG.read(_OLD_CONFIG_FILE)
-    print("Writing a new config file to: {}".format(CURRENT_CONFIG_FILE))
+    print('Writing a new config file to: {}'.format(CURRENT_CONFIG_FILE))
     write_config()
-    print("Backing up the old config file: {}.bak".format(_OLD_CONFIG_FILE))
+    print('Backing up the old config file: {}.bak'.format(_OLD_CONFIG_FILE))
     os.rename(_OLD_CONFIG_FILE, _OLD_CONFIG_FILE + '.bak')
 
+    old_config_dir = os.path.dirname(_OLD_CONFIG_FILE)
+    plugin_file = CONFIG.get('yt', 'pluginfilename')
+    if plugin_file and \
+            os.path.exists(os.path.join(old_config_dir, plugin_file)):
+        print('Migrating plugin file {} to new location'.format(plugin_file))
+        shutil.copyfile(
+            os.path.join(old_config_dir, plugin_file),
+            os.path.join(os.path.dirname(CURRENT_CONFIG_FILE), plugin_file))
+        print('Backing up the old plugin file: {}.bak'.format(_OLD_CONFIG_FILE))
+        plugin_file = os.path.join(old_config_dir, plugin_file)
+        os.rename(plugin_file, plugin_file + '.bak')
+
 
 def rm_config(section, option):
     CONFIG.remove_option(section, option)

diff -r 2f4fbeb0ac2776ba881aa243e8ce27a75fa2fec1 -r bbef88a523bf205db3cd01a936927d3e82a26507 yt/utilities/tests/test_config.py
--- a/yt/utilities/tests/test_config.py
+++ b/yt/utilities/tests/test_config.py
@@ -15,12 +15,13 @@
 import yt.utilities.command_line
 import yt.config
 from yt.config import \
-    CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE
+    CURRENT_CONFIG_FILE, _OLD_CONFIG_FILE, CONFIG_DIR
 from yt.extern.six import StringIO
 from yt.extern.six.moves.configparser import NoOptionError, SafeConfigParser
+from yt.fields.tests.test_fields_plugins import TEST_PLUGIN_FILE
 
-
-_DUMMY_CFG = ['[yt]', 'loglevel = 49']
+_TEST_PLUGIN = '_test_plugin.py'
+_DUMMY_CFG = ['[yt]', 'loglevel = 49', 'pluginfilename = ' + _TEST_PLUGIN]
 
 
 @contextlib.contextmanager
@@ -112,23 +113,51 @@
     def setUp(self):
         if not os.path.exists(os.path.dirname(_OLD_CONFIG_FILE)):
             os.makedirs(os.path.dirname(_OLD_CONFIG_FILE))
-
+        
         with open(_OLD_CONFIG_FILE, 'w') as fh:
             for line in _DUMMY_CFG:
                 fh.write('{}\n'.format(line))
         
         if os.path.exists(CURRENT_CONFIG_FILE):
             os.remove(CURRENT_CONFIG_FILE)
+    
+        my_plugin_name = _TEST_PLUGIN
+        old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+        for base_prefix in ('', CONFIG_DIR, old_config_dir):
+            potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+            if os.path.isfile(potential_plugin_file):
+                os.rename(potential_plugin_file,
+                          potential_plugin_file + '.bak_test')
+
+        plugin_file = os.path.join(old_config_dir, my_plugin_name)
+        with open(plugin_file, 'w') as fh:
+            fh.write(TEST_PLUGIN_FILE)
 
     def tearDown(self):
         if os.path.exists(CURRENT_CONFIG_FILE):
             os.remove(CURRENT_CONFIG_FILE)
         if os.path.exists(_OLD_CONFIG_FILE + '.bak'):
             os.remove(_OLD_CONFIG_FILE + '.bak')
+        
+        my_plugin_name = _TEST_PLUGIN
+        plugin_file = os.path.join(CONFIG_DIR, my_plugin_name)
+        os.remove(plugin_file)
+
+        old_config_dir = os.path.join(os.path.expanduser('~'), '.yt')
+        for base_prefix in ('', CONFIG_DIR, old_config_dir):
+            potential_plugin_file = os.path.join(base_prefix, my_plugin_name)
+            if os.path.isfile(potential_plugin_file + '.bak_test'):
+                os.rename(potential_plugin_file + '.bak_test',
+                          potential_plugin_file)
 
     def testConfigMigration(self):
+        old_config_dir = os.path.dirname(_OLD_CONFIG_FILE)
+        new_config_dir = os.path.dirname(CURRENT_CONFIG_FILE)
+
         self.assertFalse(os.path.exists(CURRENT_CONFIG_FILE))
         self.assertTrue(os.path.exists(_OLD_CONFIG_FILE))
+        self.assertTrue(
+            os.path.exists(os.path.join(old_config_dir, _TEST_PLUGIN)))
         
         info = self._runYTConfig(['migrate'])
         self.assertEqual(info['rc'], 0)
@@ -136,6 +165,11 @@
         self.assertTrue(os.path.exists(CURRENT_CONFIG_FILE))
         self.assertFalse(os.path.exists(_OLD_CONFIG_FILE))
         self.assertTrue(os.path.exists(_OLD_CONFIG_FILE + '.bak'))
+        self.assertTrue(
+            os.path.exists(os.path.join(new_config_dir, _TEST_PLUGIN)))
+        self.assertTrue(
+            os.path.exists(os.path.join(old_config_dir, _TEST_PLUGIN + '.bak'))
+        )
 
         with open(CURRENT_CONFIG_FILE, 'r') as fh:
             new_cfg = ''.join(fh.readlines())

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