diff options
author | Steven Knight <knight@baldmt.com> | 2010-04-19 02:28:06 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2010-04-19 02:28:06 (GMT) |
commit | f1049d9db2e71842802f89b708ba825df304e774 (patch) | |
tree | 17b7ed783aafcd8fdb28147b1bbe621bf4d3f9a4 | |
parent | 391aabed467e2b5d88c13462851fef981cd8c44d (diff) | |
download | SCons-f1049d9db2e71842802f89b708ba825df304e774.zip SCons-f1049d9db2e71842802f89b708ba825df304e774.tar.gz SCons-f1049d9db2e71842802f89b708ba825df304e774.tar.bz2 |
Remove use of the "new" module from --debug=memoizer support.
-rw-r--r-- | src/engine/SCons/Memoize.py | 90 | ||||
-rw-r--r-- | src/engine/SCons/MemoizeTests.py | 16 | ||||
-rw-r--r-- | test/option/debug-memoizer.py | 50 |
3 files changed, 31 insertions, 125 deletions
diff --git a/src/engine/SCons/Memoize.py b/src/engine/SCons/Memoize.py index 30e7d9f..98e3809 100644 --- a/src/engine/SCons/Memoize.py +++ b/src/engine/SCons/Memoize.py @@ -119,7 +119,7 @@ This collected caching logic nicely, but had two drawbacks: to figure out how to optimize the underlying methods. """ -import new +import types # A flag controlling whether or not we actually use memoization. use_memoizer = None @@ -213,77 +213,29 @@ class Memoizer: def __init__(self): pass -# Find out if we support metaclasses (Python 2.2 and later). +def Dump(title=None): + if title: + print title + CounterList.sort() + for counter in CounterList: + counter.display() -class M: +class Memoized_Metaclass(type): def __init__(cls, name, bases, cls_dict): - cls.use_metaclass = 1 - def fake_method(self): - pass - new.instancemethod(fake_method, None, cls) - -try: - class A: - __metaclass__ = M - - use_metaclass = A.use_metaclass -except AttributeError: - use_metaclass = None - reason = 'no metaclasses' -except TypeError: - use_metaclass = None - reason = 'new.instancemethod() bug' -else: - del A - -del M - -if not use_metaclass: - - def Dump(title): - pass + super(Memoized_Metaclass, cls).__init__(name, bases, cls_dict) + + for counter in cls_dict.get('memoizer_counters', []): + method_name = counter.method_name + + counter.name = cls.__name__ + '.' + method_name + counter.underlying_method = cls_dict[method_name] + + replacement_method = types.MethodType(counter, None, cls) + setattr(cls, method_name, replacement_method) - try: - class Memoized_Metaclass(type): - # Just a place-holder so pre-metaclass Python versions don't - # have to have special code for the Memoized classes. - pass - except TypeError: - class Memoized_Metaclass: - # A place-holder so pre-metaclass Python versions don't - # have to have special code for the Memoized classes. - pass - - def EnableMemoization(): - import SCons.Warnings - msg = 'memoization is not supported in this version of Python (%s)' - raise SCons.Warnings.NoMetaclassSupportWarning(msg % reason) - -else: - - def Dump(title=None): - if title: - print title - CounterList.sort() - for counter in CounterList: - counter.display() - - class Memoized_Metaclass(type): - def __init__(cls, name, bases, cls_dict): - super(Memoized_Metaclass, cls).__init__(name, bases, cls_dict) - - for counter in cls_dict.get('memoizer_counters', []): - method_name = counter.method_name - - counter.name = cls.__name__ + '.' + method_name - counter.underlying_method = cls_dict[method_name] - - replacement_method = new.instancemethod(counter, None, cls) - setattr(cls, method_name, replacement_method) - - def EnableMemoization(): - global use_memoizer - use_memoizer = 1 +def EnableMemoization(): + global use_memoizer + use_memoizer = 1 # Local Variables: # tab-width:4 diff --git a/src/engine/SCons/MemoizeTests.py b/src/engine/SCons/MemoizeTests.py index b3edf01..ea2096c 100644 --- a/src/engine/SCons/MemoizeTests.py +++ b/src/engine/SCons/MemoizeTests.py @@ -132,12 +132,8 @@ class CountDictTestCase(unittest.TestCase): c = obj.get_memoizer_counter('dict') - if SCons.Memoize.use_metaclass: - assert c.hit == 3, c.hit - assert c.miss == 2, c.miss - else: - assert c.hit == 0, c.hit - assert c.miss == 0, c.miss + assert c.hit == 3, c.hit + assert c.miss == 2, c.miss class CountValueTestCase(unittest.TestCase): @@ -171,12 +167,8 @@ class CountValueTestCase(unittest.TestCase): c = obj.get_memoizer_counter('value') - if SCons.Memoize.use_metaclass: - assert c.hit == 3, c.hit - assert c.miss == 1, c.miss - else: - assert c.hit == 0, c.hit - assert c.miss == 0, c.miss + assert c.hit == 3, c.hit + assert c.miss == 1, c.miss if __name__ == "__main__": diff --git a/test/option/debug-memoizer.py b/test/option/debug-memoizer.py index f8e4cc3..222ba67 100644 --- a/test/option/debug-memoizer.py +++ b/test/option/debug-memoizer.py @@ -29,33 +29,11 @@ Test calling the --debug=memoizer option. """ import os -import new + import TestSCons test = TestSCons.TestSCons(match = TestSCons.match_re_dotall) -# Find out if we support metaclasses (Python 2.2 and later). - -class M: - def __init__(cls, name, bases, cls_dict): - cls.use_metaclass = 1 - def fake_method(self): - pass - new.instancemethod(fake_method, None, cls) - -try: - class A: - __metaclass__ = M - - use_metaclass = A.use_metaclass -except AttributeError: - use_metaclass = None - reason = 'no metaclasses' -except TypeError: - use_metaclass = None - reason = 'new.instancemethod\\(\\) bug' - - test.write('SConstruct', """ def cat(target, source, env): @@ -79,27 +57,9 @@ expect = [ ] -if use_metaclass: - - def run_and_check(test, args, desc): - test.run(arguments = args) - test.must_contain_any_line(test.stdout(), expect) - -else: - - expect_no_metaclasses = """ -scons: warning: memoization is not supported in this version of Python \\(%s\\) -""" % reason - - expect_no_metaclasses = expect_no_metaclasses + TestSCons.file_expr - - def run_and_check(test, args, desc): - test.run(arguments = args, stderr = expect_no_metaclasses) - test.must_not_contain_any_line(test.stdout(), expect) - - for args in ['-h --debug=memoizer', '--debug=memoizer']: - run_and_check(test, args, "command line '%s'" % args) + test.run(arguments = args) + test.must_contain_any_line(test.stdout(), expect) test.must_match('file.out', "file.in\n") @@ -111,7 +71,9 @@ test.unlink("file.out") os.environ['SCONSFLAGS'] = '--debug=memoizer' -run_and_check(test, '', 'SCONSFLAGS=--debug=memoizer') +test.run(arguments = '') + +test.must_contain_any_line(test.stdout(), expect) test.must_match('file.out', "file.in\n") |