diff --git a/build/SConscript.configure b/build/SConscript.configure index fe9a25028..baca8b748 100644 --- a/build/SConscript.configure +++ b/build/SConscript.configure @@ -1,3 +1,4 @@ +from __future__ import print_function import re, multiprocessing Import('sys', 'os', 'SCons', 'resources') @@ -20,14 +21,14 @@ if parallelize == True: SetOption('num_jobs', multiprocessing.cpu_count()) if not os.path.exists(configFile): - print '\nA configuration file must be selected! Have a look at http://www.mitsuba-renderer.org/docs.html' + print('\nA configuration file must be selected! Have a look at http://www.mitsuba-renderer.org/docs.html') Exit(1) needsBuildDependencies = (sys.platform == 'win32' or sys.platform == 'darwin') if needsBuildDependencies and not os.path.exists(GetBuildPath('#dependencies')): - print '\nThe required build dependency files are missing. Please see the documentation' - print 'at http://www.mitsuba-renderer.org/docs.html for details on how to get them.\n' + print('\nThe required build dependency files are missing. Please see the documentation') + print('at http://www.mitsuba-renderer.org/docs.html for details on how to get them.\n') Exit(1) python_versions = ["2.6", "2.7", "3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7"] @@ -94,11 +95,11 @@ vars.Add('INTEL_COMPILER', 'Should the Intel C++ compiler be used?') try: env = Environment(options=vars, ENV = os.environ, tools=['default', 'qt5'], toolpath=['#data/scons']) - print 'Checking for Qt 5.x... yes' + print('Checking for Qt 5.x... yes') hasQt = True except Exception: env = Environment(options=vars, ENV = os.environ, tools=['default'], toolpath=['#data/scons']) - print 'Unable to detect a Qt installation -- not building the GUI!' + print('Unable to detect a Qt installation -- not building the GUI!') hasQt = False hasCollada=True @@ -108,19 +109,19 @@ env.Append(CPPPATH=env['BASEINCLUDE']) env.Append(CPPFLAGS=[]) env.Append(LIBPATH=[]) env.Append(LIBS=env['BASELIB']) -if env.has_key('BOOSTINCLUDE'): +if 'BOOSTINCLUDE' in env: env.Prepend(CPPPATH=env['BOOSTINCLUDE']) -if env.has_key('BOOSTLIBDIR'): +if 'BOOSTLIBDIR' in env: env.Prepend(LIBPATH=env['BOOSTLIBDIR']) -if env.has_key('BOOSTLIB'): +if 'BOOSTLIB' in env: env.Prepend(LIBS=env['BOOSTLIB']) -if env.has_key('BASELIBDIR'): +if 'BASELIBDIR' in env: env.Append(LIBPATH=env['BASELIBDIR']) -if env.has_key('OEXRINCLUDE'): +if 'OEXRINCLUDE' in env: env.Prepend(CPPPATH=env['OEXRINCLUDE']) -if env.has_key('OEXRLIBDIR'): +if 'OEXRLIBDIR' in env: env.Prepend(LIBPATH=env['OEXRLIBDIR']) -if env.has_key('EIGENINCLUDE'): +if 'EIGENINCLUDE' in env: env.Prepend(CPPPATH=env['EIGENINCLUDE']) env.Decider('MD5-timestamp') @@ -140,64 +141,64 @@ libPathPrevious = SCons.Util.semi_deepcopy(env['LIBPATH']) cppFlagsPrevious = SCons.Util.semi_deepcopy(env['CPPFLAGS']) cxxFlagsPrevious = SCons.Util.semi_deepcopy(env['CXXFLAGS']) -if env.has_key('PNGINCLUDE'): +if 'PNGINCLUDE' in env: env.Prepend(CPPPATH=env['PNGINCLUDE']) -if env.has_key('PNGLIBDIR'): +if 'PNGLIBDIR' in env: env.Prepend(LIBPATH=env['PNGLIBDIR']) -if env.has_key('JPEGINCLUDE'): +if 'JPEGINCLUDE' in env: env.Prepend(CPPPATH=env['JPEGINCLUDE']) -if env.has_key('JPEGLIBDIR'): +if 'JPEGLIBDIR' in env: env.Prepend(LIBPATH=env['JPEGLIBDIR']) -if env.has_key('OEXRFLAGS'): +if 'OEXRFLAGS' in env: env.Prepend(CPPFLAGS=env['OEXRFLAGS']) -if env.has_key('OEXRINCLUDE'): +if 'OEXRINCLUDE' in env: env.Prepend(CPPPATH=env['OEXRINCLUDE']) -if env.has_key('OEXRLIBDIR'): +if 'OEXRLIBDIR' in env: env.Prepend(LIBPATH=env['OEXRLIBDIR']) -if env.has_key('XERCESINCLUDE'): +if 'XERCESINCLUDE' in env: env.Prepend(CPPPATH=env['XERCESINCLUDE']) -if env.has_key('XERCESLIBDIR'): +if 'XERCESLIBDIR' in env: env.Prepend(LIBPATH=env['XERCESLIBDIR']) -if env.has_key('GLINCLUDE'): +if 'GLINCLUDE' in env: env.Prepend(CPPPATH=env['GLINCLUDE']) -if env.has_key('GLFLAGS'): +if 'GLFLAGS' in env: env.Prepend(CPPFLAGS=env['GLFLAGS']) -if env.has_key('COLLADAINCLUDE'): +if 'COLLADAINCLUDE' in env: env.Prepend(CPPPATH=env['COLLADAINCLUDE']) -if env.has_key('COLLADALIBDIR'): +if 'COLLADALIBDIR' in env: env.Prepend(LIBPATH=env['COLLADALIBDIR']) -if env.has_key('FFTWINCLUDE'): +if 'FFTWINCLUDE' in env: env.Prepend(CPPPATH=env['FFTWINCLUDE']) -if env.has_key('FFTWLIBDIR'): +if 'FFTWLIBDIR' in env: env.Prepend(LIBPATH=env['FFTWLIBDIR']) if not conf.CheckCXX(): - print 'Could not compile a simple C++ fragment, verify that ' + \ + print('Could not compile a simple C++ fragment, verify that ' + \ env['CXX'] + ' is installed! This could also mean that the ' + \ 'Boost libraries are missing. The file "config.log" should ' + \ - 'contain more information.' + 'contain more information.') Exit(1) if not conf.CheckCHeader(['png.h']): - print 'libpng is missing (install libpng12-dev for PNG I/O support)' + print('libpng is missing (install libpng12-dev for PNG I/O support)') else: env.Append(CPPDEFINES = [['MTS_HAS_LIBPNG', 1]] ) if not conf.CheckCHeader(['stdio.h', 'jpeglib.h']): - print 'libjpeg is missing (install libjpeg62-dev for JPEG I/O support)' + print('libjpeg is missing (install libjpeg62-dev for JPEG I/O support)') else: env.Append(CPPDEFINES = [['MTS_HAS_LIBJPEG', 1]] ) if not conf.CheckCXXHeader('ImfRgba.h'): - print 'OpenEXR is missing (install libopenexr-dev for OpenEXR I/O support)' + print('OpenEXR is missing (install libopenexr-dev for OpenEXR I/O support)') else: env.Append(CPPDEFINES = [['MTS_HAS_OPENEXR', 1]] ) if not conf.CheckCXXHeader('xercesc/dom/DOMLSParser.hpp'): - print 'Xerces-C++ 3.x must be installed (install libxerces-c-dev)!' + print('Xerces-C++ 3.x must be installed (install libxerces-c-dev)!') Exit(1) if not conf.CheckCXXHeader('dae.h'): hasCollada = False - print 'COLLADA DOM is missing: not building the COLLADA importer' + print('COLLADA DOM is missing: not building the COLLADA importer') hasBreakpad = '-DMTS_HAS_BREAKPAD' in env['CCFLAGS'] or 'MTS_HAS_BREAKPAD' in env['CXXFLAGS'] @@ -211,54 +212,54 @@ for ver in python_versions: if conf.CheckCXXHeader('pyconfig.h'): hasPython += [ ver ] else: - print 'Python ' + ver + ' is missing: not building wrappers' + print('Python ' + ver + ' is missing: not building wrappers') env['CPPPATH'][:] = [ x for x in env['CPPPATH'] if x not in includePath ] if not conf.CheckCXXHeader('boost/version.hpp'): - print 'Boost is missing (install libboost-all-dev)!' + print('Boost is missing (install libboost-all-dev)!') Exit(1) if not conf.TryCompile("#include \n#if BOOST_VERSION < 104400\n#error Boost is outdated!\n#endif", ".cpp"): - print 'Boost is outdated (you will need version 1.44 or newer)!' + print('Boost is outdated (you will need version 1.44 or newer)!') Exit(1) if not conf.CheckCXXHeader('Eigen/Core'): - print 'Eigen 3.x is missing (install libeigen3-dev)!' + print('Eigen 3.x is missing (install libeigen3-dev)!') Exit(1) if not conf.CheckCXXHeader('fftw3.h'): - print 'FFTW3 not found (install for fast image convolution support)' + print('FFTW3 not found (install for fast image convolution support)') else: env.Append(CPPDEFINES = [['MTS_HAS_FFTW', 1]] ) if sys.platform == 'win32': if not (conf.CheckCHeader(['windows.h', 'GL/gl.h']) \ and conf.CheckCHeader(['windows.h', 'GL/glu.h']) \ and conf.CheckCHeader(['windows.h', 'GL/gl.h', 'GL/glext.h'])): - print 'OpenGL headers are missing!' + print('OpenGL headers are missing!') Exit(1) if not conf.CheckCHeader('GL/glew.h'): - print 'GLEW headers are missing!' + print('GLEW headers are missing!') Exit(1) elif sys.platform == 'linux2': if not (conf.CheckCHeader('GL/gl.h') and conf.CheckCHeader('GL/glu.h') and conf.CheckCHeader(['GL/gl.h', 'GL/glext.h'])): - print 'OpenGL headers are missing!' + print('OpenGL headers are missing!') Exit(1) if not conf.CheckCHeader('GL/glew.h'): - print 'GLEW headers are missing (install libglewmx1.5-dev)!' + print('GLEW headers are missing (install libglewmx1.5-dev)!') Exit(1) if not conf.CheckType('GLEWContext', '#include '): - print 'GLEW-MX must be present!' + print('GLEW-MX must be present!') Exit(1) if not conf.TryCompile("#include \n int i = GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV;", '.cpp'): - print 'Your version of GLEW-MX seems to be outdated!' + print('Your version of GLEW-MX seems to be outdated!') Exit(1) elif sys.platform == 'darwin': if not (conf.CheckCHeader('OpenGL/gl.h') and conf.CheckCHeader('OpenGL/glu.h') and conf.CheckCHeader(['OpenGL/gl.h', 'OpenGL/glext.h'])): - print 'OpenGL headers are missing!' + print('OpenGL headers are missing!') Exit(1) if not conf.CheckCHeader('OpenGL/glew.h'): - print 'GLEW headers are missing!' + print('GLEW headers are missing!') Exit(1) if sys.platform == 'linux2': if not (conf.CheckCHeader(['X11/Xlib.h', 'X11/extensions/xf86vmode.h'])): - print 'X Video Mode selection library headers are missing! (Install libxxf86vm-dev)' + print('X Video Mode selection library headers are missing! (Install libxxf86vm-dev)') Exit(1) env.Replace(CPPPATH=cppPathPrevious) @@ -273,10 +274,10 @@ for line in file: if line.startswith("#define MTS_VERSION "): MTS_VERSION = line[21:len(line)-2] if MTS_VERSION == "": - print 'could not be determined!' + print('could not be determined!') Exit(1) else: - print MTS_VERSION + print(MTS_VERSION) Export('MTS_VERSION') if needsBuildDependencies: @@ -293,14 +294,14 @@ if needsBuildDependencies: versionMismatch = True if versionMismatch: - print '\nThe dependency directory and your Mitsuba codebase have different version' - print 'numbers! Your copy of Mitsuba has version %s, whereas the dependencies ' % MTS_VERSION - print 'have version %s. Please bring them into sync, either by running\n' % depVersion - print '$ hg update -r v%s\n' % depVersion - print 'in the Mitsuba directory, or by running\n' - print '$ cd dependencies' - print '$ hg pull' - print '$ hg update -r v%s\n' % MTS_VERSION + print('\nThe dependency directory and your Mitsuba codebase have different version') + print('numbers! Your copy of Mitsuba has version %s, whereas the dependencies ' % MTS_VERSION) + print('have version %s. Please bring them into sync, either by running\n' % depVersion) + print('$ hg update -r v%s\n' % depVersion) + print('in the Mitsuba directory, or by running\n') + print('$ cd dependencies') + print('$ hg pull') + print('$ hg update -r v%s\n' % MTS_VERSION) Exit(1) env = conf.Finish() diff --git a/build/SConscript.install b/build/SConscript.install index 1db43c99f..45fd6a18e 100644 --- a/build/SConscript.install +++ b/build/SConscript.install @@ -1,3 +1,4 @@ +from __future__ import print_function import fnmatch Import('env', 'os', 'sys', 'plugins', 'dist', @@ -27,7 +28,7 @@ def installAs(target, path, prefix = None): return result if not 'DISTDIR' in env: - print 'The \"DISTDIR\" variable is missing. Please update your configuration file!' + print('The \"DISTDIR\" variable is missing. Please update your configuration file!') Exit(1) distDir = env.GetBuildPath(env['DISTDIR']) diff --git a/data/scons/qt5.py b/data/scons/qt5.py index 4bddb8985..38c2cfd9f 100644 --- a/data/scons/qt5.py +++ b/data/scons/qt5.py @@ -135,23 +135,28 @@ def __call__(self, target, source, env): out_sources = source[:] for obj in source: - if isinstance(obj,basestring): # big kludge! - print "scons: qt5: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj) + if isinstance(obj,str): # big kludge! + print("scons: qt5: '%s' MAYBE USING AN OLD SCONS VERSION AND NOT CONVERTED TO 'File'. Discarded." % str(obj)) continue if not obj.has_builder(): # binary obj file provided if debug: - print "scons: qt: '%s' seems to be a binary. Discarded." % str(obj) + print("scons: qt: '%s' seems to be a binary. Discarded." % str(obj)) continue cpp = obj.sources[0] if not splitext(str(cpp))[1] in cxx_suffixes: if debug: - print "scons: qt: '%s' is no cxx file. Discarded." % str(cpp) + print("scons: qt: '%s' is no cxx file. Discarded." % str(cpp)) # c or fortran source continue #cpp_contents = comment.sub('', cpp.get_contents()) try: cpp_contents = cpp.get_contents() + + # cpp_contents can be bytes or string. Use try: to convert it into string. + try: cpp_contents = cpp_contents.decode() + except (UnicodeDecodeError, AttributeError): pass + except: continue # may be an still not generated source h=None for h_ext in header_extensions: @@ -161,12 +166,16 @@ def __call__(self, target, source, env): h = find_file(hname, (cpp.get_dir(),), env.File) if h: if debug: - print "scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp)) + print("scons: qt: Scanning '%s' (header of '%s')" % (str(h), str(cpp))) #h_contents = comment.sub('', h.get_contents()) h_contents = h.get_contents() + + try: h_contents = h_contents.decode() + except (UnicodeDecodeError, AttributeError): pass + break if not h and debug: - print "scons: qt: no header for '%s'." % (str(cpp)) + print("scons: qt: no header for '%s'." % (str(cpp))) if h and q_object_search.search(h_contents): # h file with the Q_OBJECT macro found -> add moc_cpp moc_cpp = env.Moc5(h) @@ -174,14 +183,14 @@ def __call__(self, target, source, env): out_sources.append(moc_o) #moc_cpp.target_scanner = SCons.Defaults.CScan if debug: - print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp)) + print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(h), str(moc_cpp))) if cpp and q_object_search.search(cpp_contents): # cpp file with Q_OBJECT macro found -> add moc # (to be included in cpp) moc = env.Moc5(cpp) env.Ignore(moc, moc) if debug: - print "scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc)) + print("scons: qt: found Q_OBJECT macro in '%s', moc'ing to '%s'" % (str(cpp), str(moc))) #moc.source_scanner = SCons.Defaults.CScan # restore the original env attributes (FIXME) objBuilder.env = objBuilderEnv @@ -303,6 +312,10 @@ def recursiveFiles(basepath, path) : result.append(itemPath) return result contents = node.get_contents() + + try: contents = contents.decode() + except (UnicodeDecodeError, AttributeError): pass + includes = qrcinclude_re.findall(contents) qrcpath = os.path.dirname(node.path) dirs = [included for included in includes if os.path.isdir(os.path.join(qrcpath,included))] diff --git a/src/mtsgui/SConscript b/src/mtsgui/SConscript index 0cc822265..602d5ecd3 100644 --- a/src/mtsgui/SConscript +++ b/src/mtsgui/SConscript @@ -3,10 +3,10 @@ Import('env', 'os', 'glob', 'sys', 'hasQt', 'hasCollada', 'hasBreakpad', 'mainEn # For running Uic & Moc (below) def recursiveDirs(root) : - return filter((lambda a : a.rfind(".svn") == -1), [a[0] for a in os.walk(root)]) + return list(filter((lambda a : a.rfind(".svn") == -1), [a[0] for a in os.walk(root)])) -def unique(list) : - return dict.fromkeys(list).keys() +def unique(mylist) : + return list(dict.fromkeys(mylist).keys()) def scanFiles(dir, accept=["*.cpp"], reject=[]) : sources = [] @@ -15,15 +15,15 @@ def scanFiles(dir, accept=["*.cpp"], reject=[]) : for pattern in accept : sources+=glob.glob(path + "/" + pattern) for pattern in reject: - sources = filter((lambda a : a.rfind(pattern) == -1), sources) - sources = map((lambda a : os.path.basename(a)), sources) + sources = list(filter((lambda a : a.rfind(pattern) == -1), sources)) + sources = list(map((lambda a : os.path.basename(a)), sources)) return unique(sources) if hasQt: qtEnv = mainEnv.Clone() qtEnv.Append(CPPPATH=['#src/mtsgui']) - if qtEnv.has_key('QTINCLUDE'): + if 'QTINCLUDE' in qtEnv: qtEnv.Prepend(CPPPATH=qtEnv['QTINCLUDE']) qtEnv.EnableQt5Modules(['QtGui', 'QtWidgets', 'QtCore', 'QtOpenGL', 'QtXml', 'QtXmlPatterns', 'QtNetwork']) @@ -51,9 +51,9 @@ if hasQt: if hasCollada: qtSources += converter_objects - if env.has_key('COLLADALIBDIR'): + if 'COLLADALIBDIR' in env: qtEnv.Prepend(LIBPATH=env['COLLADALIBDIR']) - if env.has_key('COLLADALIB'): + if 'COLLADALIB' in env: qtEnv.Prepend(LIBS=env['COLLADALIB']) if sys.platform == 'darwin':