Fixes for Python 3 compatibility. https://sourceforge.net/p/ggt/bugs/29/ --- SConstruct.orig 2023-03-09 18:31:41.000000000 -0600 +++ SConstruct 2023-03-09 18:33:02.000000000 -0600 @@ -17,11 +17,6 @@ sys.path.append('tools/build') from AutoDist import * -# True and False were not defined prior to Python 2.2.1. -if sys.version[:3] == '2.2' and sys.version[3] != '.': - False = 0 - True = 1 - enable_python = False boost_version = '1.31' have_cppunit = False @@ -49,17 +44,17 @@ def GetPlatform(): "Determines what platform this build is being run on." - if string.find(sys.platform, 'irix') != -1: + if sys.platform.find('irix') != -1: return 'irix' - elif string.find(sys.platform, 'linux') != -1: + elif sys.platform.find('linux') != -1: return 'linux' - elif string.find(sys.platform, 'freebsd') != -1: + elif sys.platform.find('freebsd') != -1: return 'freebsd' - elif string.find(sys.platform, 'darwin') != -1: + elif sys.platform.find('darwin') != -1: return 'darwin' - elif string.find(sys.platform, 'cygwin') != -1: + elif sys.platform.find('cygwin') != -1: return 'cygwin' - elif string.find(os.name, 'win32') != -1: + elif os.name.find('win32') != -1: return 'win32' else: return sys.platform @@ -218,21 +213,21 @@ def BuildWin32Environment(): global optimize, compiler_major_ver - if ARGUMENTS.has_key("MSVS_VERSION"): + if "MSVS_VERSION" in ARGUMENTS: # Python extension modules can only be built using Visual C++ 7.1 or # 9.0. msvs_ver = ARGUMENTS["MSVS_VERSION"] if msvs_ver not in ("7.1", "9.0"): - print "Cannot build Python extensions using MSVS version %s" % \ - msvs_ver + print("Cannot build Python extensions using MSVS version %s" % \ + msvs_ver) sys.exit(1) python_ver = sys.version[:3] if msvs_ver == "7.1" and python_ver not in ("2.4", "2.5"): - print "Python 2.4 or 2.5 must be used with Visual C++ 7.1" + print("Python 2.4 or 2.5 must be used with Visual C++ 7.1") sys.exit(1) elif msvs_ver == "9.0" and python_ver not in ("2.6"): - print "Python 2.6 must be used with Visual C++ 9.0" + print("Python 2.6 must be used with Visual C++ 9.0") sys.exit(1) env = Environment(MSVS_VERSION = msvs_ver) @@ -242,7 +237,7 @@ else: env = Environment(ENV = os.environ) - print "Using MSVS version:", env["MSVS"]["VERSION"] + print("Using MSVS version:", env["MSVS"]["VERSION"]) compiler_major_ver = env["MSVS"]["VERSION"] # We need exception handling support turned on for Boost.Python. @@ -286,7 +281,7 @@ elif GetPlatform() == 'cygwin': env = BuildCygwinEnvironment() else: - print 'Unsupported build environment: ' + GetPlatform(), "Trying default" + print('Unsupported build environment: ' + GetPlatform(), "Trying default") env = Environment() return env @@ -302,7 +297,7 @@ exp = re.compile('^(\d+\.\d+(\.\d+)?)\D*$') match = exp.search(value) boost_version = match.group(1) - print "Using Boost version", boost_version + print("Using Boost version", boost_version) else: assert False, "Invalid Boost key" @@ -310,7 +305,7 @@ "Validate the boost option settings" global enable_python, optimize, compiler_major_ver req_boost_version = 103100 - print "checking for %s [%s]...\n" % (key, value) + print("checking for %s [%s]...\n" % (key, value)) if "BoostPythonDir" == key: version_dir = 'boost-' + re.sub(r'\.', '_', boost_version) @@ -318,16 +313,16 @@ potential_inc_paths = [pj('include', version_dir), "include"] for pth in potential_inc_paths: if os.path.isdir(pj(value,pth)): - boost_inc_dir = pj(value,pth) - break - print " trying boost include dir: [%s]"%boost_inc_dir + boost_inc_dir = pj(value,pth) + break + print(" trying boost include dir: [%s]"%boost_inc_dir) # Get the boost version. boost_ver_filename = pj(boost_inc_dir, 'boost', 'version.hpp') if not os.path.isfile(boost_ver_filename): sys.stdout.write("%s not found.\n" % boost_ver_filename) - enable_python = False - return False + enable_python = False + return False ver_file = file(boost_ver_filename) @@ -337,7 +332,7 @@ sys.stdout.write("found version: %s\n" % ver_num) if ver_num < req_boost_version: - print " Boost version too old! Required version: %s" % req_boost_version + print(" Boost version too old! Required version: %s" % req_boost_version) Exit() return False @@ -417,16 +412,16 @@ '%s%s.%s' % (shlib_prefix, n, shlib_ext)) - print "Checking for '%s'" % boost_python_lib_name + print("Checking for '%s'" % boost_python_lib_name) if os.path.isfile(boost_python_lib_name): - print "Using '%s'" % boost_python_lib_name + print("Using '%s'" % boost_python_lib_name) bpl_libdir = l bpl_name = n bpl_found = True break if not bpl_found: - print "No Boost.Python library was found in", libdirs + print("No Boost.Python library was found in", libdirs) Exit() return False @@ -475,7 +470,7 @@ python = WhereIs('python') if not python: enable_python = False - print 'WARNING: Can\'t find python executable' + print('WARNING: Can\'t find python executable') return False py_cmd = python + ' -c \'import sys; print sys.prefix; print sys.version[:3]\'' @@ -496,7 +491,7 @@ # Version must match if float(py_ver) < required_version: - print 'WARNING: Python version ' + py_ver + ' != ' + str(required_version) + print('WARNING: Python version ' + py_ver + ' != ' + str(required_version)) enable_python = False else: # Build up the env information @@ -570,11 +565,11 @@ } my_file = env.SubstBuilder('file.out','file.in', submap=submap) - env.AddPostAction (my_file, Chmod('$TARGET', 0644)) + env.AddPostAction (my_file, Chmod('$TARGET', 0o644)) env.Depends(my_file, 'version.h') """ - targets = map(lambda x: str(x), target) - sources = map(lambda x: str(x), source) + targets = [str(x) for x in target] + sources = [str(x) for x in source] submap = env['submap'] @@ -585,12 +580,12 @@ # Go through the substitution dictionary and modify the contents read in # from the source file - for key, value in submap.items(): + for key, value in list(submap.items()): contents = contents.replace(key, value); # Write out the target file with the new contents open(targets[i], 'w').write(contents) - os.chmod(targets[i], 0755) + os.chmod(targets[i], 0o755) def generate_builder_str(target, source, env): builderStr = "generating: "; @@ -609,7 +604,7 @@ # Figure out what version of GMTL we're building GMTL_VERSION = GetGMTLVersion() -print 'Building GMTL Version: %i.%i.%i' % GMTL_VERSION +print('Building GMTL Version: %i.%i.%i' % GMTL_VERSION) help_text = "\n---- GMTL Build System ----\n" @@ -620,7 +615,7 @@ Prefix(PREFIX) Export('PREFIX') Export('optimize') -print "Install prefix: ", Prefix() +print("Install prefix: ", Prefix()) baseEnv = BuildPlatformEnv() baseEnv["BUILDERS"]["SubstBuilder"] = \ @@ -662,7 +657,7 @@ Export('installed_targets') if not has_help_flag: - print "Preparing build settings...\n" + print("Preparing build settings...\n") # Create the GMTL package pkg = Package('gmtl', '%i.%i.%i' % GMTL_VERSION) @@ -693,10 +688,9 @@ # Find gmtl headers, set up install rule and add to package gmtl_headers = [] - def get_headers(hdrs, dirname, flist): - hdrs.extend( [pj(dirname,f) for f in flist if f.endswith('.h')]) - os.path.walk('gmtl',get_headers,gmtl_headers) - #print "GMTL Headers:\n", gmtl_headers, "\n" + for dirname, _, flist in os.walk('gmtl'): + gmtl_headers.extend([pj(dirname, f) for f in flist if f.endswith('.h')]) + #print("GMTL Headers:\n", gmtl_headers, "\n") # --- Setup installation paths --- # base_inst_paths = {} @@ -715,7 +709,7 @@ base_inst_paths['include'] = pj(base_inst_paths['base'], 'include', include_version) - print "using prefix:", base_inst_paths['base'] + print("using prefix:", base_inst_paths['base']) for h in gmtl_headers: installed_targets += baseEnv.InstallAs(pj(PREFIX, include_dir, h), h) @@ -762,7 +756,7 @@ fpc_filename = "-".join(name_parts) + ".fpc" gmtl_fpc = env.SubstBuilder(pj(base_inst_paths['flagpoll'], fpc_filename), 'gmtl.fpc.in', submap = submap) - env.AddPostAction(gmtl_fpc, Chmod('$TARGET', 0644)) + env.AddPostAction(gmtl_fpc, Chmod('$TARGET', 0o644)) env.Depends(gmtl_fpc, 'gmtl/Version.h') gmtl_pc = env.SubstBuilder(pj(base_inst_paths['pkgconfig'], "gmtl.pc"), 'gmtl.fpc.in', submap = submap)