diff options
author | Todd Gamblin <tgamblin@llnl.gov> | 2017-03-11 05:48:36 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-11 05:48:36 -0800 |
commit | e3101808ae077a3d352d8740cc39d877ed355b86 (patch) | |
tree | 96cbd8435a6677e4bf266236fea17018b69972a4 /var | |
parent | 15f80ed15c31c4a36c05d9fe405f9bc712898b1c (diff) | |
download | spack-e3101808ae077a3d352d8740cc39d877ed355b86.tar.gz spack-e3101808ae077a3d352d8740cc39d877ed355b86.tar.bz2 spack-e3101808ae077a3d352d8740cc39d877ed355b86.tar.xz spack-e3101808ae077a3d352d8740cc39d877ed355b86.zip |
Make multimethods work with inheritance. (#3411)
Previously, this would fail with a NoSuchMethodError:
class Package(object):
# this is the default implementation
def some_method(self):
...
class Foo(Package):
@when('platform=cray')
def some_method(self):
...
@when('platform=linux')
def some_method(self):
...
This fixes the implementation of `@when` so that the superclass method
will be invoked when no subclass method matches.
Adds tests to ensure this works, as well.
Diffstat (limited to 'var')
-rw-r--r-- | var/spack/repos/builtin.mock/packages/multimethod-base/package.py | 40 | ||||
-rw-r--r-- | var/spack/repos/builtin.mock/packages/multimethod/package.py | 12 |
2 files changed, 51 insertions, 1 deletions
diff --git a/var/spack/repos/builtin.mock/packages/multimethod-base/package.py b/var/spack/repos/builtin.mock/packages/multimethod-base/package.py new file mode 100644 index 0000000000..bd3b29c5ee --- /dev/null +++ b/var/spack/repos/builtin.mock/packages/multimethod-base/package.py @@ -0,0 +1,40 @@ +############################################################################## +# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## +from spack import * + + +class MultimethodBase(Package): + """This is a base class for the Multimethod test case. + + It tests whether mutlimethod properly invokes methods in a base + class when subclass multi-methods do not match. + + """ + + homepage = 'http://www.example.com/' + url = 'http://www.example.com/example-1.0.tar.gz' + + def base_method(self): + return "base_method" diff --git a/var/spack/repos/builtin.mock/packages/multimethod/package.py b/var/spack/repos/builtin.mock/packages/multimethod/package.py index fa3f815135..9e18d65cbb 100644 --- a/var/spack/repos/builtin.mock/packages/multimethod/package.py +++ b/var/spack/repos/builtin.mock/packages/multimethod/package.py @@ -25,8 +25,10 @@ from spack import * import spack.architecture +from spack.pkg.builtin.mock.multimethod_base import MultimethodBase -class Multimethod(Package): + +class Multimethod(MultimethodBase): """This package is designed for use with Spack's multimethod test. It has a bunch of test cases for the @when decorator that the test uses. @@ -132,3 +134,11 @@ class Multimethod(Package): @when('^mpi@2:') def different_by_virtual_dep(self): return 2 + + # + # Make sure methods with a default implementation in a superclass + # will invoke that method when none in the subclass match. + # + @when("@2:") + def base_method(self): + return "subclass_method" |