Commits

masklinn committed 6b3a7cd

Move extends from package to module, bump version to 0.2

  • Participants
  • Parent commits b583dca

Comments (0)

Files changed (3)

+__all__ = ['Base', 'Extend']
+
+def get_extends(cls):
+    # __subclasses__ is sorted in loading order and the mro
+    # executes the bases left-to-right. We want the resolution
+    # order of the extended type to be last-loaded first (the
+    # latest-loaded extender sees its methods executed first,
+    # execution goes up the extension sequence and ends on the
+    # base class), therefore we must revert ``extenders``
+    return [
+        sub for sub in cls.__subclasses__()
+        if issubclass(sub, Extend)
+        if sub is not Extend
+        if cls._accepts(sub)][::-1]
+
+class MetaBase(type):
+    def __new__(typ, name, bases, attributes):
+        return type.__new__(
+            typ, name, bases,
+            dict(attributes, _extension_filters=[]))
+
+class Extend(object):
+    pass
+
+class Base(object):
+    __metaclass__ = MetaBase
+    def __new__(cls):
+        base_extenders = get_extends(cls)
+        ancestor_extenders = sum(
+            [get_extends(ancestor) for ancestor in cls.mro()[1:]
+             if issubclass(ancestor, Base)
+             if ancestor is not Base], [])
+        if not (base_extenders or ancestor_extenders):
+            return object.__new__(cls)
+
+        extenders = (base_extenders or [cls]) + ancestor_extenders
+        return object.__new__(
+            MetaBase(cls.__name__, tuple(extenders), {}))
+    @classmethod
+    def add_filter(cls, callable):
+        cls._extension_filters.append(callable)
+    @classmethod
+    def _accepts(cls, candidate):
+        for class_ in cls.mro():
+            for callable in getattr(class_, '_extension_filters', []):
+                if callable(cls, candidate) is False:
+                    return False
+        return True

File extends/__init__.py

-__all__ = ['Base', 'Extend']
-
-def get_extends(cls):
-    # __subclasses__ is sorted in loading order and the mro
-    # executes the bases left-to-right. We want the resolution
-    # order of the extended type to be last-loaded first (the
-    # latest-loaded extender sees its methods executed first,
-    # execution goes up the extension sequence and ends on the
-    # base class), therefore we must revert ``extenders``
-    return [
-        sub for sub in cls.__subclasses__()
-        if issubclass(sub, Extend)
-        if sub is not Extend
-        if cls._accepts(sub)][::-1]
-
-class MetaBase(type):
-    def __new__(typ, name, bases, attributes):
-        return type.__new__(
-            typ, name, bases,
-            dict(attributes, _extension_filters=[]))
-
-class Extend(object):
-    pass
-
-class Base(object):
-    __metaclass__ = MetaBase
-    def __new__(cls):
-        base_extenders = get_extends(cls)
-        ancestor_extenders = sum(
-            [get_extends(ancestor) for ancestor in cls.mro()[1:]
-             if issubclass(ancestor, Base)
-             if ancestor is not Base], [])
-        if not (base_extenders or ancestor_extenders):
-            return object.__new__(cls)
-
-        extenders = (base_extenders or [cls]) + ancestor_extenders
-        return object.__new__(
-            MetaBase(cls.__name__, tuple(extenders), {}))
-    @classmethod
-    def add_filter(cls, callable):
-        cls._extension_filters.append(callable)
-    @classmethod
-    def _accepts(cls, candidate):
-        for class_ in cls.mro():
-            for callable in getattr(class_, '_extension_filters', []):
-                if callable(cls, candidate) is False:
-                    return False
-        return True
 NEWS = open(os.path.join(here, 'NEWS.txt')).read()
 
 
-version = '0.1'
+version = '0.2.0'
 
 install_requires = [
 ]
     author_email='xavier.morel@masklinn.net',
     url='',
     license='BSD',
-    packages=['extends'],
+    py_modules=['extends'],
     include_package_data=True,
     zip_safe=False,
     install_requires=install_requires,