summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-07-17 11:49:24 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-07-17 11:50:04 -0700
commitd33fcf6cc7380633329fdaf2e7f7543bbdd2490e (patch)
treea93784103a38b10e72abedff927c6951288885d6
parent9d681429a3c78520614be1f4852de8ffb1bfcd8a (diff)
downloadattobuild-d33fcf6cc7380633329fdaf2e7f7543bbdd2490e.tar.gz
attobuild-d33fcf6cc7380633329fdaf2e7f7543bbdd2490e.tar.bz2
attobuild-d33fcf6cc7380633329fdaf2e7f7543bbdd2490e.tar.xz
attobuild-d33fcf6cc7380633329fdaf2e7f7543bbdd2490e.zip
Use a metaclass instead of @add_slots
-rw-r--r--attoconf/_version.py2
-rw-r--r--attoconf/classy.py35
-rw-r--r--attoconf/core.py2
-rw-r--r--attoconf/lib/arches.py2
-rw-r--r--attoconf/lib/c.py2
-rw-r--r--attoconf/lib/install.py8
-rw-r--r--attoconf/lib/make.py6
-rw-r--r--attoconf/lib/templates.py6
-rw-r--r--attoconf/tests/test_core.py2
-rw-r--r--attoconf/types.py2
10 files changed, 34 insertions, 33 deletions
diff --git a/attoconf/_version.py b/attoconf/_version.py
index 18e1fb6..791d3d9 100644
--- a/attoconf/_version.py
+++ b/attoconf/_version.py
@@ -11,7 +11,7 @@ minor = 9
# Incremented if there is a bugfix release.
# Might not be contiguous.
-patch = 0
+patch = 1
# Reserved for distributors and forks.
# Contains arbitrary text, but no parentheses or newlines.
diff --git a/attoconf/classy.py b/attoconf/classy.py
index a27230d..98d54aa 100644
--- a/attoconf/classy.py
+++ b/attoconf/classy.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
@@ -19,24 +19,33 @@ from __future__ import print_function, division, absolute_import
from .core import Project, Build
-# TODO: put this in a metaclass
-# some of the init/jiggle logic would also be simplified by a metaclass
+class PolymorphicSlotMergerMetaclass(type):
+
+ def __new__(meta, name, bases, dct):
+ if '__slots__' not in dct:
+ s = ()
+ for b in bases:
+ s2 = b.__dict__.get('_merge_slots_', ())
+ if isinstance(s2, basestring):
+ s2 = (s2,)
+ s += s2
+ s += dct.get('_merge_slots_', ())
+ dct['__slots__'] = s
+ else:
+ assert dct['__slots__'] == ()
+ return type.__new__(meta, name, bases, dct)
+
+
+# TODO: remove this for 1.0
def add_slots(cls):
- ''' A decorator that fixes __slots__ after multiple inheritance.
- '''
- return type(cls.__name__, cls.__bases__,
- dict(cls.__dict__, __slots__=cls.slots()))
+ return cls
class ClassyProject(Project):
''' A more convenient, objectish, way of setting up a project.
'''
__slots__ = ()
- @classmethod
- def slots(self):
- ''' slots don't work too well with multiple inheritance,
- so make the most-derived class create all the slots
- '''
- return ()
+ _merge_slots_ = ()
+ __metaclass__ = PolymorphicSlotMergerMetaclass
def __init__(self, srcdir):
super(ClassyProject, self).__init__(srcdir)
diff --git a/attoconf/core.py b/attoconf/core.py
index 0d196e9..8fff40f 100644
--- a/attoconf/core.py
+++ b/attoconf/core.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
diff --git a/attoconf/lib/arches.py b/attoconf/lib/arches.py
index 8c70f0b..63f6244 100644
--- a/attoconf/lib/arches.py
+++ b/attoconf/lib/arches.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
diff --git a/attoconf/lib/c.py b/attoconf/lib/c.py
index bc32c49..03f77da 100644
--- a/attoconf/lib/c.py
+++ b/attoconf/lib/c.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
diff --git a/attoconf/lib/install.py b/attoconf/lib/install.py
index f43b2a1..3dc7f5b 100644
--- a/attoconf/lib/install.py
+++ b/attoconf/lib/install.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
@@ -141,11 +141,7 @@ def psdir(build, DIR):
class Install(ClassyProject):
__slots__ = ()
-
- @classmethod
- def slots(cls):
- return super(Install, cls).slots() + (
- 'package', 'package_name')
+ _merge_slots_ = ('package', 'package_name')
# Compatibility with configure written for attoconf < 0.7
# In attoconf 1.0, the positional srcdir argument will go away,
diff --git a/attoconf/lib/make.py b/attoconf/lib/make.py
index b965f28..f815cd0 100644
--- a/attoconf/lib/make.py
+++ b/attoconf/lib/make.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
@@ -62,9 +62,7 @@ class Make(ClassyProject):
''' Post hook to generate a Makefile from Makefile.in
'''
__slots__ = ()
- @classmethod
- def slots(cls):
- return super(Make, cls).slots() + ('make_in', 'make_out')
+ _merge_slots_ = ('make_in', 'make_out')
# compatibility with attoconf < 0.7
def __init__(self, srcdir,
diff --git a/attoconf/lib/templates.py b/attoconf/lib/templates.py
index d6fc24d..0ec1a3e 100644
--- a/attoconf/lib/templates.py
+++ b/attoconf/lib/templates.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
@@ -62,9 +62,7 @@ class Templates(ClassyProject):
''' Post hook to generate output files from *.in templates
'''
__slots__ = ()
- @classmethod
- def slots(cls):
- return super(Templates, cls).slots() + ('template_files',)
+ _merge_slots_ = ('template_files')
# this class didn't exist in attoconf < 0.7, no need for compatibility
def __init__(self, template_files, **kwargs):
diff --git a/attoconf/tests/test_core.py b/attoconf/tests/test_core.py
index 09c2c64..d8de71f 100644
--- a/attoconf/tests/test_core.py
+++ b/attoconf/tests/test_core.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#
diff --git a/attoconf/types.py b/attoconf/types.py
index e7c8465..8a8d56a 100644
--- a/attoconf/types.py
+++ b/attoconf/types.py
@@ -1,4 +1,4 @@
-# Copyright 2013 Ben Longbons <b.r.longbons@gmail.com>
+# Copyright 2013-2014 Ben Longbons <b.r.longbons@gmail.com>
#
# This file is part of attoconf.
#