From 0f3cadcc3eaa9add2961219fd5e52919499ba487 Mon Sep 17 00:00:00 2001 From: Alex Willmer <alex@moreati.org.uk> Date: Fri, 10 May 2019 21:13:32 +0100 Subject: [PATCH] Enable absolute imports, true division, & print() These have no effect in Python 3.x, they are the default. Enabling them in Python 2.x, enabling them in Python 2.x allows single source compatiblity. --- SConstruct | 9 ++++++--- examples/SConscript | 2 ++ examples/base64.py | 2 +- examples/base64_sem1.py | 2 +- examples/base64_sem2.py | 2 +- src/SConscript | 3 +++ src/bindings/cpp/SConscript | 3 +++ src/bindings/dotnet/SConscript | 3 +++ src/bindings/perl/SConscript | 3 +++ src/bindings/php/SConscript | 3 +++ src/bindings/python/SConscript | 3 +++ src/bindings/python/hammer_tests.py | 2 ++ src/bindings/ruby/SConscript | 3 +++ tools/csharp/__init__.py | 4 +++- tools/csharp/csharp.py | 2 ++ tools/csharp/mono.py | 2 ++ tools/scanreplace.py | 2 ++ 17 files changed, 43 insertions(+), 7 deletions(-) diff --git a/SConstruct b/SConstruct index 41b467e9..ae85cda1 100644 --- a/SConstruct +++ b/SConstruct @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os import os.path import platform @@ -43,9 +46,9 @@ env['prefix'] = os.path.abspath(env['prefix']) if 'DESTDIR' in env: env['DESTDIR'] = os.path.abspath(env['DESTDIR']) if rel_prefix: - print >>sys.stderr, '--!!-- You used a relative prefix with a DESTDIR. This is probably not what you' - print >>sys.stderr, '--!!-- you want; files will be installed in' - print >>sys.stderr, '--!!-- %s' % (calcInstallPath('$prefix'),) + print('--!!-- You used a relative prefix with a DESTDIR. This is probably not what you', file=sys.stderr) + print('--!!-- you want; files will be installed in', file=sys.stderr) + print('--!!-- %s' % (calcInstallPath('$prefix'),), file=sys.stderr) env['libpath'] = calcInstallPath('$prefix', 'lib') diff --git a/examples/SConscript b/examples/SConscript index 06947216..b34b85a1 100644 --- a/examples/SConscript +++ b/examples/SConscript @@ -1,3 +1,5 @@ +from __future__ import absolute_import, division, print_function + Import('env') example = env.Clone() diff --git a/examples/base64.py b/examples/base64.py index 3ffe304c..0233ff74 100644 --- a/examples/base64.py +++ b/examples/base64.py @@ -10,7 +10,7 @@ # base64_sem1.py and base64_sem2.py for examples how to attach appropriate # semantic actions to the grammar. -from __future__ import print_function +from __future__ import absolute_import, division, print_function import sys diff --git a/examples/base64_sem1.py b/examples/base64_sem1.py index f0676ebb..2c4d6e04 100644 --- a/examples/base64_sem1.py +++ b/examples/base64_sem1.py @@ -13,7 +13,7 @@ # transform the parse tree in small steps in a bottom-up fashion. Compare # base64_sem2.py for an alternative approach using a single top-level action. -from __future__ import print_function +from __future__ import absolute_import, division, print_function import functools import sys diff --git a/examples/base64_sem2.py b/examples/base64_sem2.py index 6b5f8db1..3b023dd3 100644 --- a/examples/base64_sem2.py +++ b/examples/base64_sem2.py @@ -14,7 +14,7 @@ # for an alternative approach using a fine-grained piece-by-piece # transformation. -from __future__ import print_function +from __future__ import absolute_import, division, print_function import functools import sys diff --git a/src/SConscript b/src/SConscript index a46ddacc..4bd6c28c 100644 --- a/src/SConscript +++ b/src/SConscript @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os.path Import('env testruns') diff --git a/src/bindings/cpp/SConscript b/src/bindings/cpp/SConscript index 9555b988..385759e0 100644 --- a/src/bindings/cpp/SConscript +++ b/src/bindings/cpp/SConscript @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os.path Import("env libhammer_shared testruns targets") diff --git a/src/bindings/dotnet/SConscript b/src/bindings/dotnet/SConscript index 94f874ee..62e4b227 100644 --- a/src/bindings/dotnet/SConscript +++ b/src/bindings/dotnet/SConscript @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os.path Import("env libhammer_shared testruns targets") diff --git a/src/bindings/perl/SConscript b/src/bindings/perl/SConscript index 49b693a7..e3e37c6a 100644 --- a/src/bindings/perl/SConscript +++ b/src/bindings/perl/SConscript @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os.path Import("env libhammer_shared testruns targets") diff --git a/src/bindings/php/SConscript b/src/bindings/php/SConscript index 34728af2..28468007 100644 --- a/src/bindings/php/SConscript +++ b/src/bindings/php/SConscript @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os, os.path Import('env libhammer_shared testruns') diff --git a/src/bindings/python/SConscript b/src/bindings/python/SConscript index dac2d959..d5d092dd 100644 --- a/src/bindings/python/SConscript +++ b/src/bindings/python/SConscript @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os, os.path Import('env libhammer_shared testruns targets') diff --git a/src/bindings/python/hammer_tests.py b/src/bindings/python/hammer_tests.py index 45a63f49..ee79caa3 100644 --- a/src/bindings/python/hammer_tests.py +++ b/src/bindings/python/hammer_tests.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import, division, print_function + import unittest import hammer as h diff --git a/src/bindings/ruby/SConscript b/src/bindings/ruby/SConscript index 6d85a932..d50b644c 100644 --- a/src/bindings/ruby/SConscript +++ b/src/bindings/ruby/SConscript @@ -1,4 +1,7 @@ # -*- python -*- + +from __future__ import absolute_import, division, print_function + import os.path Import("env libhammer_shared testruns targets") diff --git a/tools/csharp/__init__.py b/tools/csharp/__init__.py index af4f5198..fbc9d30e 100644 --- a/tools/csharp/__init__.py +++ b/tools/csharp/__init__.py @@ -21,4 +21,6 @@ # 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 csharp import exists, generate +from __future__ import absolute_import, division, print_function + +from .csharp import exists, generate diff --git a/tools/csharp/csharp.py b/tools/csharp/csharp.py index 6b38b453..f10fc71f 100644 --- a/tools/csharp/csharp.py +++ b/tools/csharp/csharp.py @@ -30,6 +30,8 @@ # This is an attempt to meld to two based initially on the Microsoft C# tool with amendmnets from the Mono # tool. +from __future__ import absolute_import, division, print_function + import os.path import SCons.Builder import SCons.Node.FS diff --git a/tools/csharp/mono.py b/tools/csharp/mono.py index a2cc380e..99c509c1 100644 --- a/tools/csharp/mono.py +++ b/tools/csharp/mono.py @@ -25,6 +25,8 @@ # This C# Tool for Mono taken from http://www.scons.org/wiki/CsharpBuilder. +from __future__ import absolute_import, division, print_function + import os.path import SCons.Builder import SCons.Node.FS diff --git a/tools/scanreplace.py b/tools/scanreplace.py index 5321e481..81a167ef 100644 --- a/tools/scanreplace.py +++ b/tools/scanreplace.py @@ -1,3 +1,5 @@ +from __future__ import absolute_import, division, print_function + from string import Template def replace_action(target, source, env): -- GitLab