def find_dependencies(module): if not CYTHON_INSTALLED: return [] from Cython.Compiler.Version import version if split_version(version) < (0,9,6,13): return [] package_dir = os.path.join(get_base_dir(), PACKAGE_PATH) files = os.listdir(package_dir) pxd_files = [ os.path.join(PACKAGE_PATH, filename) for filename in files if filename.endswith('.pxd') ] if 'etree' in module: pxi_files = [ os.path.join(PACKAGE_PATH, filename) for filename in files if filename.endswith('.pxi') and 'objectpath' not in filename ] pxd_files = [ filename for filename in pxd_files if 'etreepublic' not in filename ] elif 'objectify' in module: pxi_files = [ os.path.join(PACKAGE_PATH, 'objectpath.pxi') ] else: pxi_files = [] return pxd_files + pxi_files
def find_dependencies(module): if not CYTHON_INSTALLED: return [] base_dir = get_base_dir() package_dir = os.path.join(base_dir, PACKAGE_PATH) includes_dir = os.path.join(base_dir, INCLUDE_PACKAGE_PATH) pxd_files = [ os.path.join(includes_dir, filename) for filename in os.listdir(includes_dir) if filename.endswith('.pxd') ] if 'etree' in module: pxi_files = [ os.path.join(PACKAGE_PATH, filename) for filename in os.listdir(package_dir) if filename.endswith('.pxi') and 'objectpath' not in filename ] pxd_files = [ filename for filename in pxd_files if 'etreepublic' not in filename ] elif 'objectify' in module: pxi_files = [os.path.join(PACKAGE_PATH, 'objectpath.pxi')] else: pxi_files = [] return pxd_files + pxi_files
def find_dependencies(module): if not CYTHON_INSTALLED: return [] from Cython.Compiler.Version import version if split_version(version) < (0, 9, 6, 13): return [] package_dir = os.path.join(get_base_dir(), PACKAGE_PATH) files = os.listdir(package_dir) pxd_files = [ os.path.join(PACKAGE_PATH, filename) for filename in files if filename.endswith('.pxd') ] if 'etree' in module: pxi_files = [ os.path.join(PACKAGE_PATH, filename) for filename in files if filename.endswith('.pxi') and 'objectpath' not in filename ] pxd_files = [ filename for filename in pxd_files if 'etreepublic' not in filename ] elif 'objectify' in module: pxi_files = [os.path.join(PACKAGE_PATH, 'objectpath.pxi')] else: pxi_files = [] return pxd_files + pxi_files
def find_dependencies(module): if not CYTHON_INSTALLED or "lxml.html" in module: return [] base_dir = get_base_dir() package_dir = os.path.join(base_dir, SOURCE_PATH, "lxml") includes_dir = os.path.join(base_dir, INCLUDE_PACKAGE_PATH) pxd_files = [ os.path.join(INCLUDE_PACKAGE_PATH, filename) for filename in os.listdir(includes_dir) if filename.endswith(".pxd") ] if module == "lxml.etree": pxi_files = [ os.path.join(SOURCE_PATH, "lxml", filename) for filename in os.listdir(package_dir) if filename.endswith(".pxi") and "objectpath" not in filename ] pxd_files = [ filename for filename in pxd_files if "etreepublic" not in filename ] elif module == "lxml.objectify": pxi_files = [os.path.join(SOURCE_PATH, "lxml", "objectpath.pxi")] else: pxi_files = pxd_files = [] return pxd_files + pxi_files
def find_dependencies(module): if not CYTHON_INSTALLED: return [] base_dir = get_base_dir() package_dir = os.path.join(base_dir, PACKAGE_PATH) includes_dir = os.path.join(base_dir, INCLUDE_PACKAGE_PATH) pxd_files = [ os.path.join(INCLUDE_PACKAGE_PATH, filename) for filename in os.listdir(includes_dir) if filename.endswith('.pxd') ] if 'etree' in module: pxi_files = [ os.path.join(PACKAGE_PATH, filename) for filename in os.listdir(package_dir) if filename.endswith('.pxi') and 'objectpath' not in filename ] pxd_files = [ filename for filename in pxd_files if 'etreepublic' not in filename ] elif 'objectify' in module: pxi_files = [os.path.join(PACKAGE_PATH, 'objectpath.pxi')] else: pxi_files = [] return pxd_files + pxi_files
def find_dependencies(module): if not CYTHON_INSTALLED: return [] base_dir = get_base_dir() package_dir = os.path.join(base_dir, SOURCE_PATH, 'pyxpdf') includes_dir = os.path.join(base_dir, INCLUDE_PACKAGE_PATH) pxd_files = [ os.path.join(INCLUDE_PACKAGE_PATH, filename) for filename in os.listdir(includes_dir) if filename.endswith('.pxd') ] if module == 'pyxpdf.xpdf': pxi_files = [ os.path.join(SOURCE_PATH, 'pyxpdf', filename) for filename in os.listdir(package_dir) if filename.endswith('.pxi') ] else: pxi_files = pxd_files = [] return pxd_files + pxi_files
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): from get_libxpdf import get_prebuilt_libxpdf get_prebuilt_libxpdf(OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) modules = EXT_MODULES + COMPILED_MODULES module_files = list( os.path.join(SOURCE_PATH, *module.split('.')) for module in modules) cpp_files_exist = [ os.path.exists(module + '.cpp') for module in module_files ] use_cython = True if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or not all(cpp_files_exist)): print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code from Cython.Compiler import Options Options.generate_cleanup_code = 3 Options.clear_to_none = False elif not OPTION_WITHOUT_CYTHON and not all(cpp_files_exist): for exists, module in zip(cpp_files_exist, module_files): if not exists: raise RuntimeError( "ERROR: Trying to build without Cython, but pre-generated '%s.cpp' " "is not available (pass --without-cython to ignore this error)." % module) else: if not all(cpp_files_exist): for exists, module in zip(cpp_files_exist, module_files): if not exists: print( "WARNING: Trying to build without Cython, but pre-generated " "'%s.cpp' is not available." % module) use_cython = False print("Building without Cython.") base_dir = get_base_dir() _include_dirs = _prefer_reldirs( base_dir, include_dirs(static_include_dirs) + [ SOURCE_PATH, INCLUDE_PACKAGE_PATH, ]) _library_dirs = _prefer_reldirs(base_dir, library_dirs(static_library_dirs)) _cflags = cflags(static_cflags) _ldflags = ['-isysroot', get_xcode_isysroot() ] if sys.platform == 'darwin' else None _define_macros = define_macros() _libraries = libraries() if _library_dirs: message = "Building against libxpdf in " print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS: from Cython.Compiler import Errors Errors.LEVEL = 0 cythonize_directives = { 'binding': True, } if OPTION_WITH_COVERAGE: cythonize_directives['linetrace'] = True result = [] for module, src_file in zip(modules, module_files): is_py = module in COMPILED_MODULES main_module_source = src_file + ('.cpp' if not use_cython else '.py' if is_py else '.pyx') result.append( Extension( module, sources=[main_module_source], depends=find_dependencies(module), extra_compile_args=_cflags, extra_link_args=None if is_py else _ldflags, extra_objects=None if is_py else static_binaries, define_macros=_define_macros, include_dirs=_include_dirs, library_dirs=None if is_py else _library_dirs, runtime_library_dirs=None if is_py else runtime_library_dirs, libraries=None if is_py else _libraries, )) if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB: for ext in result: ext.cython_gdb = True if CYTHON_INSTALLED and use_cython: # build .cpp files right now and convert Extension() objects from Cython.Build import cythonize result = cythonize(result, compiler_directives=cythonize_directives) return result
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): global XML2_CONFIG, XSLT_CONFIG if OPTION_BUILD_LIBXML2XSLT: from buildlibxml import build_libxml2xslt, get_prebuilt_libxml2xslt if sys.platform.startswith('win'): get_prebuilt_libxml2xslt(OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) else: XML2_CONFIG, XSLT_CONFIG = build_libxml2xslt( OPTION_DOWNLOAD_DIR, 'build/tmp', static_include_dirs, static_library_dirs, static_cflags, static_binaries, libiconv_version=OPTION_LIBICONV_VERSION, libxml2_version=OPTION_LIBXML2_VERSION, libxslt_version=OPTION_LIBXSLT_VERSION, multicore=OPTION_MULTICORE) if OPTION_WITHOUT_OBJECTIFY: modules = [entry for entry in EXT_MODULES if 'objectify' not in entry] else: modules = EXT_MODULES c_files_exist = [ os.path.exists('%s%s.c' % (PACKAGE_PATH, module)) for module in modules ] if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or False in c_files_exist): source_extension = ".pyx" print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code from Cython.Compiler import Options Options.generate_cleanup_code = 3 Options.clear_to_none = False elif not OPTION_WITHOUT_CYTHON and False in c_files_exist: for exists, module in zip(c_files_exist, modules): if not exists: raise RuntimeError( "ERROR: Trying to build without Cython, but pre-generated '%s%s.c' " "is not available (pass --without-cython to ignore this error)." % (PACKAGE_PATH, module)) else: if False in c_files_exist: for exists, module in zip(c_files_exist, modules): if not exists: print( "WARNING: Trying to build without Cython, but pre-generated " "'%s%s.c' is not available." % (PACKAGE_PATH, module)) source_extension = ".c" print("Building without Cython.") lib_versions = get_library_versions() versions_ok = True if lib_versions[0]: print("Using build configuration of libxml2 %s and libxslt %s" % lib_versions) versions_ok = check_min_version(lib_versions[0], (2, 7, 0), 'libxml2') else: print("Using build configuration of libxslt %s" % lib_versions[1]) versions_ok |= check_min_version(lib_versions[1], (1, 1, 23), 'libxslt') if not versions_ok: raise RuntimeError("Dependency missing") _include_dirs = include_dirs(static_include_dirs) _library_dirs = library_dirs(static_library_dirs) _cflags = cflags(static_cflags) _define_macros = define_macros() _libraries = libraries() _include_dirs.append(os.path.join(get_base_dir(), INCLUDE_PACKAGE_PATH)) if _library_dirs: message = "Building against libxml2/libxslt in " if len(_library_dirs) > 1: print(message + "one of the following directories:") for dir in _library_dirs: print(" " + dir) else: print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS: from Cython.Compiler import Errors Errors.LEVEL = 0 result = [] for module in modules: main_module_source = PACKAGE_PATH + module + source_extension result.append( Extension( module, sources=[main_module_source], depends=find_dependencies(module), extra_compile_args=_cflags, extra_objects=static_binaries, define_macros=_define_macros, include_dirs=_include_dirs, library_dirs=_library_dirs, runtime_library_dirs=runtime_library_dirs, libraries=_libraries, )) if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB: for ext in result: ext.cython_gdb = True if CYTHON_INSTALLED and source_extension == '.pyx': # build .c files right now and convert Extension() objects from Cython.Build import cythonize result = cythonize(result) return result
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): global XML2_CONFIG, XSLT_CONFIG if OPTION_BUILD_LIBXML2XSLT: from buildlibxml import build_libxml2xslt, get_prebuilt_libxml2xslt if sys.platform.startswith('win'): get_prebuilt_libxml2xslt( OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) else: XML2_CONFIG, XSLT_CONFIG = build_libxml2xslt( OPTION_DOWNLOAD_DIR, 'build/tmp', static_include_dirs, static_library_dirs, static_cflags, static_binaries, libiconv_version=OPTION_LIBICONV_VERSION, libxml2_version=OPTION_LIBXML2_VERSION, libxslt_version=OPTION_LIBXSLT_VERSION, multicore=OPTION_MULTICORE) if OPTION_WITHOUT_OBJECTIFY: modules = [ entry for entry in EXT_MODULES if 'objectify' not in entry ] else: modules = EXT_MODULES c_files_exist = [ os.path.exists('%s%s.c' % (PACKAGE_PATH, module)) for module in modules ] if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or False in c_files_exist): source_extension = ".pyx" print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code from Cython.Compiler import Options Options.generate_cleanup_code = 3 elif not OPTION_WITHOUT_CYTHON and False in c_files_exist: for exists, module in zip(c_files_exist, modules): if not exists: raise RuntimeError( "ERROR: Trying to build without Cython, but pre-generated '%s%s.c' " "is not available (pass --without-cython to ignore this error)." % ( PACKAGE_PATH, module)) else: if False in c_files_exist: for exists, module in zip(c_files_exist, modules): if not exists: print("WARNING: Trying to build without Cython, but pre-generated " "'%s%s.c' is not available." % (PACKAGE_PATH, module)) source_extension = ".c" print("Building without Cython.") lib_versions = get_library_versions() if lib_versions[0]: print("Using build configuration of libxml2 %s and libxslt %s" % lib_versions) else: print("Using build configuration of libxslt %s" % lib_versions[1]) _include_dirs = include_dirs(static_include_dirs) _library_dirs = library_dirs(static_library_dirs) _cflags = cflags(static_cflags) _define_macros = define_macros() _libraries = libraries() _include_dirs.append(os.path.join(get_base_dir(), INCLUDE_PACKAGE_PATH)) if _library_dirs: message = "Building against libxml2/libxslt in " if len(_library_dirs) > 1: print(message + "one of the following directories:") for dir in _library_dirs: print(" " + dir) else: print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS: from Cython.Compiler import Errors Errors.LEVEL = 0 result = [] for module in modules: main_module_source = PACKAGE_PATH + module + source_extension result.append( Extension( module, sources = [main_module_source], depends = find_dependencies(module), extra_compile_args = _cflags, extra_objects = static_binaries, define_macros = _define_macros, include_dirs = _include_dirs, library_dirs = _library_dirs, runtime_library_dirs = runtime_library_dirs, libraries = _libraries, )) if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB: for ext in result: ext.cython_gdb = True return result
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): global XML2_CONFIG, XSLT_CONFIG if OPTION_BUILD_LIBXML2XSLT: from buildlibxml import build_libxml2xslt, get_prebuilt_libxml2xslt if sys.platform.startswith('win'): get_prebuilt_libxml2xslt( OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) else: XML2_CONFIG, XSLT_CONFIG = build_libxml2xslt( OPTION_DOWNLOAD_DIR, 'build/tmp', static_include_dirs, static_library_dirs, static_cflags, static_binaries, libiconv_version=OPTION_LIBICONV_VERSION, libxml2_version=OPTION_LIBXML2_VERSION, libxslt_version=OPTION_LIBXSLT_VERSION, zlib_version=OPTION_ZLIB_VERSION, multicore=OPTION_MULTICORE) modules = EXT_MODULES + COMPILED_MODULES if OPTION_WITHOUT_OBJECTIFY: modules = [entry for entry in modules if 'objectify' not in entry] module_files = list(os.path.join(SOURCE_PATH, *module.split('.')) for module in modules) c_files_exist = [os.path.exists(module + '.c') for module in module_files] use_cython = True if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or not all(c_files_exist)): print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code from Cython.Compiler import Options Options.generate_cleanup_code = 3 Options.clear_to_none = False elif not OPTION_WITHOUT_CYTHON and not all(c_files_exist): for exists, module in zip(c_files_exist, module_files): if not exists: raise RuntimeError( "ERROR: Trying to build without Cython, but pre-generated '%s.c' " "is not available (pass --without-cython to ignore this error)." % module) else: if not all(c_files_exist): for exists, module in zip(c_files_exist, module_files): if not exists: print("WARNING: Trying to build without Cython, but pre-generated " "'%s.c' is not available." % module) use_cython = False print("Building without Cython.") if not check_build_dependencies(): raise RuntimeError("Dependency missing") base_dir = get_base_dir() _include_dirs = _prefer_reldirs( base_dir, include_dirs(static_include_dirs) + [ SOURCE_PATH, INCLUDE_PACKAGE_PATH, ]) _library_dirs = _prefer_reldirs(base_dir, library_dirs(static_library_dirs)) _cflags = cflags(static_cflags) _ldflags = ['-isysroot', get_xcode_isysroot()] if sys.platform == 'darwin' else None _define_macros = define_macros() _libraries = libraries() if _library_dirs: message = "Building against libxml2/libxslt in " if len(_library_dirs) > 1: print(message + "one of the following directories:") for dir in _library_dirs: print(" " + dir) else: print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS: from Cython.Compiler import Errors Errors.LEVEL = 0 cythonize_directives = { 'binding': True, } if OPTION_WITH_COVERAGE: cythonize_directives['linetrace'] = True result = [] for module, src_file in zip(modules, module_files): is_py = module in COMPILED_MODULES main_module_source = src_file + ( '.c' if not use_cython else '.py' if is_py else '.pyx') result.append( Extension( module, sources = [main_module_source], depends = find_dependencies(module), extra_compile_args = _cflags, extra_link_args = None if is_py else _ldflags, extra_objects = None if is_py else static_binaries, define_macros = _define_macros, include_dirs = _include_dirs, library_dirs = None if is_py else _library_dirs, runtime_library_dirs = None if is_py else runtime_library_dirs, libraries = None if is_py else _libraries, )) if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB: for ext in result: ext.cython_gdb = True if CYTHON_INSTALLED and use_cython: # build .c files right now and convert Extension() objects from Cython.Build import cythonize result = cythonize(result, compiler_directives=cythonize_directives) # for backwards compatibility reasons, provide "etree[_api].h" also as "lxml.etree[_api].h" for header_filename in HEADER_FILES: src_file = os.path.join(SOURCE_PATH, 'lxml', header_filename) dst_file = os.path.join(SOURCE_PATH, 'lxml', 'lxml.' + header_filename) if not os.path.exists(src_file): continue if os.path.exists(dst_file) and os.path.getmtime(dst_file) >= os.path.getmtime(src_file): continue with io.open(src_file, 'r', encoding='iso8859-1') as f: content = f.read() for filename in HEADER_FILES: content = content.replace('"%s"' % filename, '"lxml.%s"' % filename) with io.open(dst_file, 'w', encoding='iso8859-1') as f: f.write(content) return result
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): global XML2_CONFIG, XSLT_CONFIG if OPTION_BUILD_LIBXML2XSLT: from buildlibxml import build_libxml2xslt, get_prebuilt_libxml2xslt if sys.platform.startswith('win'): get_prebuilt_libxml2xslt( OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) else: XML2_CONFIG, XSLT_CONFIG = build_libxml2xslt( OPTION_DOWNLOAD_DIR, 'build/tmp', static_include_dirs, static_library_dirs, static_cflags, static_binaries, libiconv_version=OPTION_LIBICONV_VERSION, libxml2_version=OPTION_LIBXML2_VERSION, libxslt_version=OPTION_LIBXSLT_VERSION, multicore=OPTION_MULTICORE) if CYTHON_INSTALLED: source_extension = ".pyx" print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code for globals, but not for etree types imported in objectify from Cython.Compiler import Options Options.generate_cleanup_code = 2 else: source_extension = ".c" if not os.path.exists(PACKAGE_PATH + 'lxml.etree.c'): print ("WARNING: Trying to build without Cython, but pre-generated " "'%slxml.etree.c' does not seem to be available." % PACKAGE_PATH) else: print ("Building without Cython.") if OPTION_WITHOUT_OBJECTIFY: modules = [ entry for entry in EXT_MODULES if 'objectify' not in entry ] else: modules = EXT_MODULES lib_versions = get_library_versions() if lib_versions[0]: print("Using build configuration of libxml2 %s and libxslt %s" % lib_versions) else: print("Using build configuration of libxslt %s" % lib_versions[1]) _include_dirs = include_dirs(static_include_dirs) _library_dirs = library_dirs(static_library_dirs) _cflags = cflags(static_cflags) _define_macros = define_macros() _libraries = libraries() _include_dirs.append(os.path.join(get_base_dir(), INCLUDE_PACKAGE_PATH)) if _library_dirs: message = "Building against libxml2/libxslt in " if len(_library_dirs) > 1: print(message + "one of the following directories:") for dir in _library_dirs: print(" " + dir) else: print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if OPTION_SHOW_WARNINGS: if CYTHON_INSTALLED: from Cython.Compiler import Errors Errors.LEVEL = 0 else: _cflags = ['-w'] + _cflags result = [] for module in modules: main_module_source = PACKAGE_PATH + module + source_extension result.append( Extension( module, sources = [main_module_source], depends = find_dependencies(module), extra_compile_args = _cflags, extra_objects = static_binaries, define_macros = _define_macros, include_dirs = _include_dirs, library_dirs = _library_dirs, runtime_library_dirs = runtime_library_dirs, libraries = _libraries, )) return result
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): global XML2_CONFIG, XSLT_CONFIG if OPTION_BUILD_LIBXML2XSLT: from buildlibxml import build_libxml2xslt, get_prebuilt_libxml2xslt if sys.platform.startswith('win'): get_prebuilt_libxml2xslt(OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) else: XML2_CONFIG, XSLT_CONFIG = build_libxml2xslt( OPTION_DOWNLOAD_DIR, 'build/tmp', static_include_dirs, static_library_dirs, static_cflags, static_binaries, libiconv_version=OPTION_LIBICONV_VERSION, libxml2_version=OPTION_LIBXML2_VERSION, libxslt_version=OPTION_LIBXSLT_VERSION, multicore=OPTION_MULTICORE) if CYTHON_INSTALLED: source_extension = ".pyx" print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code from Cython.Compiler import Options Options.generate_cleanup_code = 3 else: source_extension = ".c" if not os.path.exists(PACKAGE_PATH + 'lxml.etree.c'): print("WARNING: Trying to build without Cython, but pre-generated " "'%slxml.etree.c' does not seem to be available." % PACKAGE_PATH) else: print("Building without Cython.") if OPTION_WITHOUT_OBJECTIFY: modules = [entry for entry in EXT_MODULES if 'objectify' not in entry] else: modules = EXT_MODULES lib_versions = get_library_versions() if lib_versions[0]: print("Using build configuration of libxml2 %s and libxslt %s" % lib_versions) else: print("Using build configuration of libxslt %s" % lib_versions[1]) _include_dirs = include_dirs(static_include_dirs) _library_dirs = library_dirs(static_library_dirs) _cflags = cflags(static_cflags) _define_macros = define_macros() _libraries = libraries() _include_dirs.append(os.path.join(get_base_dir(), INCLUDE_PACKAGE_PATH)) if _library_dirs: message = "Building against libxml2/libxslt in " if len(_library_dirs) > 1: print(message + "one of the following directories:") for dir in _library_dirs: print(" " + dir) else: print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS: from Cython.Compiler import Errors Errors.LEVEL = 0 result = [] for module in modules: main_module_source = PACKAGE_PATH + module + source_extension result.append( Extension( module, sources=[main_module_source], depends=find_dependencies(module), extra_compile_args=_cflags, extra_objects=static_binaries, define_macros=_define_macros, include_dirs=_include_dirs, library_dirs=_library_dirs, runtime_library_dirs=runtime_library_dirs, libraries=_libraries, )) if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB: for ext in result: ext.cython_gdb = True return result
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): global XML2_CONFIG, XSLT_CONFIG if OPTION_BUILD_LIBXML2XSLT: from buildlibxml import build_libxml2xslt, get_prebuilt_libxml2xslt if sys.platform.startswith('win'): get_prebuilt_libxml2xslt( OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) else: XML2_CONFIG, XSLT_CONFIG = build_libxml2xslt( OPTION_DOWNLOAD_DIR, 'build/tmp', static_include_dirs, static_library_dirs, static_cflags, static_binaries, libiconv_version=OPTION_LIBICONV_VERSION, libxml2_version=OPTION_LIBXML2_VERSION, libxslt_version=OPTION_LIBXSLT_VERSION, multicore=OPTION_MULTICORE) modules = EXT_MODULES if OPTION_WITHOUT_OBJECTIFY: modules = [entry for entry in modules if 'objectify' not in entry] c_files_exist = [os.path.exists('%s%s.c' % (PACKAGE_PATH, module)) for module in modules] source_extension = ".pyx" if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or not all(c_files_exist)): print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code from Cython.Compiler import Options Options.generate_cleanup_code = 3 Options.clear_to_none = False elif not OPTION_WITHOUT_CYTHON and not all(c_files_exist): for exists, module in zip(c_files_exist, modules): if not exists: raise RuntimeError( "ERROR: Trying to build without Cython, but pre-generated '%s%s.c' " "is not available (pass --without-cython to ignore this error)." % ( PACKAGE_PATH, module)) else: if not all(c_files_exist): for exists, module in zip(c_files_exist, modules): if not exists: print("WARNING: Trying to build without Cython, but pre-generated " "'%s%s.c' is not available." % (PACKAGE_PATH, module)) source_extension = ".c" print("Building without Cython.") lib_versions = get_library_versions() versions_ok = True if lib_versions[0]: print("Using build configuration of libxml2 %s and libxslt %s" % lib_versions) versions_ok = check_min_version(lib_versions[0], (2, 7, 0), 'libxml2') else: print("Using build configuration of libxslt %s" % lib_versions[1]) versions_ok |= check_min_version(lib_versions[1], (1, 1, 23), 'libxslt') if not versions_ok: raise RuntimeError("Dependency missing") base_dir = get_base_dir() _include_dirs = _prefer_reldirs( base_dir, include_dirs(static_include_dirs) + [INCLUDE_PACKAGE_PATH]) _library_dirs = _prefer_reldirs(base_dir, library_dirs(static_library_dirs)) _cflags = cflags(static_cflags) _define_macros = define_macros() _libraries = libraries() if _library_dirs: message = "Building against libxml2/libxslt in " if len(_library_dirs) > 1: print(message + "one of the following directories:") for dir in _library_dirs: print(" " + dir) else: print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS: from Cython.Compiler import Errors Errors.LEVEL = 0 cythonize_options = {} if OPTION_WITH_COVERAGE: cythonize_options['compiler_directives'] = {'linetrace': True} result = [] for module in modules: main_module_source = PACKAGE_PATH + module + source_extension result.append( Extension( module, sources = [main_module_source], depends = find_dependencies(module), extra_compile_args = _cflags, extra_objects = static_binaries, define_macros = _define_macros, include_dirs = _include_dirs, library_dirs = _library_dirs, runtime_library_dirs = runtime_library_dirs, libraries = _libraries, )) if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB: for ext in result: ext.cython_gdb = True if CYTHON_INSTALLED and source_extension == '.pyx': # build .c files right now and convert Extension() objects from Cython.Build import cythonize result = cythonize(result, **cythonize_options) return result
def ext_modules(static_include_dirs, static_library_dirs, static_cflags, static_binaries): from get_libxpdf import build_libxpdf, get_prebuilt_libxpdf if OPTION_BUILD_LIBXPDF: btype = "Release" if OPTION_DEBUG_GCC: btype = "Debug" libs = build_libxpdf( OPTION_DOWNLOAD_DIR, "build/tmp", static_include_dirs, static_library_dirs, static_cflags, static_binaries, libxpdf_version=OPTION_LIBXPDF_VERSION, build_type=btype, multicore=OPTION_MULTICORE, ) if not libs: sys.exit(1) else: get_prebuilt_libxpdf(OPTION_DOWNLOAD_DIR, static_include_dirs, static_library_dirs) modules = EXT_MODULES + COMPILED_MODULES module_files = list( os.path.join(SOURCE_PATH, *module.split(".")) for module in modules) cpp_files_exist = [ os.path.exists(module + ".cpp") for module in module_files ] use_cython = True if CYTHON_INSTALLED and (OPTION_WITH_CYTHON or not all(cpp_files_exist)): print("Building with Cython %s." % Cython.Compiler.Version.version) # generate module cleanup code from Cython.Compiler import Options Options.generate_cleanup_code = 3 Options.clear_to_none = False elif not OPTION_WITHOUT_CYTHON and not all(cpp_files_exist): for exists, module in zip(cpp_files_exist, module_files): if not exists: raise RuntimeError( "ERROR: Trying to build without Cython, but pre-generated '%s.cpp' " "is not available (pass --without-cython to ignore this error)." % module) else: if not all(cpp_files_exist): for exists, module in zip(cpp_files_exist, module_files): if not exists: print( "WARNING: Trying to build without Cython, but pre-generated " "'%s.cpp' is not available." % module) use_cython = False print("Building without Cython.") base_dir = get_base_dir() _include_dirs = _prefer_reldirs( base_dir, include_dirs(static_include_dirs) + [ SOURCE_PATH, INCLUDE_PACKAGE_PATH, EXT_CXX_INCLUDE, ], ) _library_dirs = _prefer_reldirs(base_dir, library_dirs(static_library_dirs)) _cflags = cflags(static_cflags) _ldflags = ["-isysroot", get_xcode_isysroot() ] if sys.platform == "darwin" else None _define_macros = define_macros() _libraries = libraries() if _library_dirs: message = "Building against libxpdf in " print(message + "the following directory: " + _library_dirs[0]) if OPTION_AUTO_RPATH: runtime_library_dirs = _library_dirs else: runtime_library_dirs = [] if CYTHON_INSTALLED and OPTION_SHOW_WARNINGS: from Cython.Compiler import Errors Errors.LEVEL = 0 cythonize_directives = { "binding": True, } if OPTION_WITH_COVERAGE: cythonize_directives["linetrace"] = True if OPTION_WITH_SIGNATURE: cythonize_directives["embedsignature"] = True result = [] for module, src_file in zip(modules, module_files): is_py = module in COMPILED_MODULES main_module_source = src_file + (".cpp" if not use_cython else ".py" if is_py else ".pyx") result.append( Extension( module, sources=[main_module_source] + EXT_MODULES_EXTRA_SRC.get(module, []), depends=find_dependencies(module), extra_compile_args=_cflags, extra_link_args=None if is_py else _ldflags, extra_objects=None if is_py else static_binaries, define_macros=_define_macros, include_dirs=_include_dirs, library_dirs=None if is_py else _library_dirs, runtime_library_dirs=None if is_py else runtime_library_dirs, libraries=None if is_py else _libraries, )) gdb = False if CYTHON_INSTALLED and OPTION_WITH_CYTHON_GDB: gdb = True if CYTHON_INSTALLED and use_cython: # build .cpp files right now and convert Extension() objects from Cython.Build import cythonize result = cythonize(result, compiler_directives=cythonize_directives, gdb_debug=gdb) return result