From bcdc9a412521ae0b9f9aea7997a880af6dbda2a6 Mon Sep 17 00:00:00 2001 From: Greg Noel Date: Sat, 24 Apr 2010 22:25:56 +0000 Subject: Convert to Python 3.x division rules. --- QMTest/TestCmd.py | 1 + QMTest/TestSCons.py | 7 ++++--- QMTest/scons_tdb.py | 2 +- bench/bench.py | 1 + bench/timeit.py | 1 + bin/calibrate.py | 3 ++- bin/linecount.py | 1 + bin/svn-bisect.py | 3 ++- src/engine/SCons/Defaults.py | 5 ++--- src/engine/SCons/Node/FSTests.py | 7 ++++--- src/engine/SCons/Script/SConscript.py | 3 ++- src/engine/SCons/TaskmasterTests.py | 5 +++-- src/engine/SCons/Tool/intelc.py | 4 ++-- src/script/scons-time.py | 8 ++++---- test/option/debug-time.py | 2 +- 15 files changed, 31 insertions(+), 22 deletions(-) diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 301e5a6..1ee5d4e 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -213,6 +213,7 @@ version. # PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, # AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. +from __future__ import division __author__ = "Steven Knight " __revision__ = "TestCmd.py 0.37.D001 2010/01/11 16:55:50 knight" diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py index e35cbfe..f9e2250 100644 --- a/QMTest/TestSCons.py +++ b/QMTest/TestSCons.py @@ -13,6 +13,7 @@ attributes defined in this subclass. """ # __COPYRIGHT__ +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -994,13 +995,13 @@ class Stat: StatList = [ Stat('memory-initial', 'kbytes', r'Memory before reading SConscript files:\s+(\d+)', - convert=lambda s: int(s) / 1024), + convert=lambda s: int(s) // 1024), Stat('memory-prebuild', 'kbytes', r'Memory before building targets:\s+(\d+)', - convert=lambda s: int(s) / 1024), + convert=lambda s: int(s) // 1024), Stat('memory-final', 'kbytes', r'Memory after building targets:\s+(\d+)', - convert=lambda s: int(s) / 1024), + convert=lambda s: int(s) // 1024), Stat('time-sconscript', 'seconds', r'Total SConscript file execution time:\s+([\d.]+) seconds'), diff --git a/QMTest/scons_tdb.py b/QMTest/scons_tdb.py index e2c40df..6be4696 100644 --- a/QMTest/scons_tdb.py +++ b/QMTest/scons_tdb.py @@ -20,7 +20,7 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# +from __future__ import division """ QMTest classes to support SCons' testing and Aegis-inspired workflow. diff --git a/bench/bench.py b/bench/bench.py index 3391f9d..74dbf12 100644 --- a/bench/bench.py +++ b/bench/bench.py @@ -23,6 +23,7 @@ # # This will allow (as much as possible) us to time just the code itself, # not Python function call overhead. +from __future__ import division import getopt import sys diff --git a/bench/timeit.py b/bench/timeit.py index 199b7c9..ed94361 100644 --- a/bench/timeit.py +++ b/bench/timeit.py @@ -46,6 +46,7 @@ be aware of it. The baseline overhead can be measured by invoking the program without arguments. The baseline overhead differs between Python versions! """ +from __future__ import division try: import gc diff --git a/bin/calibrate.py b/bin/calibrate.py index c5d45ce..f377869 100644 --- a/bin/calibrate.py +++ b/bin/calibrate.py @@ -20,6 +20,7 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +from __future__ import division import optparse import os @@ -71,7 +72,7 @@ def main(argv=None): good = 0 for v in vm.groups(): var, value = v.split('=', 1) - value = int((int(value) * opts.max) / elapsed) + value = int((int(value) * opts.max) // elapsed) os.environ[var] = str(value) run += 1 diff --git a/bin/linecount.py b/bin/linecount.py index 7dd4c20..6f49dca 100644 --- a/bin/linecount.py +++ b/bin/linecount.py @@ -21,6 +21,7 @@ # in each category, the number of non-blank lines, and the number of # non-comment lines. The last figure (non-comment) lines is the most # interesting one for most purposes. +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" diff --git a/bin/svn-bisect.py b/bin/svn-bisect.py index e9ebcf8..77bda58 100755 --- a/bin/svn-bisect.py +++ b/bin/svn-bisect.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # -*- Python -*- +from __future__ import division import sys from math import log, ceil @@ -52,7 +53,7 @@ msg = "****** max %d revisions to test (bug bracketed by [%d,%d])" while upper-lower > 1: print msg % (ceil(log(upper-lower,2)), lower, upper) - mid = int((lower + upper)/2) + mid = (lower + upper)//2 midfails = testfail(mid) if midfails == lowerfails: lower = mid diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py index ece6d59..be6ea9f 100644 --- a/src/engine/SCons/Defaults.py +++ b/src/engine/SCons/Defaults.py @@ -31,13 +31,12 @@ from distutils.msvccompiler. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" - import os -import os.path import errno import shutil import stat @@ -435,7 +434,7 @@ class Variable_Method_Caller: self.variable = variable self.method = method def __call__(self, *args, **kw): - try: 1/0 + try: 1//0 except ZeroDivisionError: # Don't start iterating with the current stack-frame to # prevent creating reference cycles (f_back is safe). diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py index 7fcec8f..38a895b 100644 --- a/src/engine/SCons/Node/FSTests.py +++ b/src/engine/SCons/Node/FSTests.py @@ -20,6 +20,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -1307,7 +1308,7 @@ class FSTestCase(_tempdirTestCase): # We round down the current time to the nearest even integer # value, subtract two to make sure the timestamp is not "now," # and then convert it back to a float. - tstamp = float(int(time.time() / 2) * 2) - 2 + tstamp = float(int(time.time() // 2) * 2) - 2.0 os.utime(test.workpath("tstamp"), (tstamp - 2.0, tstamp)) f = fs.File("tstamp") t = f.get_timestamp() @@ -1325,7 +1326,7 @@ class FSTestCase(_tempdirTestCase): f2 = test.workpath('tdir2', 'file2') test.write(f1, 'file1\n') test.write(f2, 'file2\n') - current_time = float(int(time.time() / 2) * 2) + current_time = float(int(time.time() // 2) * 2) t1 = current_time - 4.0 t2 = current_time - 2.0 os.utime(f1, (t1 - 2.0, t1)) @@ -2786,7 +2787,7 @@ class RepositoryTestCase(_tempdirTestCase): # We round down the current time to the nearest even integer # value, subtract two to make sure the timestamp is not "now," # and then convert it back to a float. - tstamp = float(int(time.time() / 2) * 2) - 2 + tstamp = float(int(time.time() // 2) * 2) - 2.0 os.utime(test.workpath("rep2", "tstamp"), (tstamp - 2.0, tstamp)) f = fs.File("tstamp") t = f.get_timestamp() diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 5928a88..ed077ba 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -26,6 +26,7 @@ files. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -77,7 +78,7 @@ sconscript_chdir = 1 def get_calling_namespaces(): """Return the locals and globals for the function that called into this module in the current call stack.""" - try: 1/0 + try: 1//0 except ZeroDivisionError: # Don't start iterating with the current stack-frame to # prevent creating reference cycles (f_back is safe). diff --git a/src/engine/SCons/TaskmasterTests.py b/src/engine/SCons/TaskmasterTests.py index 3dd22e3..e95e92c 100644 --- a/src/engine/SCons/TaskmasterTests.py +++ b/src/engine/SCons/TaskmasterTests.py @@ -20,6 +20,7 @@ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -969,7 +970,7 @@ class TaskmasterTestCase(unittest.TestCase): t.exception_set(3) assert t.exception == 3 - try: 1/0 + try: 1//0 except: pass t.exception_set(None) exc_type, exc_value, exc_tb = t.exception @@ -1010,7 +1011,7 @@ class TaskmasterTestCase(unittest.TestCase): pass try: - 1/0 + 1//0 except: tb = sys.exc_info()[2] t.exception_set((Exception3, "arg", tb)) diff --git a/src/engine/SCons/Tool/intelc.py b/src/engine/SCons/Tool/intelc.py index 9f782ee..5629636 100644 --- a/src/engine/SCons/Tool/intelc.py +++ b/src/engine/SCons/Tool/intelc.py @@ -30,7 +30,7 @@ selection method. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -81,7 +81,7 @@ def linux_ver_normalize(vstr): m = re.match(r'([0-9]+)\.([0-9]+)\.([0-9]+)', vstr) if m: vmaj,vmin,build = m.groups() - return float(vmaj) * 10 + float(vmin) + float(build) / 1000.; + return float(vmaj) * 10. + float(vmin) + float(build) / 1000.; else: f = float(vstr) if is_windows: diff --git a/src/script/scons-time.py b/src/script/scons-time.py index b35cc32..37ee593 100644 --- a/src/script/scons-time.py +++ b/src/script/scons-time.py @@ -29,7 +29,7 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# +from __future__ import division from __future__ import nested_scopes __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" @@ -120,12 +120,12 @@ class Plotter: between 5 and 9 horizontal lines on the graph, on some set of boundaries that are multiples of 10/100/1000/etc. """ - i = largest / 5 + i = largest // 5 if not i: return largest multiplier = 1 while i >= 10: - i = i / 10 + i = i // 10 multiplier = multiplier * 10 return i * multiplier @@ -133,7 +133,7 @@ class Plotter: # Round up to next integer. largest = int(largest) + 1 increment = self.increment_size(largest) - return ((largest + increment - 1) / increment) * increment + return ((largest + increment - 1) // increment) * increment class Line: def __init__(self, points, type, title, label, comment, fmt="%s %s"): diff --git a/test/option/debug-time.py b/test/option/debug-time.py index 39a47c1..324dc28 100644 --- a/test/option/debug-time.py +++ b/test/option/debug-time.py @@ -20,7 +20,7 @@ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# +from __future__ import division __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" -- cgit v0.12