def run(self): if platform.mac_ver()[0] < '10.7.': cc = [get_config_var('CC')] env = dict(os.environ) env['MACOSX_DEPLOYMENT_TARGET'] = get_config_var('MACOSX_DEPLOYMENT_TARGET') else: cc = ['xcrun', 'clang'] env = dict(os.environ) env['MACOSX_DEPLOYMENT_TARGET'] = get_config_var('MACOSX_DEPLOYMENT_TARGET') if not os.path.exists('lib'): os.mkdir('lib') cflags = get_config_var('CFLAGS') arch_flags = sum([shlex.split(x) for x in re.findall('-arch\s+\S+', cflags)], []) root_flags = sum([shlex.split(x) for x in re.findall('-isysroot\s+\S+', cflags)], []) cmd = cc + arch_flags + root_flags + ['-dynamiclib', '-o', os.path.abspath('lib/libshared.1.dylib'), 'src/sharedlib.c'] subprocess.check_call(cmd, env=env) if os.path.exists('lib/libshared.dylib'): os.unlink('lib/libshared.dylib') os.symlink('libshared.1.dylib', 'lib/libshared.dylib') if not os.path.exists('lib/stash'): os.makedirs('lib/stash') if os.path.exists('lib/libhalf.dylib'): os.unlink('lib/libhalf.dylib') cmd = cc + arch_flags + root_flags + ['-dynamiclib', '-o', os.path.abspath('lib/libhalf.dylib'), 'src/sharedlib.c'] subprocess.check_call(cmd, env=env) os.rename('lib/libhalf.dylib', 'lib/stash/libhalf.dylib') os.symlink('stash/libhalf.dylib', 'lib/libhalf.dylib')
def get_link(): """Get link flags needed for linking C/Fortran code with the PICO library.""" return ' '.join(['-L%s -lpico '%os.path.dirname(os.path.abspath(__file__)), '-L%s/lib'%PREFIX.strip()] + get_config_var('LIBS').split() + get_config_var('SYSLIBS').split() + ['-lpython' + get_config_var('VERSION')])
def pythonLinkData(): # @TODO Fix to work with static builds of Python libdir = sysconfig.get_config_var('LIBDIR') if libdir is None: libdir = os.path.abspath(os.path.join( sysconfig.get_config_var('LIBDEST'), "..", "libs")) version = pythonVersion() version_no_dots = version.replace('.', '') flags = {} flags['libdir'] = libdir if sys.platform == 'win32': suffix = '_d' if any([tup[0].endswith('_d.pyd') for tup in imp.get_suffixes()]) else '' flags['lib'] = 'python{}{}'.format(version_no_dots, suffix) elif sys.platform == 'darwin': flags['lib'] = 'python{}'.format(version) # Linux and anything else else: if sys.version_info[0] < 3: suffix = '_d' if any([tup[0].endswith('_d.so') for tup in imp.get_suffixes()]) else '' flags['lib'] = 'python{}{}'.format(version, suffix) else: flags['lib'] = 'python{}{}'.format(version, sys.abiflags) return flags
def buildKeywordDictionary(): from distutils.core import Extension setupKeywords = {} setupKeywords["name"] = "yank" setupKeywords["version"] = "0.1.0" setupKeywords["author"] = "John D. Chodera, Kyle A. Beauchamp, Michael R. Shirts, and Kai Wang" setupKeywords["author_email"] = "[email protected], [email protected]" setupKeywords["license"] = "LGPL 3.0" setupKeywords["url"] = "http://github.com/choderalab/yank" setupKeywords["download_url"] = "http://github.com/choderalab/yank" setupKeywords["packages"] = ['yank'] setupKeywords["package_dir"] = {'yank' : 'yank'} setupKeywords["data_files"] = [] #setupKeywords["ext_modules"] = [CMBAR] #setupKeywords["test_suite"] = "tests" # requires we migrate to setuptools setupKeywords["platforms"] = ["Linux", "Mac OS X", "Windows"] setupKeywords["description"] = "Testbed for GPU-accelerated alchemical binding free energy calculations." setupKeywords["requires"] = ["numpy", "scipy", "pandas", "nose", "pymbar"] setupKeywords["long_description"] = """ YANK is a testbed for experimenting with algorithms for the efficient computation of small molecule binding free energies to biomolecular targets using alchemical methods. YANK is built on OpenMM, the API for molecular simulation, and uses its GPU-accelerated library implementation for hardware acceleration. """ outputString="" firstTab = 40 secondTab = 60 for key in sorted( setupKeywords.iterkeys() ): value = setupKeywords[key] outputString += key.rjust(firstTab) + str( value ).rjust(secondTab) + "\n" print("%s" % outputString) get_config_var(None) # this line is necessary to fix the imports Mac OS X return setupKeywords
def _get_lib_name(lib, add_extension_suffix): """ Helper function to get an architecture and Python version specific library filename. :type add_extension_suffix: bool :param add_extension_suffix: NumPy distutils adds a suffix to the filename we specify to build internally (as specified by Python builtin `sysconfig.get_config_var("EXT_SUFFIX")`. So when loading the file we have to add this suffix, but not during building. """ # our custom defined part of the extension filename libname = "lib%s_%s_%s_py%s" % ( lib, platform.system(), platform.architecture()[0], ''.join([str(i) for i in platform.python_version_tuple()[:2]])) libname = cleanse_pymodule_filename(libname) # NumPy distutils adds extension suffix by itself during build (#771, #755) if add_extension_suffix: # append any extension suffix defined by Python for current platform ext_suffix = sysconfig.get_config_var("EXT_SUFFIX") # in principle "EXT_SUFFIX" is what we want. # "SO" seems to be deprecated on newer python # but: older python seems to have empty "EXT_SUFFIX", so we fall back if not ext_suffix: try: ext_suffix = sysconfig.get_config_var("SO") except Exception as e: msg = ("Empty 'EXT_SUFFIX' encountered while building CDLL " "filename and fallback to 'SO' variable failed " "(%s)." % str(e)) warnings.warn(msg) pass if ext_suffix: libname = libname + ext_suffix return libname
def _patch(self): if self._patched: return LOCALMODLIBS = "" LINKFORSHARED = sysconfig.get_config_var("LINKFORSHARED") if LINKFORSHARED and sys.platform != 'darwin': linker = " ".join([sysconfig.get_config_var(x) for x in 'LINKCC LDFLAGS LINKFORSHARED'.split()]) if '-Xlinker' in linker: linker += ' -Xlinker -zmuldefs' linker += ' -Xlinker --disable-new-dtags' LOCALMODLIBS = sysconfig.get_config_var("LOCALMODLIBS") or "" self.compiler.set_executables(linker_exe=linker) def hacked(*args, **kwargs): for x in ('export_symbols', 'build_temp'): try: del kwargs[x] except KeyError: pass if LOCALMODLIBS: kwargs["extra_postargs"] = LOCALMODLIBS.split() retval = self.compiler.link_executable(*args, **kwargs) maybe_strip(args[1]) return retval self.compiler.link_shared_object = hacked self._patched = True
def get_ext_filename(self, ext_name): r"""Convert the name of an extension (eg. "foo.bar") into the name of the file from which it will be loaded (eg. "foo/bar.so", or "foo\bar.pyd"). """ from distutils.sysconfig import get_config_var ext_path = string.split(ext_name, ".") # OS/2 has an 8 character module (extension) limit :-( if os.name == "os2": ext_path[len(ext_path) - 1] = ext_path[len(ext_path) - 1][:8] # PyPy tweak: first try to get the C extension suffix from # 'imp'. If it fails we fall back to the 'SO' config var, like # the previous version of this code did. This should work for # CPython too. The point is that on PyPy with cpyext, the # config var 'SO' is just ".so" but we want to return # ".pypy-VERSION.so" instead. Note a further tweak for cffi's # embedding mode: if EXT_SUFFIX is also defined, use that # directly. so_ext = get_config_var("EXT_SUFFIX") if so_ext is None: so_ext = _get_c_extension_suffix() if so_ext is None: so_ext = get_config_var("SO") # fall-back # extensions in debug_mode are named 'module_d.pyd' under windows if os.name == "nt" and self.debug: so_ext = "_d.pyd" return os.path.join(*ext_path) + so_ext
def _get_cmake_ext_path(self, name): # This is the name of the arrow C-extension suffix = sysconfig.get_config_var('EXT_SUFFIX') if suffix is None: suffix = sysconfig.get_config_var('SO') filename = name + suffix return pjoin(self._get_build_dir(), filename)
def get_ext_filename(self, ext_name): filename = _build_ext.get_ext_filename(self, ext_name) so_ext = get_config_var('SO') soabi = get_config_var('SOABI') if soabi and os.uname()[0] == 'Darwin': filename = "%s.%s%s" % (filename[:-len(so_ext)], soabi, so_ext) return filename
def get_ext_filename(self, ext_name): filename = _build_ext.get_ext_filename(self, ext_name) so_ext = get_config_var('SO') soabi = get_config_var('SOABI') if sys.version_info < (3, 5) and soabi and platform == 'Darwin': filename = "%s.%s%s" % (filename[:-len(so_ext)], soabi, so_ext) return filename
def add_optimization(self): c = self.compiler.compiler_type if c == 'msvc': for e in self.extensions: e.extra_compile_args = MSVC_OPTIMIZE_COMPILE_ARGS return True if c in ('unix','cygwin','mingw32'): if c == 'unix': cc = sysconfig.get_config_var('CXX') if cc is None: self.warn('the environment variable "CXX" is not set so ' + "I'll just assume the compiler is GCC or Clang and " + "hope for the best") else: cc = os.path.basename(cc) if not ('gcc' in cc or 'g++' in cc or 'clang' in cc): return False py_debug = sysconfig.get_config_var('Py_DEBUG') == 1 for e in self.extensions: e.extra_compile_args = GCC_EXTRA_COMPILE_ARGS[:] if not (py_debug and self.debug): e.extra_compile_args += GCC_OPTIMIZE_COMPILE_ARGS if not self.debug: e.extra_link_args = ['-s'] # this is normally defined automatically, but not when # using Mingw32 under windows e.define_macros.append(('NDEBUG',1)) return True return False
def _build_python_obj(target, source, CFLAGS, CPPPATH): includes = ["-I" + path for path in CPPPATH] if os.path.dirname(source) != '': includes.append("-I" + os.path.dirname(source)) includes.append("-I" + get_config_var("CONFINCLUDEPY")) # Check for header dependencies mem = Mem.instance() mem.add_deps([nodes.File(f) for f in make_depends(target, [ source ], CFLAGS=CFLAGS, CPPPATH=CPPPATH, inc_dirs=includes ) ]) cargs = get_config_var('BLDSHARED').split(' ') args = util.convert_cmd([cargs[0]] + cargs[1:] + CFLAGS + includes + target_inc_flag(target, [ source ]) + list(includes) + ["-c", "-o", target] + [ source ]) util.ensure_file_dir(target) if util.run("GCC (Python Extension)", source, args) != 0: Mem.instance().fail() return [ nodes.File(target) ]
def prepare(abs_path_c_files): modules = [] for c_file in abs_path_c_files: relfile = os.path.relpath(c_file, src_dir) filename = os.path.splitext(relfile)[0] extName = filename.replace(os.path.sep, ".") extension = Extension(extName, sources=[c_file], define_macros=[('PYREX_WITHOUT_ASSERTIONS', None)] # ignore asserts in code ) modules.append(extension) if platform.system() != 'Windows': cflags = sysconfig.get_config_var('CFLAGS') opt = sysconfig.get_config_var('OPT') sysconfig._config_vars['CFLAGS'] = cflags.replace(' -g ', ' ') sysconfig._config_vars['OPT'] = opt.replace(' -g ', ' ') if platform.system() == 'Linux': ldshared = sysconfig.get_config_var('LDSHARED') sysconfig._config_vars['LDSHARED'] = ldshared.replace(' -g ', ' ') elif platform.system() == 'Darwin': #-mno-fused-madd is a deprecated flag that now causes a hard error # but distuitls still keeps it # it was used to disable the generation of the fused multiply/add instruction for flag, flags_line in sysconfig._config_vars.iteritems(): if ' -g' in str(flags_line): sysconfig._config_vars[flag] = flags_line.replace(' -g', '') for key in ['CONFIG_ARGS', 'LIBTOOL', 'PY_CFLAGS', 'CFLAGS']: value = sysconfig.get_config_var(key) if value: sysconfig._config_vars[key] = value.replace('-mno-fused-madd', '') sysconfig._config_vars[key] = value.replace('-DENABLE_DTRACE', '') return modules
def compileTestCase(self): libdir = os.path.join('build', 'temp.%s-%d.%d'%(get_platform(), sys.version_info[0], sys.version_info[1])) if hasattr(sys, 'gettotalrefcount'): libdir += "-pydebug" libdir = os.path.join(libdir, 'libffi-src') libffiobjects = self.object_files(libdir) if self.filename.endswith('.m'): extra_link = '-framework Foundation' else: extra_link = '' commandline='MACOSX_DEPLPOYMENT_TARGET=%s %s %s -g -DMACOSX -Ilibffi-src/include -Ilibffi-src/powerpc -o /tmp/test.bin %s %s %s 2>&1'%( get_config_var('MACOSX_DEPLOYMENT_TARGET'), get_config_var('CC'), get_config_var('CFLAGS'), self.filename, ' '.join(libffiobjects), extra_link) fp = os.popen(commandline) data = fp.read() xit = fp.close() if xit != None: self.fail("Compile failed[%s]:\n%s"%(xit, data))
def get_python_lib_dirs(): lib_dirs = [] if os.name == 'nt': lib_dirs.append(os.path.join(sys.exec_prefix, 'libs')) elif os.name == 'os2': lib_dirs.append(os.path.join(sys.exec_prefix, 'Config')) if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': if sys.excutable.startswith(os.path.join(sys.exec_prefix, "bin")): lib_dirs.append(os.path.join(sys.prefix, "lib", "python" + sysconfig.get_python_version(), "config")) else: lib_dirs.append(".") sysconfig.get_config_var('Py_ENABLE_SHARED') if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu') or sys.platform.startswith('sunos')) and sysconfig.get_config_var('Py_ENABLE_SHARED')): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions lib_dirs.append(sysconfig.get_config_var('LIBDIR')) else: # building python standard extensions lib_dirs.append('.') return lib_dirs
def prep_postgres( prepped, args ): pg_version = args['version'] pg_srcdir = os.path.join( os.getcwd(), "postgresql-%s" % pg_version ) # set up environment os.environ['CC'] = get_config_var('CC') os.environ['CFLAGS'] = get_config_var('CFLAGS') os.environ['LDFLAGS'] = get_config_var('LDFLAGS') if '-fPIC' not in os.environ['CFLAGS']: os.environ['CFLAGS'] += ' -fPIC' # run configure run( "./configure --prefix=%s/postgres --disable-dependency-tracking --enable-static --disable-shared --without-readline --with-thread-safety" % os.getcwd(), os.path.join( os.getcwd(), "postgresql-%s" % pg_version ), "Configuring postgres (./configure)" ) # compile run( "make ../../src/include/utils/fmgroids.h", os.path.join( pg_srcdir, 'src', 'backend' ), "Compiling fmgroids.h (cd src/backend; make ../../src/include/utils/fmgroids.h)" ) run( "make", os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Compiling libpq (cd src/interfaces/libpq; make)" ) run( "make", os.path.join( pg_srcdir, 'src', 'bin', 'pg_config' ), "Compiling pg_config (cd src/bin/pg_config; make)" ) # install run( "make install", os.path.join( pg_srcdir, 'src', 'interfaces', 'libpq' ), "Compiling libpq (cd src/interfaces/libpq; make install)" ) run( "make install", os.path.join( pg_srcdir, 'src', 'bin', 'pg_config' ), "Compiling pg_config (cd src/bin/pg_config; make install)" ) run( "make install", os.path.join( pg_srcdir, 'src', 'include' ), "Compiling pg_config (cd src/include; make install)" ) # create prepped archive print "%s(): Creating prepped archive for future builds at:" % sys._getframe().f_code.co_name print " ", prepped compress( prepped, 'postgres/bin', 'postgres/include', 'postgres/lib' )
def finalize_options(self): _build_ext.finalize_options(self) self.set_undefined_options('build', ('petsc_dir', 'petsc_dir'), ('petsc_arch', 'petsc_arch')) import sys, os from distutils import sysconfig if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu') or sys.platform.startswith('sunos')) and sysconfig.get_config_var('Py_ENABLE_SHARED')): py_version = sysconfig.get_python_version() bad_pylib_dir = os.path.join(sys.prefix, "lib", "python" + py_version, "config") try: self.library_dirs.remove(bad_pylib_dir) except ValueError: pass pylib_dir = sysconfig.get_config_var("LIBDIR") if pylib_dir not in self.library_dirs: self.library_dirs.append(pylib_dir) if pylib_dir not in self.rpath: self.rpath.append(pylib_dir) if sys.exec_prefix == '/usr': self.library_dirs.remove(pylib_dir) self.rpath.remove(pylib_dir)
def initialize_compiler(platform): if not DEBUG: # Don't produce debug symbols when debug is off. if platform != 'windows': cflags = sysconfig.get_config_var('CFLAGS') opt = sysconfig.get_config_var('OPT') sysconfig._config_vars['CFLAGS'] = cflags.replace(' -g ', ' ') sysconfig._config_vars['OPT'] = opt.replace(' -g ', ' ') if platform == 'linux': ldshared = sysconfig.get_config_var('LDSHARED') sysconfig._config_vars['LDSHARED'] = ldshared.replace(' -g ', ' ') if platform == 'windows': msvc_info = find_msvc_info() if msvc_info is None: return 'unknown' version, path = msvc_info # Reliance on these is hard-coded somewhere in the guts of setuptools/distutils: os.environ['VS90COMNTOOLS'] = path os.environ['VS100COMNTOOLS'] = path os.environ['VS110COMNTOOLS'] = path os.environ['VS120COMNTOOLS'] = path return 'msvc' else: return 'default' # TODO: clang vs. gcc
def build_library(self, library, pkg_config_name, local_source=None, supports_non_srcdir_builds=True): log.info("checking if library '%s' is installed", library) try: build_args = self.pkgconfig(pkg_config_name) log.info("found '%s' installed, using it", library) except CalledProcessError: # If local_source is not specified, then immediately fail. if local_source is None: raise DistutilsExecError("library '%s' is not installed", library) log.info("building library '%s' from source", library) # Determine which compilers we are to use. cc = ' '.join(self.compiler.compiler) cxx = ' '.join(self.compiler.compiler_cxx) # Use a subdirectory of build_temp as the build directory. build_temp = os.path.realpath(os.path.join(self.build_temp, library)) # Destination for headers and libraries is build_clib. build_clib = os.path.realpath(self.build_clib) # Create build directories if they do not yet exist. mkpath(build_temp) mkpath(build_clib) if not supports_non_srcdir_builds: self._stage_files_recursive(local_source, build_temp) # This flag contains the architecture flags, if any. # On 32-bit Python on Mac OS, this will map to something like # '-arch i386 -DNDEBUG -g -O3 -arch i386'. basecflags = get_config_var('BASECFLAGS') cflags = get_config_var('CFLAGS') cflags.partition(basecflags)[-1] # Run configure. cmd = ['/bin/sh', os.path.join(os.path.realpath(local_source), 'configure'), '--prefix=' + build_clib, 'CC=' + cc, 'CXX=' + cxx, 'CFLAGS=' + cflags, 'CXXFLAGS=' + cflags, '--disable-shared', '--with-pic', '--disable-maintainer-mode'] log.info('%s', ' '.join(cmd)) check_call(cmd, cwd=build_temp, env=self._environ) # Run make install. cmd = ['make', 'install'] log.info('%s', ' '.join(cmd)) check_call(cmd, cwd=build_temp, env=self._environ) build_args = self.pkgconfig(pkg_config_name) return build_args
def compile_libevent(build): sdir = libevent_source_path if not sdir: return from distutils import sysconfig configure = os.path.abspath(os.path.join(sdir, "configure")) addlibs = [] bdir = os.path.join(build.build_temp, "libevent") if not os.path.isdir(bdir): os.makedirs(bdir) cwd = os.getcwd() os.chdir(bdir) try: if "CC" not in os.environ: cc = sysconfig.get_config_var("CC") if cc: os.environ["CC"] = cc archflags = sysconfig.get_config_var("ARCHFLAGS") if archflags: os.environ["AM_CFLAGS"] = archflags if not exists("./config.status"): mysystem("%s --with-pic --disable-shared --disable-dependency-tracking" % configure) if "bsd" in sys.platform: mysystem("gmake") else: mysystem("make") for line in open("Makefile"): if line.startswith("LIBS = "): addlibs = [x[2:] for x in line[len("LIBS = "):].strip().split() if x.startswith("-l")] finally: os.chdir(cwd) if build is None: return if build.include_dirs is None: build.include_dirs = [] if build.library_dirs is None: build.library_dirs = [] # bdir is needed for event-config.h build.include_dirs[:0] = [bdir, "%s/include" % bdir, sdir, "%s/include" % sdir] build.library_dirs[:0] = ["%s/.libs" % bdir] build.libraries.extend(addlibs) cc = build.compiler if sys.platform == "darwin": # stupid apple: http://developer.apple.com/mac/library/qa/qa2006/qa1393.html cc.linker_so += ['-Wl,-search_paths_first'] cc.linker_exe += ['-Wl,-search_paths_first'] cc.set_include_dirs(build.include_dirs) cc.set_library_dirs(build.library_dirs) cc.set_libraries(build.libraries)
def get_ext_built(self, name): if sys.platform == 'win32': head, tail = os.path.split(name) suffix = sysconfig.get_config_var('SO') return pjoin(head, build_type, tail + suffix) else: suffix = sysconfig.get_config_var('SO') return name + suffix
def copy_scripts (self): """Copy each script listed in 'self.scripts'; if it's marked as a Python script in the Unix way (first line matches 'first_line_re', ie. starts with "\#!" and contains "python"), then adjust the first line to refer to the current Python interpreter as we copy. """ self.mkpath(self.build_dir) for script in self.scripts: adjust = 0 script = convert_path(script) outfile = os.path.join(self.build_dir, os.path.basename(script)) if not self.force and not newer(script, outfile): self.announce("not copying %s (up-to-date)" % script) continue # Always open the file, but ignore failures in dry-run mode -- # that way, we'll get accurate feedback if we can read the # script. try: f = open(script, "r") except IOError: if not self.dry_run: raise f = None else: first_line = f.readline() if not first_line: self.warn("%s is an empty file (skipping)" % script) continue match = first_line_re.match(first_line) if match: adjust = 1 post_interp = match.group(1) or '' if adjust: self.announce("copying and adjusting %s -> %s" % (script, self.build_dir)) if not self.dry_run: outf = open(outfile, "w") if not sysconfig.python_build: outf.write("#!%s%s\n" % (os.path.normpath(sys.executable), post_interp)) else: outf.write("#!%s%s" % (os.path.join( sysconfig.get_config_var("BINDIR"), "python" + sysconfig.get_config_var("EXE")), post_interp)) outf.writelines(f.readlines()) outf.close() if f: f.close() else: f.close() self.copy_file(script, outfile)
def get_libraries(self, ext): """Return the list of libraries to link against when building a shared extension. On most platforms, this is just 'ext.libraries'; on Windows, we add the Python library (eg. python20.dll). """ # The python library is always needed on Windows. For MSVC, this # is redundant, since the library is mentioned in a pragma in # pyconfig.h that MSVC groks. The other Windows compilers all seem # to need it mentioned explicitly, though, so that's what we do. # Append '_d' to the python import library on debug builds. if sys.platform == "win32": from distutils._msvccompiler import MSVCCompiler if not isinstance(self.compiler, MSVCCompiler): template = "python%d%d" if self.debug: template = template + "_d" pythonlib = template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xFF) # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] else: return ext.libraries elif sys.platform[:6] == "cygwin": template = "python%d.%d" pythonlib = template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xFF) # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] elif sys.platform[:6] == "atheos": from distutils import sysconfig template = "python%d.%d" pythonlib = template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xFF) # Get SHLIBS from Makefile extra = [] for lib in sysconfig.get_config_var("SHLIBS").split(): if lib.startswith("-l"): extra.append(lib[2:]) else: extra.append(lib) # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib, "m"] + extra elif sys.platform == "darwin": # Don't use the default code below return ext.libraries elif sys.platform[:3] == "aix": # Don't use the default code below return ext.libraries else: from distutils import sysconfig if sysconfig.get_config_var("Py_ENABLE_SHARED"): pythonlib = "python{}.{}{}".format(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xFF, sys.abiflags) return ext.libraries + [pythonlib] else: return ext.libraries
def replace_tags(filenames, tagdict={}, dry_run=False): """ Update known tags in a list of files by modifying them in place. Always updates the ##COPYRIGHT## tag with the contents of the COPYRIGHT file. @param tagdict: a dictionary of tags to search for and the value that the tag should be replaced with. Only one tag should be used per line as this function is quite stupid and looks for a line starting with the tag, ignoring the rest of the line and replacing the whole line with tag = tag_value. """ copyright_file = 'COPYRIGHT' copydata = open(copyright_file).read() for line in fileinput.input(filenames, inplace=True): matched = False # replace python #! line if fileinput.isfirstline(): match = first_line_re.match(line) if match: matched = True post_interp = match.group(1) or '' if not dry_run: sys.stdout.write("#!%s%s\n" % (os.path.join( sysconfig.get_config_var("BINDIR"), "python" + sysconfig.get_config_var("EXE")), post_interp)) pass pass else: if not dry_run: sys.stdout.write(line) pass continue pass if line.startswith('##COPYRIGHT##'): if not dry_run: sys.stdout.write(copydata) matched = True continue for tag in tagdict: if line.startswith(tag): if not dry_run: sys.stdout.write("%s = '%s'\n" % (tag, tagdict[tag])) matched = True break # this only happens if nothing matches if not matched: if not dry_run: sys.stdout.write(line)
def main(): qmakePath = getEnv("QMAKE", "qmake") sipPath = getEnv("SIP", "sip") sipConfig = sipconfig.Configuration() config = Config(qmakePath) projectPath = getEnv("PROJECT_PATH", "../..") libraryPath = getEnv("LIBRARY_PATH", projectPath + "/fakevim") sipFilePath = getEnv("SIP_FILE_PATH", projectPath + "/python/fakevim.sip") pyQtIncludePath = getEnv("PYQT_INCLUDE_PATH", "/usr/share/sip/PyQt" + (config.hasQt5() and "5" or "4")) commandOutput( sipPath, config.sipFlags().split(" ") + ["-I", pyQtIncludePath, "-b", "fakevim_python.pro", "-o", "-c", ".", sipFilePath], ) with open("fakevim_python.pro", "a") as pro: pro.write( """ TEMPLATE = lib CONFIG += release plugin no_plugin_name_prefix QT += widgets TARGET = $$target HEADERS = $$headers "{projectPythonInclude}/fakevimproxy.h" SOURCES = $$sources "{projectPythonInclude}/fakevimproxy.cpp" INCLUDEPATH += "{sipInclude}" "{pythonInclude}" "{projectInclude}" "{projectPythonInclude}" LIBS += -Wl,-rpath,"{libraryPath}" -L"{libraryPath}" -lfakevim "{pythonLibrary}" DEFINES += FAKEVIM_PYQT_MAJOR_VERSION={qtVersion} isEmpty(PREFIX) {{ PREFIX = "{installPath}" }} target.path = $$PREFIX INSTALLS += target """.format( pythonInclude=sysconfig.get_python_inc(), sipInclude=sipConfig.sip_inc_dir, projectInclude=projectPath, projectPythonInclude=projectPath + "/python", libraryPath=libraryPath, pythonLibrary=sysconfig.get_config_var("LIBDIR") + "/" + sysconfig.get_config_var("MULTIARCH") + "/" + sysconfig.get_config_var("LDLIBRARY"), qtVersion=config.hasQt5() and 5 or 4, installPath=site.getusersitepackages(), ).replace( "\n ", "\n" ) )
def _build_monoclr(self, ext): mono_libs = _check_output("pkg-config --libs mono-2", shell=True) mono_cflags = _check_output("pkg-config --cflags mono-2", shell=True) glib_libs = _check_output("pkg-config --libs glib-2.0", shell=True) glib_cflags = _check_output("pkg-config --cflags glib-2.0", shell=True) cflags = mono_cflags.strip() + " " + glib_cflags.strip() libs = mono_libs.strip() + " " + glib_libs.strip() # build the clr python module clr_ext = Extension("clr", sources=[ "src/monoclr/pynetinit.c", "src/monoclr/clrmod.c" ], extra_compile_args=cflags.split(" "), extra_link_args=libs.split(" ")) build_ext.build_extension(self, clr_ext) # build the clr python executable sources = [ "src/monoclr/pynetinit.c", "src/monoclr/python.c", ] macros = ext.define_macros[:] for undef in ext.undef_macros: macros.append((undef,)) objects = self.compiler.compile(sources, output_dir=self.build_temp, macros=macros, include_dirs=ext.include_dirs, debug=self.debug, extra_postargs=cflags.split(" "), depends=ext.depends) output_dir = os.path.dirname(self.get_ext_fullpath(ext.name)) py_libs = get_config_var("BLDLIBRARY") libs += " " + py_libs # Include the directories python's shared libs were installed to. This # is case python was built with --enable-shared as then npython will need # to be able to find libpythonX.X.so. runtime_library_dirs = (get_config_var("DESTDIRS") or "").split(" ") if ext.runtime_library_dirs: runtime_library_dirs.extend(ext.runtime_library_dirs) self.compiler.link_executable(objects, _npython_exe, output_dir=output_dir, libraries=self.get_libraries(ext), library_dirs=ext.library_dirs, runtime_library_dirs=runtime_library_dirs, extra_postargs=libs.split(" "), debug=self.debug)
def get_python_libs(): """ Get the shared library names for embedding jep. See python-config """ if is_windows(): return ['python' + sysconfig.get_config_var('VERSION')] return ['python' + sysconfig.get_config_var('VERSION'), 'dl']
def get_ext_path(self, name): # Get the package directory from build_py build_py = self.get_finalized_command('build_py') package_dir = build_py.get_package_dir('dynd') # This is the name of the dynd-python C-extension suffix = sysconfig.get_config_var('EXT_SUFFIX') if (suffix is None): suffix = sysconfig.get_config_var('SO') filename = name + suffix return os.path.join(package_dir, filename)
def _get_cmake_ext_path(self, name): # Get the package directory from build_py build_py = self.get_finalized_command('build_py') package_dir = build_py.get_package_dir('pyarrow') # This is the name of the arrow C-extension suffix = sysconfig.get_config_var('EXT_SUFFIX') if suffix is None: suffix = sysconfig.get_config_var('SO') filename = name + suffix return pjoin(package_dir, filename)
def get_ext_path(self, name): # Get the package directory from build_py build_py = self.get_finalized_command("build_py") package_dir = build_py.get_package_dir("dynd") # This is the name of the dynd-python C-extension suffix = sysconfig.get_config_var("EXT_SUFFIX") if suffix is None: suffix = sysconfig.get_config_var("SO") filename = name + suffix return os.path.join(package_dir, filename)
def copy_scripts(self): """Copy each script listed in 'self.scripts'; if it's marked as a Python script in the Unix way (first line matches 'first_line_re', ie. starts with "\#!" and contains "python"), then adjust the first line to refer to the current Python interpreter as we copy. """ self.mkpath(self.build_dir) outfiles = [] for script in self.scripts: adjust = 0 script = convert_path(script) outfile = os.path.join(self.build_dir, os.path.basename(script)) outfiles.append(outfile) if not self.force and not newer(script, outfile): log.debug("not copying %s (up-to-date)", script) continue # Always open the file, but ignore failures in dry-run mode -- # that way, we'll get accurate feedback if we can read the # script. try: f = open(script, "r") except IOError: if not self.dry_run: raise f = None else: first_line = f.readline() if not first_line: self.warn("%s is an empty file (skipping)" % script) continue match = first_line_re.match(first_line) if match: adjust = 1 post_interp = match.group(1) or '' if adjust: log.info("copying and adjusting %s -> %s", script, self.build_dir) if not self.dry_run: outf = open(outfile, "w") if not sysconfig.python_build: outf.write("#!%s%s\n" % (self.executable, post_interp)) else: outf.write("#!%s%s\n" % (os.path.join( sysconfig.get_config_var("BINDIR"), "python" + sysconfig.get_config_var("EXE")), post_interp)) outf.writelines(f.readlines()) outf.close() if f: f.close() else: f.close() self.copy_file(script, outfile) if os.name == 'posix': for file in outfiles: if self.dry_run: log.info("changing mode of %s", file) else: oldmode = os.stat(file)[ST_MODE] & 07777 newmode = (oldmode | 0555) & 07777 if newmode != oldmode: log.info("changing mode of %s from %o to %o", file, oldmode, newmode) os.chmod(file, newmode)
def get_libraries (self, ext): """Return the list of libraries to link against when building a shared extension. On most platforms, this is just 'ext.libraries'; on Windows and OS/2, we add the Python library (eg. python20.dll). """ # The python library is always needed on Windows. For MSVC, this # is redundant, since the library is mentioned in a pragma in # pyconfig.h that MSVC groks. The other Windows compilers all seem # to need it mentioned explicitly, though, so that's what we do. # Append '_d' to the python import library on debug builds. if sys.platform == "win32": from distutils.msvccompiler import MSVCCompiler if not isinstance(self.compiler, MSVCCompiler): template = "python%d%d" if self.debug: template = template + '_d' pythonlib = (template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] else: return ext.libraries elif sys.platform == "os2emx": # EMX/GCC requires the python library explicitly, and I # believe VACPP does as well (though not confirmed) - AIM Apr01 template = "python%d%d" # debug versions of the main DLL aren't supported, at least # not at this time - AIM Apr01 #if self.debug: # template = template + '_d' pythonlib = (template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] elif sys.platform[:6] == "cygwin": template = "python%d.%d" pythonlib = (template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib] elif sys.platform[:6] == "atheos": from distutils import sysconfig template = "python%d.%d" pythonlib = (template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) # Get SHLIBS from Makefile extra = [] for lib in sysconfig.get_config_var('SHLIBS').split(): if lib.startswith('-l'): extra.append(lib[2:]) else: extra.append(lib) # don't extend ext.libraries, it may be shared with other # extensions, it is a reference to the original list return ext.libraries + [pythonlib, "m"] + extra elif sys.platform == 'darwin': # Don't use the default code below return ext.libraries else: from distutils import sysconfig if sysconfig.get_config_var('Py_ENABLE_SHARED'): template = "python%d.%d" pythonlib = (template % (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff)) return ext.libraries + [pythonlib] else: return ext.libraries
def find_library_file(self, dirs, lib, debug=0): shared_f = self.library_filename(lib, lib_type='shared') dylib_f = self.library_filename(lib, lib_type='dylib') xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub') static_f = self.library_filename(lib, lib_type='static') if sys.platform == 'darwin': # On OSX users can specify an alternate SDK using # '-isysroot', calculate the SDK root if it is specified # (and use it further on) # # Note that, as of Xcode 7, Apple SDKs may contain textual stub # libraries with .tbd extensions rather than the normal .dylib # shared libraries installed in /. The Apple compiler tool # chain handles this transparently but it can cause problems # for programs that are being built with an SDK and searching # for specific libraries. Callers of find_library_file need to # keep in mind that the base filename of the returned SDK library # file might have a different extension from that of the library # file installed on the running system, for example: # /Applications/Xcode.app/Contents/Developer/Platforms/ # MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/ # usr/lib/libedit.tbd # vs # /usr/lib/libedit.dylib cflags = sysconfig.get_config_var('CFLAGS') m = re.search(r'-isysroot\s*(\S+)', cflags) if m is None: sysroot = '/' else: sysroot = m.group(1) for dir in dirs: shared = os.path.join(dir, shared_f) dylib = os.path.join(dir, dylib_f) static = os.path.join(dir, static_f) xcode_stub = os.path.join(dir, xcode_stub_f) if sys.platform == 'darwin' and ( dir.startswith('/System/') or (dir.startswith('/usr/') and not dir.startswith('/usr/local/'))): shared = os.path.join(sysroot, dir[1:], shared_f) dylib = os.path.join(sysroot, dir[1:], dylib_f) static = os.path.join(sysroot, dir[1:], static_f) xcode_stub = os.path.join(sysroot, dir[1:], xcode_stub_f) # We're second-guessing the linker here, with not much hard # data to go on: GCC seems to prefer the shared library, so I'm # assuming that *all* Unix C compilers do. And of course I'm # ignoring even GCC's "-static" option. So sue me. if os.path.exists(dylib): return dylib elif os.path.exists(xcode_stub): return xcode_stub elif os.path.exists(shared): return shared elif os.path.exists(static): return static # Oops, didn't find it in *any* of 'dirs' return None
def init_env(): from setup.build_environment import msvc, is64bit, win_inc, win_lib, NMAKE from distutils import sysconfig linker = None if isunix: cc = os.environ.get('CC', 'gcc') cxx = os.environ.get('CXX', 'g++') debug = '' # debug = '-ggdb' cflags = os.environ.get( 'OVERRIDE_CFLAGS', '-Wall -DNDEBUG %s -fno-strict-aliasing -pipe' % debug) cflags = shlex.split(cflags) + ['-fPIC'] ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall') ldflags = shlex.split(ldflags) cflags += shlex.split(os.environ.get('CFLAGS', '')) ldflags += shlex.split(os.environ.get('LDFLAGS', '')) cflags += ['-fvisibility=hidden'] if islinux: cflags.append('-pthread') if sys.stdout.isatty(): cflags.append('-fdiagnostics-color=always') ldflags.append('-shared') if isbsd: cflags.append('-pthread') ldflags.append('-shared') if ishaiku: cflags.append('-lpthread') ldflags.append('-shared') if islinux or isbsd or ishaiku: cflags.append('-I' + sysconfig.get_python_inc()) # getattr(..., 'abiflags') is for PY2 compat, since PY2 has no abiflags # member ldflags.append('-lpython{}{}'.format( sysconfig.get_config_var('VERSION'), getattr(sys, 'abiflags', ''))) if isosx: cflags.append('-D_OSX') ldflags.extend('-bundle -undefined dynamic_lookup'.split()) cflags.extend(['-fno-common', '-dynamic']) cflags.append('-I' + sysconfig.get_python_inc()) if iswindows: cc = cxx = msvc.cc cflags = '/c /nologo /MD /W3 /EHsc /utf-8 /DNDEBUG'.split() ldflags = '/DLL /nologo /INCREMENTAL:NO /NODEFAULTLIB:libcmt.lib'.split( ) # cflags = '/c /nologo /Ox /MD /W3 /EHsc /Zi'.split() # ldflags = '/DLL /nologo /INCREMENTAL:NO /DEBUG'.split() if is64bit: cflags.append('/GS-') for p in win_inc: cflags.append('-I' + p) for p in win_lib: if p: ldflags.append('/LIBPATH:' + p) cflags.append('-I%s' % sysconfig.get_python_inc()) ldflags.append('/LIBPATH:' + os.path.join(sysconfig.PREFIX, 'libs')) linker = msvc.linker return namedtuple('Environment', 'cc cxx cflags ldflags linker make')( cc=cc, cxx=cxx, cflags=cflags, ldflags=ldflags, linker=linker, make=NMAKE if iswindows else 'make')
def pythonlib_dir(): """return path where libpython* is.""" if sys.platform == 'win32': return os.path.join(sys.prefix, "libs") else: return get_config_var('LIBDIR')
def get_config_var(name, default=''): return sysconfig.get_config_var(name) or default
def build_extensions(self): library_dirs = [] include_dirs = [] _add_directory(include_dirs, "src/libImaging") pkg_config = None if _cmd_exists('pkg-config'): pkg_config = _pkg_config # # add configured kits for root_name, lib_name in dict( JPEG_ROOT="libjpeg", JPEG2K_ROOT="libopenjp2", TIFF_ROOT=("libtiff-5", "libtiff-4"), ZLIB_ROOT="zlib", FREETYPE_ROOT="freetype2", LCMS_ROOT="lcms2", IMAGEQUANT_ROOT="libimagequant").items(): root = globals()[root_name] if root is None and pkg_config: if isinstance(lib_name, tuple): for lib_name2 in lib_name: _dbg('Looking for `%s` using pkg-config.' % lib_name2) root = pkg_config(lib_name2) if root: break else: _dbg('Looking for `%s` using pkg-config.' % lib_name) root = pkg_config(lib_name) if isinstance(root, tuple): lib_root, include_root = root else: lib_root = include_root = root _add_directory(library_dirs, lib_root) _add_directory(include_dirs, include_root) # respect CFLAGS/LDFLAGS for k in ('CFLAGS', 'LDFLAGS'): if k in os.environ: for match in re.finditer(r'-I([^\s]+)', os.environ[k]): _add_directory(include_dirs, match.group(1)) for match in re.finditer(r'-L([^\s]+)', os.environ[k]): _add_directory(library_dirs, match.group(1)) # include, rpath, if set as environment variables: for k in ('C_INCLUDE_PATH', 'CPATH', 'INCLUDE'): if k in os.environ: for d in os.environ[k].split(os.path.pathsep): _add_directory(include_dirs, d) for k in ('LD_RUN_PATH', 'LIBRARY_PATH', 'LIB'): if k in os.environ: for d in os.environ[k].split(os.path.pathsep): _add_directory(library_dirs, d) prefix = sysconfig.get_config_var("prefix") if prefix: _add_directory(library_dirs, os.path.join(prefix, "lib")) _add_directory(include_dirs, os.path.join(prefix, "include")) # # add platform directories if self.disable_platform_guessing: pass elif sys.platform == "cygwin": # pythonX.Y.dll.a is in the /usr/lib/pythonX.Y/config directory _add_directory( library_dirs, os.path.join("/usr/lib", "python%s" % sys.version[:3], "config")) elif sys.platform == "darwin": # attempt to make sure we pick freetype2 over other versions _add_directory(include_dirs, "/sw/include/freetype2") _add_directory(include_dirs, "/sw/lib/freetype2/include") # fink installation directories _add_directory(library_dirs, "/sw/lib") _add_directory(include_dirs, "/sw/include") # darwin ports installation directories _add_directory(library_dirs, "/opt/local/lib") _add_directory(include_dirs, "/opt/local/include") # if Homebrew is installed, use its lib and include directories try: prefix = subprocess.check_output(['brew', '--prefix' ]).strip().decode('latin1') except Exception: # Homebrew not installed prefix = None ft_prefix = None if prefix: # add Homebrew's include and lib directories _add_directory(library_dirs, os.path.join(prefix, 'lib')) _add_directory(include_dirs, os.path.join(prefix, 'include')) ft_prefix = os.path.join(prefix, 'opt', 'freetype') if ft_prefix and os.path.isdir(ft_prefix): # freetype might not be linked into Homebrew's prefix _add_directory(library_dirs, os.path.join(ft_prefix, 'lib')) _add_directory(include_dirs, os.path.join(ft_prefix, 'include')) else: # fall back to freetype from XQuartz if # Homebrew's freetype is missing _add_directory(library_dirs, "/usr/X11/lib") _add_directory(include_dirs, "/usr/X11/include") elif sys.platform.startswith("linux"): arch_tp = (plat.processor(), plat.architecture()[0]) # This should be correct on debian derivatives. if os.path.exists('/etc/debian_version'): # If this doesn't work, don't just silently patch # downstream because it's going to break when people # try to build pillow from source instead of # installing from the system packages. self.add_multiarch_paths() elif arch_tp == ("x86_64", "32bit"): # Special Case: 32-bit build on 64-bit machine. _add_directory(library_dirs, "/usr/lib/i386-linux-gnu") else: libdirs = { 'x86_64': ["/lib64", "/usr/lib64", "/usr/lib/x86_64-linux-gnu"], '64bit': ["/lib64", "/usr/lib64", "/usr/lib/x86_64-linux-gnu"], 'i386': ["/usr/lib/i386-linux-gnu"], 'i686': ["/usr/lib/i386-linux-gnu"], '32bit': ["/usr/lib/i386-linux-gnu"], 'aarch64': ["/usr/lib64", "/usr/lib/aarch64-linux-gnu"], 'arm': ["/usr/lib/arm-linux-gnueabi"], 'armv71': ["/usr/lib/arm-linux-gnueabi"], 'armv7l': ["/usr/lib"], 'ppc64': [ "/usr/lib64", "/usr/lib/ppc64-linux-gnu", "/usr/lib/powerpc64-linux-gnu" ], 'ppc64le': ["/usr/lib64"], 'ppc': ["/usr/lib/ppc-linux-gnu", "/usr/lib/powerpc-linux-gnu"], 's390x': ["/usr/lib64", "/usr/lib/s390x-linux-gnu"], 's390': ["/usr/lib/s390-linux-gnu"], } for platform_ in arch_tp: dirs = libdirs.get(platform_, None) if not dirs: continue for path in dirs: _add_directory(library_dirs, path) break else: raise ValueError( "Unable to identify Linux platform: `%s`" % platform_) # termux support for android. # system libraries (zlib) are installed in /system/lib # headers are at $PREFIX/include # user libs are at $PREFIX/lib if os.environ.get('ANDROID_ROOT', None): _add_directory( library_dirs, os.path.join(os.environ['ANDROID_ROOT'], 'lib')) elif sys.platform.startswith("gnu"): self.add_multiarch_paths() elif sys.platform.startswith("freebsd"): _add_directory(library_dirs, "/usr/local/lib") _add_directory(include_dirs, "/usr/local/include") elif sys.platform.startswith("netbsd"): _add_directory(library_dirs, "/usr/pkg/lib") _add_directory(include_dirs, "/usr/pkg/include") elif sys.platform.startswith("sunos5"): _add_directory(library_dirs, "/opt/local/lib") _add_directory(include_dirs, "/opt/local/include") # FIXME: check /opt/stuff directories here? # standard locations if not self.disable_platform_guessing: _add_directory(library_dirs, "/usr/local/lib") _add_directory(include_dirs, "/usr/local/include") _add_directory(library_dirs, "/usr/lib") _add_directory(include_dirs, "/usr/include") # alpine, at least _add_directory(library_dirs, "/lib") # on Windows, look for the OpenJPEG libraries in the location that # the official installer puts them if sys.platform == "win32": program_files = os.environ.get('ProgramFiles', '') best_version = (0, 0) best_path = None for name in os.listdir(program_files): if name.startswith('OpenJPEG '): version = tuple( int(x) for x in name[9:].strip().split('.')) if version > best_version: best_version = version best_path = os.path.join(program_files, name) if best_path: _dbg('Adding %s to search list', best_path) _add_directory(library_dirs, os.path.join(best_path, 'lib')) _add_directory(include_dirs, os.path.join(best_path, 'include')) # # insert new dirs *before* default libs, to avoid conflicts # between Python PYD stub libs and real libraries self.compiler.library_dirs = library_dirs + self.compiler.library_dirs self.compiler.include_dirs = include_dirs + self.compiler.include_dirs # # look for available libraries feature = self.feature if feature.want('zlib'): _dbg('Looking for zlib') if _find_include_file(self, "zlib.h"): if _find_library_file(self, "z"): feature.zlib = "z" elif (sys.platform == "win32" and _find_library_file(self, "zlib")): feature.zlib = "zlib" # alternative name if feature.want('jpeg'): _dbg('Looking for jpeg') if _find_include_file(self, "jpeglib.h"): if _find_library_file(self, "jpeg"): feature.jpeg = "jpeg" elif (sys.platform == "win32" and _find_library_file(self, "libjpeg")): feature.jpeg = "libjpeg" # alternative name feature.openjpeg_version = None if feature.want('jpeg2000'): _dbg('Looking for jpeg2000') best_version = None best_path = None # Find the best version for directory in self.compiler.include_dirs: _dbg('Checking for openjpeg-#.# in %s', directory) try: listdir = os.listdir(directory) except Exception: # WindowsError, FileNotFoundError continue for name in listdir: if name.startswith('openjpeg-') and \ os.path.isfile(os.path.join(directory, name, 'openjpeg.h')): _dbg('Found openjpeg.h in %s/%s', (directory, name)) version = tuple(int(x) for x in name[9:].split('.')) if best_version is None or version > best_version: best_version = version best_path = os.path.join(directory, name) _dbg('Best openjpeg version %s so far in %s', (best_version, best_path)) if best_version and _find_library_file(self, 'openjp2'): # Add the directory to the include path so we can include # <openjpeg.h> rather than having to cope with the versioned # include path # FIXME (melvyn-sopacua): # At this point it's possible that best_path is already in # self.compiler.include_dirs. Should investigate how that is # possible. _add_directory(self.compiler.include_dirs, best_path, 0) feature.jpeg2000 = 'openjp2' feature.openjpeg_version = '.'.join( str(x) for x in best_version) if feature.want('imagequant'): _dbg('Looking for imagequant') if _find_include_file(self, 'libimagequant.h'): if _find_library_file(self, "imagequant"): feature.imagequant = "imagequant" elif _find_library_file(self, "libimagequant"): feature.imagequant = "libimagequant" if feature.want('tiff'): _dbg('Looking for tiff') if _find_include_file(self, 'tiff.h'): if _find_library_file(self, "tiff"): feature.tiff = "tiff" if (sys.platform == "win32" and _find_library_file(self, "libtiff")): feature.tiff = "libtiff" if (sys.platform == "darwin" and _find_library_file(self, "libtiff")): feature.tiff = "libtiff" if feature.want('freetype'): _dbg('Looking for freetype') if _find_library_file(self, "freetype"): # look for freetype2 include files freetype_version = 0 for subdir in self.compiler.include_dirs: _dbg('Checking for include file %s in %s', ("ft2build.h", subdir)) if os.path.isfile(os.path.join(subdir, "ft2build.h")): _dbg('Found %s in %s', ("ft2build.h", subdir)) freetype_version = 21 subdir = os.path.join(subdir, "freetype2") break subdir = os.path.join(subdir, "freetype2") _dbg('Checking for include file %s in %s', ("ft2build.h", subdir)) if os.path.isfile(os.path.join(subdir, "ft2build.h")): _dbg('Found %s in %s', ("ft2build.h", subdir)) freetype_version = 21 break if freetype_version: feature.freetype = "freetype" feature.freetype_version = freetype_version if subdir: _add_directory(self.compiler.include_dirs, subdir, 0) if feature.want('lcms'): _dbg('Looking for lcms') if _find_include_file(self, "lcms2.h"): if _find_library_file(self, "lcms2"): feature.lcms = "lcms2" elif _find_library_file(self, "lcms2_static"): # alternate Windows name. feature.lcms = "lcms2_static" if feature.want('webp'): _dbg('Looking for webp') if (_find_include_file(self, "webp/encode.h") and _find_include_file(self, "webp/decode.h")): # In Google's precompiled zip it is call "libwebp": if _find_library_file(self, "webp"): feature.webp = "webp" elif _find_library_file(self, "libwebp"): feature.webp = "libwebp" if feature.want('webpmux'): _dbg('Looking for webpmux') if (_find_include_file(self, "webp/mux.h") and _find_include_file(self, "webp/demux.h")): if (_find_library_file(self, "webpmux") and _find_library_file(self, "webpdemux")): feature.webpmux = "webpmux" if (_find_library_file(self, "libwebpmux") and _find_library_file(self, "libwebpdemux")): feature.webpmux = "libwebpmux" for f in feature: if not getattr(feature, f) and feature.require(f): if f in ('jpeg', 'zlib'): raise RequiredDependencyException(f) raise DependencyException(f) # # core library files = ["src/_imaging.c"] for src_file in _IMAGING: files.append("src/" + src_file + ".c") for src_file in _LIB_IMAGING: files.append(os.path.join("src/libImaging", src_file + ".c")) libs = [] defs = [] if feature.jpeg: libs.append(feature.jpeg) defs.append(("HAVE_LIBJPEG", None)) if feature.jpeg2000: libs.append(feature.jpeg2000) defs.append(("HAVE_OPENJPEG", None)) if sys.platform == "win32": defs.append(("OPJ_STATIC", None)) if feature.zlib: libs.append(feature.zlib) defs.append(("HAVE_LIBZ", None)) if feature.imagequant: libs.append(feature.imagequant) defs.append(("HAVE_LIBIMAGEQUANT", None)) if feature.tiff: libs.append(feature.tiff) defs.append(("HAVE_LIBTIFF", None)) if sys.platform == "win32": libs.extend(["kernel32", "user32", "gdi32"]) if struct.unpack("h", "\0\1".encode('ascii'))[0] == 1: defs.append(("WORDS_BIGENDIAN", None)) if sys.platform == "win32" and not (PLATFORM_PYPY or PLATFORM_MINGW): defs.append(("PILLOW_VERSION", '"\\"%s\\""' % PILLOW_VERSION)) else: defs.append(("PILLOW_VERSION", '"%s"' % PILLOW_VERSION)) exts = [(Extension("PIL._imaging", files, libraries=libs, define_macros=defs))] # # additional libraries if feature.freetype: libs = ["freetype"] defs = [] exts.append( Extension("PIL._imagingft", ["src/_imagingft.c"], libraries=libs, define_macros=defs)) if feature.lcms: extra = [] if sys.platform == "win32": extra.extend(["user32", "gdi32"]) exts.append( Extension("PIL._imagingcms", ["src/_imagingcms.c"], libraries=[feature.lcms] + extra)) if feature.webp: libs = [feature.webp] defs = [] if feature.webpmux: defs.append(("HAVE_WEBPMUX", None)) libs.append(feature.webpmux) libs.append(feature.webpmux.replace('pmux', 'pdemux')) exts.append( Extension("PIL._webp", ["src/_webp.c"], libraries=libs, define_macros=defs)) tk_libs = ['psapi'] if sys.platform == 'win32' else [] exts.append( Extension("PIL._imagingtk", ["src/_imagingtk.c", "src/Tk/tkImaging.c"], include_dirs=['src/Tk'], libraries=tk_libs)) exts.append(Extension("PIL._imagingmath", ["src/_imagingmath.c"])) exts.append(Extension("PIL._imagingmorph", ["src/_imagingmorph.c"])) self.extensions[:] = exts build_ext.build_extensions(self) # # sanity checks self.summary_report(feature)
def get_ext_name(self, name): suffix = sysconfig.get_config_var('EXT_SUFFIX') if suffix is None: suffix = sysconfig.get_config_var('SO') suffix = "." + suffix.rsplit(".", 1)[-1] return name + suffix
import os import inspect import sys from distutils import sysconfig from distutils.sysconfig import get_python_lib try: from setuptools import setup, Extension from setuptools.command.build_ext import build_ext as _build_ext except ImportError: print( "Installing REBOUNDx requires setuptools. Do 'pip install setuptools'." ) sys.exit(1) suffix = sysconfig.get_config_var('EXT_SUFFIX') if suffix is None: suffix = ".so" # Try to get git hash try: import subprocess ghash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii") ghash_arg = "-DREBXGITHASH=" + ghash except: ghash_arg = "-DREBXGITHASH=f6f6c159ec82f3298938f5b2899db2896afaaf1a" #GITHASHAUTOUPDATE class build_ext(_build_ext): def finalize_options(self):
pass elif line.startswith('-'): pass else: extras_require[section].append(line.strip()) install_requires = extras_require.pop('default') tests_require = extras_require.get('tests', []) # General extension paths if sys.platform.startswith('win'): def get_config_var(name): return '.' include_dir = get_config_var('INCLUDEDIR') library_dir = get_config_var('LIBDIR') extra_extension_args = defaultdict(list) if not sys.platform.startswith('win'): extra_extension_args["runtime_library_dirs"].append( get_config_var('LIBDIR')) # Description # =========== with open(os.path.join(HERE, 'README.md'), 'r') as fh: description = ''.join(fh.readlines()) cython_coverage_enabled = os.environ.get('CYTHON_COVERAGE', None) if proj_version >= (6, 0, 0): extra_extension_args["define_macros"].append( ('ACCEPT_USE_OF_DEPRECATED_PROJ_API_H', '1'))
def link(self, target_desc, objects, output_filename, output_dir=None, libraries=None, library_dirs=None, runtime_library_dirs=None, export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None, build_temp=None, target_lang=None): objects, output_dir = self._fix_object_args(objects, output_dir) fixed_args = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs) libraries, library_dirs, runtime_library_dirs = fixed_args # filter out standard library paths, which are not explicitely needed # for linking system_libdirs = ['/lib', '/lib64', '/usr/lib', '/usr/lib64'] multiarch = sysconfig.get_config_var("MULTIARCH") if multiarch: system_libdirs.extend( ['/lib/%s' % multiarch, '/usr/lib/%s' % multiarch]) library_dirs = [ dir for dir in library_dirs if not dir in system_libdirs ] runtime_library_dirs = [ dir for dir in runtime_library_dirs if not dir in system_libdirs ] lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries) if not isinstance(output_dir, (str, type(None))): raise TypeError("'output_dir' must be a string or None") if output_dir is not None: output_filename = os.path.join(output_dir, output_filename) if self._need_link(objects, output_filename): ld_args = (objects + self.objects + lib_opts + ['-o', output_filename]) if debug: ld_args[:0] = ['-g'] if extra_preargs: ld_args[:0] = extra_preargs if extra_postargs: ld_args.extend(extra_postargs) self.mkpath(os.path.dirname(output_filename)) try: if target_desc == CCompiler.EXECUTABLE: linker = self.linker_exe[:] else: linker = self.linker_so[:] if target_lang == "c++" and self.compiler_cxx: # skip over environment variable settings if /usr/bin/env # is used to set up the linker's environment. # This is needed on OSX. Note: this assumes that the # normal and C++ compiler have the same environment # settings. i = 0 if os.path.basename(linker[0]) == "env": i = 1 while '=' in linker[i]: i += 1 linker[i] = self.compiler_cxx[i] if sys.platform == 'darwin': linker = _osx_support.compiler_fixup(linker, ld_args) self.spawn(linker + ld_args) except DistutilsExecError as msg: raise LinkError(msg) else: log.debug("skipping %s (up-to-date)", output_filename)
'sstcam_sandbox.d190209_spectra.spe_functions', sources=['sstcam_sandbox/d190209_spectra/spe_functions.cc'], ), ] def is_platform_mac(): return sys.platform == 'darwin' # Handle mac error: https://github.com/pandas-dev/pandas/issues/23424 if is_platform_mac(): if 'MACOSX_DEPLOYMENT_TARGET' not in os.environ: current_system = LooseVersion(platform.mac_ver()[0]) python_target = LooseVersion( get_config_var('MACOSX_DEPLOYMENT_TARGET')) if (python_target <= '10.9') and (current_system >= '10.9'): os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9' os.environ['CC'] = 'clang' os.environ['CXX'] = 'clang++' setup( name=PACKAGENAME, packages=find_packages(), version=VERSION, description=DESCRIPTION, license='BSD3', install_requires=[ 'astropy', 'scipy', 'numpy', 'matplotlib', 'tqdm', 'pandas>=0.21.0', 'iminuit', 'numba', 'PyYAML', 'seaborn' ],
import os import shutil import logging from distutils.core import setup, Extension from distutils.sysconfig import get_config_var, get_config_vars import _sysconfig __dir__ = __file__.rpartition("/")[0] cflags_warnings = ["-Wno-int-to-pointer-cast", "-Wno-int-conversion", "-Wno-incompatible-pointer-types-discards-qualifiers", "-Wno-pointer-type-mismatch", "-Wno-braced-scalar-init"] libpython_name = "libpython" libhpy_name = "libhpy" verbosity = '--verbose' if sys.flags.verbose else '--quiet' darwin_native = sys.platform == "darwin" and __graalpython__.platform_id == "native" relative_rpath = "@loader_path" if darwin_native else r"\$ORIGIN" so_ext = get_config_var("EXT_SUFFIX") SOABI = get_config_var("SOABI") # configure logger logger = logging.getLogger(__name__) logging.basicConfig(format='%(message)s', level=logging.DEBUG if sys.flags.verbose else logging.ERROR) threaded = _sysconfig.get_config_var("WITH_THREAD") if threaded: logger.debug("building C API threaded") import threading import queue class SimpleThreadPool:
def _make_ext_name(modname): return modname + sysconfig.get_config_var('EXT_SUFFIX')
LIBDIR2 = get_config_var('LIBPL') PYLIB = get_config_var('LIBRARY') PYLIB_DYN = get_config_var('LDLIBRARY') if PYLIB_DYN == PYLIB: # no shared library PYLIB_DYN = '' else: PYLIB_DYN = os.path.splitext(PYLIB_DYN[3:])[0] # 'lib(XYZ).so' -> XYZ CC = get_config_var('CC', os.environ.get('CC', '')) CFLAGS = get_config_var('CFLAGS') + ' ' + os.environ.get('CFLAGS', '') LINKCC = get_config_var('LINKCC', os.environ.get('LINKCC', CC)) LINKFORSHARED = get_config_var('LINKFORSHARED') LIBS = get_config_var('LIBS') SYSLIBS = get_config_var('SYSLIBS') EXE_EXT = sysconfig.get_config_var('EXE') def _debug(msg, *args): if DEBUG: if args: msg = msg % args sys.stderr.write(msg + '\n') def dump_config(): _debug('INCDIR: %s', INCDIR) _debug('LIBDIR1: %s', LIBDIR1) _debug('LIBDIR2: %s', LIBDIR2) _debug('PYLIB: %s', PYLIB) _debug('PYLIB_DYN: %s', PYLIB_DYN)
s for s, _, tp in imp.get_suffixes() if tp == imp.C_EXTENSION ] else: from importlib.machinery import EXTENSION_SUFFIXES try: # Attempt to use Cython for building extensions, if available from Cython.Distutils.build_ext import build_ext as _build_ext # Additionally, assert that the compiler module will load # also. Ref #1229. __import__('Cython.Compiler.Main') except ImportError: _build_ext = _du_build_ext # make sure _config_vars is initialized get_config_var("LDSHARED") from distutils.sysconfig import _config_vars as _CONFIG_VARS # noqa def _customize_compiler_for_shlib(compiler): if sys.platform == "darwin": # building .dylib requires additional compiler flags on OSX; here we # temporarily substitute the pyconfig.h variables so that distutils' # 'customize_compiler' uses them before we build the shared libraries. tmp = _CONFIG_VARS.copy() try: # XXX Help! I don't have any idea whether these are right... _CONFIG_VARS['LDSHARED'] = ( "gcc -Wl,-x -dynamiclib -undefined dynamic_lookup") _CONFIG_VARS['CCSHARED'] = " -dynamiclib" _CONFIG_VARS['SO'] = ".dylib"
def link_py_so(obj_files, so_file=None, cwd=None, libraries=None, cplus=False, fort=False, **kwargs): """ Link python extension module (shared object) for importing Parameters ========== obj_files: iterable of str Paths to object files to be linked. so_file: str Name (path) of shared object file to create. If not specified it will have the basname of the last object file in `obj_files` but with the extension '.so' (Unix). cwd: path string Root of relative paths and working directory of linker. libraries: iterable of strings Libraries to link against, e.g. ['m']. cplus: bool Any C++ objects? default: ``False``. fort: bool Any Fortran objects? default: ``False``. kwargs**: dict Keyword arguments passed to ``link(...)``. Returns ======= Absolute path to the generate shared object. """ libraries = libraries or [] include_dirs = kwargs.pop('include_dirs', []) library_dirs = kwargs.pop('library_dirs', []) # from distutils/command/build_ext.py: if sys.platform == "win32": warnings.warn("Windows not yet supported.") elif sys.platform == 'darwin': # Don't use the default code below pass elif sys.platform[:3] == 'aix': # Don't use the default code below pass else: from distutils import sysconfig if sysconfig.get_config_var('Py_ENABLE_SHARED'): ABIFLAGS = sysconfig.get_config_var('ABIFLAGS') pythonlib = 'python{}.{}{}'.format(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff, ABIFLAGS or '') libraries += [pythonlib] else: pass flags = kwargs.pop('flags', []) needed_flags = ('-pthread', ) for flag in needed_flags: if flag not in flags: flags.append(flag) return link(obj_files, shared=True, flags=flags, cwd=cwd, cplus=cplus, fort=fort, include_dirs=include_dirs, libraries=libraries, library_dirs=library_dirs, **kwargs)
def test_get_outputs(self): tmp_dir = self.mkdtemp() c_file = os.path.join(tmp_dir, 'foo.c') self.write_file(c_file, 'void initfoo(void) {};\n') ext = Extension('foo', [c_file]) dist = Distribution({'name': 'xx', 'ext_modules': [ext]}) cmd = build_ext(dist) support.fixup_build_ext(cmd) cmd.ensure_finalized() self.assertEqual(len(cmd.get_outputs()), 1) cmd.build_lib = os.path.join(self.tmp_dir, 'build') cmd.build_temp = os.path.join(self.tmp_dir, 'tempt') # issue #5977 : distutils build_ext.get_outputs # returns wrong result with --inplace other_tmp_dir = os.path.realpath(self.mkdtemp()) old_wd = os.getcwd() os.chdir(other_tmp_dir) try: cmd.inplace = 1 cmd.run() so_file = cmd.get_outputs()[0] finally: os.chdir(old_wd) self.assertTrue(os.path.exists(so_file)) self.assertEqual(so_file[so_file.index(os.path.extsep):], sysconfig.get_config_var('SO')) so_dir = os.path.dirname(so_file) self.assertEqual(so_dir, other_tmp_dir) cmd.compiler = None cmd.inplace = 0 cmd.run() so_file = cmd.get_outputs()[0] self.assertTrue(os.path.exists(so_file)) self.assertEqual(so_file[so_file.index(os.path.extsep):], sysconfig.get_config_var('SO')) so_dir = os.path.dirname(so_file) self.assertEqual(so_dir, cmd.build_lib) # inplace = 0, cmd.package = 'bar' build_py = cmd.get_finalized_command('build_py') build_py.package_dir = {'': 'bar'} path = cmd.get_ext_fullpath('foo') # checking that the last directory is the build_dir path = os.path.split(path)[0] self.assertEqual(path, cmd.build_lib) # inplace = 1, cmd.package = 'bar' cmd.inplace = 1 other_tmp_dir = os.path.realpath(self.mkdtemp()) old_wd = os.getcwd() os.chdir(other_tmp_dir) try: path = cmd.get_ext_fullpath('foo') finally: os.chdir(old_wd) # checking that the last directory is bar path = os.path.split(path)[0] lastdir = os.path.split(path)[-1] self.assertEqual(lastdir, 'bar')
import re import shutil import subprocess import sys import tempfile import warnings from distutils.sysconfig import get_config_var, get_config_vars from .util import (get_abspath, make_dirs, copy, Glob, ArbitraryDepthGlob, glob_at_depth, CompileError, import_module_from_file, pyx_is_cplus, sha256_of_string, sha256_of_file) from .runners import (CCompilerRunner, CppCompilerRunner, FortranCompilerRunner) sharedext = get_config_var('EXT_SUFFIX' if sys.version_info >= (3, 3) else 'SO') if os.name == 'posix': objext = '.o' elif os.name == 'nt': objext = '.obj' else: warning.warng("Unknown os.name: {}".format(os.name)) objext = '.o' def compile_sources(files, Runner=None, destdir=None, cwd=None, keep_dir_struct=False,
def finalize_options (self): from distutils import sysconfig self.set_undefined_options('build', ('build_lib', 'build_lib'), ('build_temp', 'build_temp'), ('compiler', 'compiler'), ('debug', 'debug'), ('force', 'force')) if self.package is None: self.package = self.distribution.ext_package self.extensions = self.distribution.ext_modules # Make sure Python's include directories (for Python.h, pyconfig.h, # etc.) are in the include search path. py_include = sysconfig.get_python_inc() plat_py_include = sysconfig.get_python_inc(plat_specific=1) if self.include_dirs is None: self.include_dirs = self.distribution.include_dirs or [] if type(self.include_dirs) is StringType: self.include_dirs = string.split(self.include_dirs, os.pathsep) # Put the Python "system" include dir at the end, so that # any local include dirs take precedence. self.include_dirs.append(py_include) if plat_py_include != py_include: self.include_dirs.append(plat_py_include) if type(self.libraries) is StringType: self.libraries = [self.libraries] # Life is easier if we're not forever checking for None, so # simplify these options to empty lists if unset if self.libraries is None: self.libraries = [] if self.library_dirs is None: self.library_dirs = [] elif type(self.library_dirs) is StringType: self.library_dirs = string.split(self.library_dirs, os.pathsep) if self.rpath is None: self.rpath = [] elif type(self.rpath) is StringType: self.rpath = string.split(self.rpath, os.pathsep) # for extensions under windows use different directories # for Release and Debug builds. # also Python's library directory must be appended to library_dirs if os.name == 'nt': self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) if self.debug: self.build_temp = os.path.join(self.build_temp, "Debug") else: self.build_temp = os.path.join(self.build_temp, "Release") # Append the source distribution include and library directories, # this allows distutils on windows to work in the source tree self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC')) self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild')) # OS/2 (EMX) doesn't support Debug vs Release builds, but has the # import libraries in its "Config" subdirectory if os.name == 'os2': self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config')) # for extensions under Cygwin and AtheOS Python's library directory must be # appended to library_dirs if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions self.library_dirs.append(os.path.join(sys.prefix, "lib", "python" + get_python_version(), "config")) else: # building python standard extensions self.library_dirs.append('.') # for extensions under Linux with a shared Python library, # Python's library directory must be appended to library_dirs if (sys.platform.startswith('linux') or sys.platform.startswith('gnu')) \ and sysconfig.get_config_var('Py_ENABLE_SHARED'): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) else: # building python standard extensions self.library_dirs.append('.') # The argument parsing will result in self.define being a string, but # it has to be a list of 2-tuples. All the preprocessor symbols # specified by the 'define' option will be set to '1'. Multiple # symbols can be separated with commas. if self.define: defines = string.split(self.define, ',') self.define = map(lambda symbol: (symbol, '1'), defines) # The option for macros to undefine is also a string from the # option parsing, but has to be a list. Multiple symbols can also # be separated with commas here. if self.undef: self.undef = string.split(self.undef, ',') if self.swig_opts is None: self.swig_opts = [] else: self.swig_opts = self.swig_opts.split(' ')
reset_line = "_reset_sys_path()" run_line = "_run()" for line in fileinput.input(boot_file, inplace=True): if line.startswith(reset_line): print(reset_line) print(get_env) elif line.startswith(run_line): print(change_interpreter) print(new_path) print(ip_dir) print(run_line) else: print(line, end='') # To use the app's own Qt framework subprocess.call(['macdeployqt', 'dist/%s' % MAC_APP_NAME]) # Workaround for what appears to be a bug with py2app and Homebrew # See https://bitbucket.org/ronaldoussoren/py2app/issue/26#comment-2092445 PF_dir = get_config_var('PYTHONFRAMEWORKINSTALLDIR') if not PY2: PF_dir = osp.join(PF_dir, 'Versions', py_ver) app_python_interpreter = 'dist/%s/Contents/MacOS/python' % MAC_APP_NAME shutil.copyfile(osp.join(PF_dir, 'Resources/Python.app/Contents/MacOS/Python'), app_python_interpreter) exec_path = '@executable_path/../Frameworks/Python.framework/Versions/%s/Python' % py_ver subprocess.call([ 'install_name_tool', '-change', osp.join(sys.prefix, 'Python'), exec_path, app_python_interpreter ])
from os.path import join as pjoin from distutils.command.clean import clean as _clean from distutils.util import strtobool from distutils import sysconfig # Check if we're running 64-bit Python is_64_bit = sys.maxsize > 2**32 if Cython.__version__ < '0.29': raise Exception('Please upgrade to Cython 0.29 or newer') setup_dir = os.path.abspath(os.path.dirname(__file__)) ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') if ext_suffix is None: # https://bugs.python.org/issue19555 ext_suffix = sysconfig.get_config_var('SO') @contextlib.contextmanager def changed_dir(dirname): oldcwd = os.getcwd() os.chdir(dirname) try: yield finally: os.chdir(oldcwd)
xcode4 = True xcode51 = False # XCode 4.0 dropped support for ppc architecture, which is hardcoded in # distutils.sysconfig if xcode4: os.environ['ARCHFLAGS'] = '' # XCode 5.1 changes clang such that it now fails to compile if the # -mno-fused-madd flag is passed, but the version of Python shipped with # OS X 10.9 Mavericks includes this flag. This causes problems in all # C extension modules, and a bug has been filed upstream at # http://bugs.python.org/issue21244. We also need to patch this here # so Mercurial can continue to compile in the meantime. if xcode51: cflags = get_config_var('CFLAGS') if cflags and re.search(r'-mno-fused-madd\b', cflags) is not None: os.environ['CFLAGS'] = ( os.environ.get('CFLAGS', '') + ' -Qunused-arguments') setup(name='mercurial', version=setupversion, author='Matt Mackall and many others', author_email='*****@*****.**', url='https://mercurial-scm.org/', download_url='https://mercurial-scm.org/release/', description=('Fast scalable distributed SCM (revision control, version ' 'control) system'), long_description=('Mercurial is a distributed SCM tool written in Python.' ' It is used by a number of large projects that require' ' fast, reliable distributed revision control, such as '
HAVE_BROKEN_SEM_UNLINK=1 ) libraries = [] elif sys.platform in ('freebsd4', 'freebsd5', 'freebsd6'): # FreeBSD's P1003.1b semaphore support is very experimental # and has many known problems. (as of June 2008) macros = dict( # FreeBSD 4-6 HAVE_SEM_OPEN=0, HAVE_SEM_TIMEDWAIT=0, HAVE_FD_TRANSFER=1, ) libraries = [] elif re.match('^(gnukfreebsd(8|9|10|11)|freebsd(7|8|9|10))', sys.platform): macros = dict( # FreeBSD 7+ and GNU/kFreeBSD 8+ HAVE_SEM_OPEN=bool( sysconfig.get_config_var('HAVE_SEM_OPEN') and not bool(sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')) ), HAVE_SEM_TIMEDWAIT=1, HAVE_FD_TRANSFER=1, ) libraries = [] elif sys.platform.startswith('openbsd'): macros = dict( # OpenBSD HAVE_SEM_OPEN=0, # Not implemented HAVE_SEM_TIMEDWAIT=0, HAVE_FD_TRANSFER=1, ) libraries = [] else: # Linux and other unices macros = dict(
def build(self, extracted_dir=None): if not extracted_dir: extracted_dir = self.download() lib_src_folder = os.path.join(extracted_dir, self.package_name + "-" + self.version) logger.info("Building dependency %s in %s using Makefile %s" % (self.package_name, lib_src_folder, self.makefile)) # On Darwin, we need to use -install_name for the native linker if darwin_native: makefile_path = os.path.join(lib_src_folder, self.makefile) with open(makefile_path, "r") as f: content = f.read() content = content.replace("-Wl,-soname -Wl,%s" % self.install_name, "-Wl,-install_name -Wl,@rpath/%s" % self.install_name) with open(makefile_path, "w") as f: f.write(content) parallel_arg = "-j" + str(os.cpu_count()) if threaded else "" system("make -C '%s' %s -f '%s' CC='%s'" % (lib_src_folder, parallel_arg, self.makefile, get_config_var("CC")), msg="Could not build libbz2") return lib_src_folder
os.path.relpath(os.path.join(root, _f), 'CoolProp') for _f in files ] return thefiles if __name__ == '__main__': # #Handling the standard library for C++ on OSX # # This is mostly related to the compiler version, but since it is much # easier to check the OSX version, we are may also use that as an # indicator. OSX 10.14 and XCode 10 completely dropped support for # libstdc++ which forces is to manipulate the minimum OSX target # version when compiling the Cython extensions. if sys.platform == 'darwin': osx_target = LooseVersion(get_config_var('MACOSX_DEPLOYMENT_TARGET')) osx_compiler = LooseVersion('0.0') osx_version = LooseVersion('0.0') FORCE_TARGET = None USE_OSX_VERSION = False if USE_OSX_VERSION: osx_version = LooseVersion(platform.mac_ver()[0]) print("OSX build detected, targetting {0} on {1}.".format( osx_target, osx_version)) else: import subprocess cmd = subprocess.Popen( r'gcc --version | grep clang | grep -o -E "(\d+\.)+\d+" | uniq | sort', shell=True, stdout=subprocess.PIPE) for line in cmd.stdout:
pass elif line.startswith('-'): pass else: extras_require[section].append(line.strip()) install_requires = extras_require.pop('default') tests_require = extras_require.pop('tests', []) # General extension paths if sys.platform.startswith('win'): def get_config_var(name): return '.' include_dir = get_config_var('INCLUDEDIR') library_dir = get_config_var('LIBDIR') if sys.platform.startswith('win'): extra_extension_args = {} else: extra_extension_args = dict( runtime_library_dirs=[get_config_var('LIBDIR')]) # Description # =========== with open(os.path.join(HERE, 'README.rst'), 'r') as fh: description = ''.join(fh.readlines()) # Main setup # ==========
if gdal_config.version()[0] == 2: extra_compile_args.append('-D GDAL2') elif gdal_config.version()[0] == 3: extra_compile_args.append('-D GDAL3') if gdal_config.version()[1] > 0: extra_compile_args.append('-D GDAL31') extra_link_args = gdal_config.extra_link_args # not sure if current directory is necessary here lib_dirs = gdal_config.lib_dirs + ['./'] if sys.platform == 'darwin': extra_compile_args.append('-stdlib=libc++') extra_link_args.append('-stdlib=libc++') ldshared = sysconfig.get_config_var('LDSHARED') sysconfig._config_vars['LDSHARED'] = re.sub( ' +', ' ', ldshared.replace('-bundle', '-dynamiclib')) extra_compile_args.append('-mmacosx-version-min=10.8') extra_link_args.append('-mmacosx-version-min=10.8') # silence various warnings extra_compile_args.append('-Wno-absolute-value') extra_compile_args.append('-Wno-shift-negative-value') extra_compile_args.append('-Wno-parentheses-equality') extra_compile_args.append('-Wno-deprecated-declarations') else: # Remove the "-Wstrict-prototypes" compiler option that swig adds, which isn't valid for C++. cfg_vars = sysconfig.get_config_vars() for key, value in cfg_vars.items():
def finalize_options(self): from distutils import sysconfig self.set_undefined_options('build', ('build_lib', 'build_lib'), ('build_temp', 'build_temp'), ('compiler', 'compiler'), ('debug', 'debug'), ('force', 'force'), ('plat_name', 'plat_name'), ) if self.package is None: self.package = self.distribution.ext_package self.extensions = self.distribution.ext_modules # Make sure Python's include directories (for Python.h, pyconfig.h, # etc.) are in the include search path. py_include = sysconfig.get_python_inc() plat_py_include = sysconfig.get_python_inc(plat_specific=1) if self.include_dirs is None: self.include_dirs = self.distribution.include_dirs or [] if isinstance(self.include_dirs, str): self.include_dirs = self.include_dirs.split(os.pathsep) # Put the Python "system" include dir at the end, so that # any local include dirs take precedence. self.include_dirs.append(py_include) if plat_py_include != py_include: self.include_dirs.append(plat_py_include) self.ensure_string_list('libraries') # Life is easier if we're not forever checking for None, so # simplify these options to empty lists if unset if self.libraries is None: self.libraries = [] if self.library_dirs is None: self.library_dirs = [] elif type(self.library_dirs) is StringType: self.library_dirs = string.split(self.library_dirs, os.pathsep) if self.rpath is None: self.rpath = [] elif type(self.rpath) is StringType: self.rpath = string.split(self.rpath, os.pathsep) # for extensions under windows use different directories # for Release and Debug builds. # also Python's library directory must be appended to library_dirs if os.name == 'nt' and not self.plat_name.startswith(('mingw')): # the 'libs' directory is for binary installs - we assume that # must be the *native* platform. But we don't really support # cross-compiling via a binary install anyway, so we let it go. self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) if self.debug: self.build_temp = os.path.join(self.build_temp, "Debug") else: self.build_temp = os.path.join(self.build_temp, "Release") # Append the source distribution include and library directories, # this allows distutils on windows to work in the source tree self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC')) if MSVC_VERSION == 9: # Use the .lib files for the correct architecture if self.plat_name == 'win32': suffix = '' else: # win-amd64 or win-ia64 suffix = self.plat_name[4:] new_lib = os.path.join(sys.exec_prefix, 'PCbuild') if suffix: new_lib = os.path.join(new_lib, suffix) self.library_dirs.append(new_lib) elif MSVC_VERSION == 8: self.library_dirs.append(os.path.join(sys.exec_prefix, 'PC', 'VS8.0')) elif MSVC_VERSION == 7: self.library_dirs.append(os.path.join(sys.exec_prefix, 'PC', 'VS7.1')) else: self.library_dirs.append(os.path.join(sys.exec_prefix, 'PC', 'VC6')) # OS/2 (EMX) doesn't support Debug vs Release builds, but has the # import libraries in its "Config" subdirectory if os.name == 'os2': self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config')) # for extensions under Cygwin and AtheOS Python's library directory must be # appended to library_dirs if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos' or self.plat_name.startswith(('mingw')): if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")): # building third party extensions config_dir_name = os.path.basename(sysconfig.get_config_var('LIBPL')) self.library_dirs.append(os.path.join(sys.prefix, "lib", "python" + get_python_version(), config_dir_name)) else: # building python standard extensions self.library_dirs.append('.') # For building extensions with a shared Python library, # Python's library directory must be appended to library_dirs # See Issues: #1600860, #4366 if (sysconfig.get_config_var('Py_ENABLE_SHARED')): if not sysconfig.python_build: # building third party extensions self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) else: # building python standard extensions self.library_dirs.append('.') # The argument parsing will result in self.define being a string, but # it has to be a list of 2-tuples. All the preprocessor symbols # specified by the 'define' option will be set to '1'. Multiple # symbols can be separated with commas. if self.define: defines = self.define.split(',') self.define = map(lambda symbol: (symbol, '1'), defines) # The option for macros to undefine is also a string from the # option parsing, but has to be a list. Multiple symbols can also # be separated with commas here. if self.undef: self.undef = self.undef.split(',') if self.swig_opts is None: self.swig_opts = [] else: self.swig_opts = self.swig_opts.split(' ') # Finally add the user include and library directories if requested if self.user: user_include = os.path.join(USER_BASE, "include") user_lib = os.path.join(USER_BASE, "lib") if os.path.isdir(user_include): self.include_dirs.append(user_include) if os.path.isdir(user_lib): self.library_dirs.append(user_lib) self.rpath.append(user_lib)
from distutils import sysconfig import sys print("; ".join("py%s=%r" % (k, v) for k, v in sorted( { 'exe': sys.executable, 'prefix': getattr(sys, "base_prefix", sys.prefix), 'version': sysconfig.get_python_version(), 'include': sysconfig.get_python_inc(prefix=''), 'ldlib': sysconfig.get_config_var('LDLIBRARY'), 'py3lib': sysconfig.get_config_var('PY3LIBRARY'), 'stdlib': sysconfig.get_python_lib(standard_lib=1, prefix=''), 'purelib': sysconfig.get_python_lib(plat_specific=0, prefix=''), 'platlib': sysconfig.get_python_lib(plat_specific=1, prefix=''), }.items())))