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

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Mar 2 09:25:55 PST 2016


2 new commits in yt:

https://bitbucket.org/yt_analysis/yt/commits/d9a0ab256d80/
Changeset:   d9a0ab256d80
Branch:      yt
User:        MatthewTurk
Date:        2016-02-28 16:37:06+00:00
Summary:     Adding yt.extensions import hook from Flask.
Affected #:  2 files

diff -r 7130b7cef71f9422cc6191b755e1bd5ca96fbaa0 -r d9a0ab256d809ea3a59302725cbc9c857637e7f9 yt/extensions/__init__.py
--- /dev/null
+++ b/yt/extensions/__init__.py
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+"""
+    yt.extensions
+    ~~~~~~~~~~~~~
+
+    Redirect imports for extensions.  This module basically makes it possible
+    for us to transition from ytext.foo to ytext_foo without having to
+    force all extensions to upgrade at the same time.
+
+    When a user does ``from yt.extensions.foo import bar`` it will attempt to
+    import ``from yt_foo import bar`` first and when that fails it will
+    try to import ``from ytext.foo import bar``.
+
+    We're switching from namespace packages because it was just too painful for
+    everybody involved.
+
+    :copyright: (c) 2015 by Armin Ronacher.
+    :license: BSD, see LICENSE for more details.
+"""
+
+# This source code is originally from flask, in the flask/ext/__init__.py file.
+
+
+def setup():
+    from ..exthook import ExtensionImporter
+    importer = ExtensionImporter(['yt_%s', 'ytext.%s'], __name__)
+    importer.install()
+
+
+setup()
+del setup

diff -r 7130b7cef71f9422cc6191b755e1bd5ca96fbaa0 -r d9a0ab256d809ea3a59302725cbc9c857637e7f9 yt/exthook.py
--- /dev/null
+++ b/yt/exthook.py
@@ -0,0 +1,121 @@
+# -*- coding: utf-8 -*-
+"""
+    yt.exthook
+    ~~~~~~~~~~
+
+    Redirect imports for extensions.  This module basically makes it possible
+    for us to transition from ytext.foo to yt_foo without having to
+    force all extensions to upgrade at the same time.
+
+    When a user does ``from yt.extensions.foo import bar`` it will attempt to
+    import ``from yt_foo import bar`` first and when that fails it will
+    try to import ``from ytext.foo import bar``.
+
+    We're switching from namespace packages because it was just too painful for
+    everybody involved.
+
+    This is used by `yt.extensions`.
+
+    :copyright: (c) 2015 by Armin Ronacher.
+    :license: BSD, see LICENSE for more details.
+"""
+# This source code was originally in flask/exthook.py
+import sys
+import os
+from .extern.six import reraise
+
+
+class ExtensionImporter(object):
+    """This importer redirects imports from this submodule to other locations.
+    This makes it possible to transition from the old flaskext.name to the
+    newer flask_name without people having a hard time.
+    """
+
+    def __init__(self, module_choices, wrapper_module):
+        self.module_choices = module_choices
+        self.wrapper_module = wrapper_module
+        self.prefix = wrapper_module + '.'
+        self.prefix_cutoff = wrapper_module.count('.') + 1
+
+    def __eq__(self, other):
+        return self.__class__.__module__ == other.__class__.__module__ and \
+               self.__class__.__name__ == other.__class__.__name__ and \
+               self.wrapper_module == other.wrapper_module and \
+               self.module_choices == other.module_choices
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+    def install(self):
+        sys.meta_path[:] = [x for x in sys.meta_path if self != x] + [self]
+
+    def find_module(self, fullname, path=None):
+        if fullname.startswith(self.prefix):
+            return self
+
+    def load_module(self, fullname):
+        if fullname in sys.modules:
+            return sys.modules[fullname]
+        modname = fullname.split('.', self.prefix_cutoff)[self.prefix_cutoff]
+        for path in self.module_choices:
+            realname = path % modname
+            try:
+                __import__(realname)
+            except ImportError:
+                exc_type, exc_value, tb = sys.exc_info()
+                # since we only establish the entry in sys.modules at the
+                # very this seems to be redundant, but if recursive imports
+                # happen we will call into the move import a second time.
+                # On the second invocation we still don't have an entry for
+                # fullname in sys.modules, but we will end up with the same
+                # fake module name and that import will succeed since this
+                # one already has a temporary entry in the modules dict.
+                # Since this one "succeeded" temporarily that second
+                # invocation now will have created a fullname entry in
+                # sys.modules which we have to kill.
+                sys.modules.pop(fullname, None)
+
+                # If it's an important traceback we reraise it, otherwise
+                # we swallow it and try the next choice.  The skipped frame
+                # is the one from __import__ above which we don't care about
+                if self.is_important_traceback(realname, tb):
+                    reraise(exc_type, exc_value, tb.tb_next)
+                continue
+            module = sys.modules[fullname] = sys.modules[realname]
+            if '.' not in modname:
+                setattr(sys.modules[self.wrapper_module], modname, module)
+            return module
+        raise ImportError('No module named %s' % fullname)
+
+    def is_important_traceback(self, important_module, tb):
+        """Walks a traceback's frames and checks if any of the frames
+        originated in the given important module.  If that is the case then we
+        were able to import the module itself but apparently something went
+        wrong when the module was imported.  (Eg: import of an import failed).
+        """
+        while tb is not None:
+            if self.is_important_frame(important_module, tb):
+                return True
+            tb = tb.tb_next
+        return False
+
+    def is_important_frame(self, important_module, tb):
+        """Checks a single frame if it's important."""
+        g = tb.tb_frame.f_globals
+        if '__name__' not in g:
+            return False
+
+        module_name = g['__name__']
+
+        # Python 2.7 Behavior.  Modules are cleaned up late so the
+        # name shows up properly here.  Success!
+        if module_name == important_module:
+            return True
+
+        # Some python versions will clean up modules so early that the
+        # module name at that point is no longer set.  Try guessing from
+        # the filename then.
+        filename = os.path.abspath(tb.tb_frame.f_code.co_filename)
+        test_string = os.path.sep + important_module.replace('.', os.path.sep)
+        return test_string + '.py' in filename or \
+               test_string + os.path.sep + '__init__.py' in filename


https://bitbucket.org/yt_analysis/yt/commits/764f5ed10e7e/
Changeset:   764f5ed10e7e
Branch:      yt
User:        MatthewTurk
Date:        2016-03-01 18:55:54+00:00
Summary:     Adding amods import
Affected #:  1 file

diff -r d9a0ab256d809ea3a59302725cbc9c857637e7f9 -r 764f5ed10e7ec972b70dbccbfb201c03d2657e58 yt/__init__.py
--- a/yt/__init__.py
+++ b/yt/__init__.py
@@ -175,3 +175,6 @@
 # Import some helpful math utilities
 from yt.utilities.math_utils import \
     ortho_find, quartiles, periodic_position
+
+from yt.analysis_modules.list_modules import \
+    amods

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