def set_platform_directories(): """Initialise the global variables relating to platform specific directories. """ global plat_py_site_dir, plat_py_inc_dir, plat_py_conf_inc_dir global plat_bin_dir, plat_py_lib_dir, plat_sip_dir # We trust distutils for some stuff. plat_py_site_dir = sysconfig.get_python_lib(plat_specific=1) plat_py_inc_dir = sysconfig.get_python_inc() plat_py_conf_inc_dir = os.path.dirname(sysconfig.get_config_h_filename()) if sys.platform == "win32": if sysconfig.python_build: try: plat_py_lib_dir = sysconfig.project_base + '\\PCBuild' except AttributeError: plat_py_lib_dir = sysconfig.get_python_inc() + '\\..\\pcbuild' else: plat_py_lib_dir = sys.prefix + "\\libs" plat_bin_dir = sys.exec_prefix plat_sip_dir = sys.prefix + "\\sip" else: lib_dir = sysconfig.get_python_lib(plat_specific=1, standard_lib=1) plat_py_lib_dir = lib_dir + "/config" plat_bin_dir = sys.exec_prefix + "/bin" plat_sip_dir = sys.prefix + "/share/sip"
def check_config_h(): """Check if the current Python installation (specifically, pyconfig.h) appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: CONFIG_H_OK all is well, go ahead and compile CONFIG_H_NOTOK doesn't look good CONFIG_H_UNCERTAIN not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". """ from distutils import sysconfig import string if string.find(sys.version, 'GCC') >= 0: return (CONFIG_H_OK, "sys.version mentions 'GCC'") fn = sysconfig.get_config_h_filename() try: f = open(fn) try: s = f.read() finally: f.close() except IOError as exc: return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)) if string.find(s, '__GNUC__') >= 0: return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn) else: return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
def set_platform_directories(): """Initialise the global variables relating to platform specific directories. """ global plat_py_site_dir, plat_py_inc_dir, plat_py_conf_inc_dir global plat_bin_dir, plat_py_lib_dir, plat_sip_dir # We trust distutils for some stuff. if os.environ.get("CROSS_COMPILE") == "yes": ketlaer = os.environ.get("KETLAER") plat_py_site_dir = ketlaer + "/lib/python2.6/site-packages" plat_py_inc_dir = ketlaer + "/include/python2.6" plat_py_conf_inc_dir = ketlaer + "/include/python2.6" else: plat_py_site_dir = sysconfig.get_python_lib(plat_specific=1) plat_py_inc_dir = sysconfig.get_python_inc() plat_py_conf_inc_dir = os.path.dirname(sysconfig.get_config_h_filename()) if sys.platform == "win32": plat_py_lib_dir = sys.prefix + "\\libs" plat_bin_dir = sys.exec_prefix plat_sip_dir = sys.prefix + "\\sip" else: if os.environ.get("CROSS_COMPILE") == "yes": lib_dir = ketlaer + "/python/lib/python2.6" else: lib_dir = sysconfig.get_python_lib(plat_specific=1, standard_lib=1) plat_py_lib_dir = lib_dir + "/config" plat_bin_dir = sys.exec_prefix + "/bin" plat_sip_dir = sys.prefix + "/share/sip"
def check_config_h(): """Check if the current Python installation appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: - CONFIG_H_OK: all is well, go ahead and compile - CONFIG_H_NOTOK: doesn't look good - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". """ from distutils import sysconfig if 'GCC' in sys.version: return CONFIG_H_OK, "sys.version mentions 'GCC'" fn = sysconfig.get_config_h_filename() try: config_h = open(fn) try: if '__GNUC__' in config_h.read(): return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn else: return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn finally: config_h.close() except OSError as exc: return CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)
def test_parse_config_h(self): config_h = sysconfig.get_config_h_filename() input = {} with open(config_h, encoding="utf-8") as f: result = sysconfig.parse_config_h(f, g=input) self.assertTrue(input is result) with open(config_h, encoding="utf-8") as f: result = sysconfig.parse_config_h(f) self.assertTrue(isinstance(result, dict))
def check_config_h(): """Check if the current Python installation (specifically, pyconfig.h) appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: CONFIG_H_OK all is well, go ahead and compile CONFIG_H_NOTOK doesn't look good CONFIG_H_UNCERTAIN not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". """ # XXX since this function also checks sys.version, it's not strictly a # "pyconfig.h" check -- should probably be renamed... from distutils import sysconfig import string # if sys.version contains GCC then python was compiled with # GCC, and the pyconfig.h file should be OK if string.find(sys.version,"GCC") >= 0: return (CONFIG_H_OK, "sys.version mentions 'GCC'") fn = sysconfig.get_config_h_filename() try: # It would probably better to read single lines to search. # But we do this only once, and it is fast enough f = open(fn) try: s = f.read() finally: f.close() except IOError as exc: # if we can't read this file, we cannot say it is wrong # the compiler will complain later about this file as missing return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)) else: # "pyconfig.h" contains an "#ifdef __GNUC__" or something similar if string.find(s,"__GNUC__") >= 0: return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn) else: return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
def check_config_h(): """Check if the current Python installation (specifically, pyconfig.h) appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: CONFIG_H_OK all is well, go ahead and compile CONFIG_H_NOTOK doesn't look good CONFIG_H_UNCERTAIN not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". """ # XXX since this function also checks sys.version, it's not strictly a # "pyconfig.h" check -- should probably be renamed... from distutils import sysconfig # if sys.version contains GCC then python was compiled with # GCC, and the pyconfig.h file should be OK if sys.version.find("GCC") >= 0: return (CONFIG_H_OK, "sys.version mentions 'GCC'") fn = sysconfig.get_config_h_filename() try: # It would probably better to read single lines to search. # But we do this only once, and it is fast enough f = open(fn) try: s = f.read() finally: f.close() except IOError as exc: # if we can't read this file, we cannot say it is wrong # the compiler will complain later about this file as missing return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)) else: # "pyconfig.h" contains an "#ifdef __GNUC__" or something similar if s.find("__GNUC__") >= 0: return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn) else: return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
def check_config_h(): """Check if the current Python installation appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: - CONFIG_H_OK: all is well, go ahead and compile - CONFIG_H_NOTOK: doesn't look good - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". """ # XXX since this function also checks sys.version, it's not strictly a # "pyconfig.h" check -- should probably be renamed... from distutils import sysconfig # if sys.version contains GCC then python was compiled with GCC, and the # pyconfig.h file should be OK if "GCC" in sys.version: return CONFIG_H_OK, "sys.version mentions 'GCC'" # Clang would also work if "Clang" in sys.version: return CONFIG_H_OK, "sys.version mentions 'Clang'" # let's see if __GNUC__ is mentioned in python.h fn = sysconfig.get_config_h_filename() try: config_h = open(fn) try: if "__GNUC__" in config_h.read(): return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn else: return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn finally: config_h.close() except OSError as exc: return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror))
def set_platform_directories(): """ Initialise the global variables relating to platform-specific directories. """ global plat_py_site_dir, plat_py_inc_dir, plat_py_venv_inc_dir global plat_py_conf_inc_dir, plat_bin_dir, plat_py_lib_dir, plat_sip_dir # We trust distutils for some stuff. plat_py_site_dir = sysconfig.get_python_lib(plat_specific=1) plat_py_inc_dir = sysconfig.get_python_inc() plat_py_venv_inc_dir = sysconfig.get_python_inc(prefix=sys.prefix) plat_py_conf_inc_dir = os.path.dirname(sysconfig.get_config_h_filename()) if sys.platform == "win32": bin_dir = sys.exec_prefix try: # Python v3.3 and later. base_prefix = sys.base_prefix if sys.exec_prefix != sys.base_exec_prefix: bin_dir += '\\Scripts' except AttributeError: try: # virtualenv for Python v2. base_prefix = sys.real_prefix bin_dir += '\\Scripts' except AttributeError: # We can't detect the base prefix in Python v3 prior to v3.3. base_prefix = sys.prefix plat_py_lib_dir = base_prefix + "\\libs" plat_bin_dir = bin_dir plat_sip_dir = sys.prefix + "\\sip" else: lib_dir = sysconfig.get_python_lib(plat_specific=1, standard_lib=1) plat_py_lib_dir = lib_dir + "/config" plat_bin_dir = sys.exec_prefix + "/bin" plat_sip_dir = sys.prefix + "/share/sip"
def check_config_h(): """Check if the current Python installation appears amenable to building extensions with GCC. Returns a tuple (status, details), where 'status' is one of the following constants: - CONFIG_H_OK: all is well, go ahead and compile - CONFIG_H_NOTOK: doesn't look good - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h 'details' is a human-readable string explaining the situation. Note there are two ways to conclude "OK": either 'sys.version' contains the string "GCC" (implying that this Python was built with GCC), or the installed "pyconfig.h" contains the string "__GNUC__". """ # XXX since this function also checks sys.version, it's not strictly a # "pyconfig.h" check -- should probably be renamed... from distutils import sysconfig # if sys.version contains GCC then python was compiled with GCC, and the # pyconfig.h file should be OK if "GCC" in sys.version: return CONFIG_H_OK, "sys.version mentions 'GCC'" # let's see if __GNUC__ is mentioned in python.h fn = sysconfig.get_config_h_filename() try: config_h = open(fn) try: if "__GNUC__" in config_h.read(): return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn else: return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn finally: config_h.close() except OSError as exc: return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror))
def GetConfigVars(*args): """Parse the installed pyconfig.h file. A dictionary containing name/value pairs is returned. If an optional dictionary is passed in as the second argument, it is used instead of a new dictionary. """ global _config_vars if _config_vars is None: _config_vars = {} filename = sysconfig.get_config_h_filename() try: fp = open(filename) except IOError, err: msg = "invalid Python installation: unable to open %s" % filename if err.strerror: msg += " (%s)" % msg.strerror raise DistutilsPlatformError(msg) try: if sys.version < '2.5': define_rx = re.compile("#define ([A-Z][a-zA-Z0-9_]+) (.*)$") undef_rx = re.compile("/[*] #undef ([A-Z][a-zA-Z0-9_]+) [*]/$") line = fp.readline() while line: m = define_rx.match(line) if m: n, v = m.group(1, 2) try: v = int(v) except ValueError: pass _config_vars[n] = v else: m = undef_rx.match(line) if m: _config_vars[m.group(1)] = 0 line = fp.readline() else: sysconfig.parse_config_h(fp, _config_vars) finally: fp.close()
def check_config_h(): from distutils import sysconfig import string if string.find(sys.version, 'GCC') >= 0: return (CONFIG_H_OK, "sys.version mentions 'GCC'") fn = sysconfig.get_config_h_filename() try: f = open(fn) try: s = f.read() finally: f.close() except IOError as exc: return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror)) if string.find(s, '__GNUC__') >= 0: return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn) else: return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
def sqlalchemyCheck(py2app_cmd, modulegraph): name = 'sqlalchemy' m = modulegraph.findNode(name) if m is None or m.filename is None: return None from distutils.sysconfig import get_config_h_filename import os.path, tempfile def path_components(path): """ Splits a path into a list of all its components """ if not path: return [] tail, head = os.path.split(path) return path_components(tail) + [head] # Get the prefix where python stuff is stored PREFIX = os.path.normpath(sys.prefix) # Figure out there pyconfig is pyconfig_hPath = get_config_h_filename() # Figure out where we want it newPyconfig_hPath = pyconfig_hPath[len(PREFIX) + 1:] # Need the path and name of the file by themselves # FIXME: Make this less crude includePath, pyconfig_h = os.path.split(pyconfig_hPath[len(PREFIX) + 1:]) # A temporary directory that we can pass to py2app to actually include # in the distribution tempInclude = os.path.join(py2app_cmd.temp_dir, includePath) # Make the temporary path, copy the file and let py2app know that it should # be included in the distribution py2app_cmd.mkpath(tempInclude) py2app_cmd.copy_file(pyconfig_hPath, os.path.join(tempInclude, pyconfig_h)) py2app_cmd.resources.append( os.path.join(py2app_cmd.temp_dir, path_components(newPyconfig_hPath)[0])) # Need to import all the database engine bits, or they do not get # included in the distribution # FIXME: import everythign? This will of course not import any of the DB # layers, perhaps they are imported if instaled? As the sqlite library # correctly handled by py2app, suggesting that something knows it is needed. modulegraph.import_hook(name + '.databases', m, ['*']) # Need to return a dict so that py2app know that we did stuff return dict()
def set_platform_directories(): """ Initialise the global variables relating to platform-specific directories. """ global plat_py_site_dir, plat_py_inc_dir, plat_py_venv_inc_dir global plat_py_conf_inc_dir, plat_bin_dir, plat_py_lib_dir, plat_sip_dir # We trust distutils for some stuff. plat_py_site_dir = sysconfig.get_python_lib(plat_specific=1) plat_py_inc_dir = sysconfig.get_python_inc() plat_py_venv_inc_dir = sysconfig.get_python_inc(prefix=sys.prefix) plat_py_conf_inc_dir = os.path.dirname(sysconfig.get_config_h_filename()) if sys.platform == "win32": plat_py_lib_dir = sys.prefix + "\\libs" plat_bin_dir = sys.exec_prefix plat_sip_dir = sys.prefix + "\\sip" else: lib_dir = sysconfig.get_python_lib(plat_specific=1, standard_lib=1) plat_py_lib_dir = lib_dir + "/config" plat_bin_dir = sys.exec_prefix + "/bin" plat_sip_dir = sys.prefix + "/share/sip"
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'), ('parallel', 'parallel'), ('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) # If in a virtualenv, add its include directory # Issue 16116 if sys.exec_prefix != sys.base_exec_prefix: self.include_dirs.append(os.path.join(sys.exec_prefix, 'include')) # 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') self.ensure_string_list('link_objects') # 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 isinstance(self.library_dirs, str): self.library_dirs = self.library_dirs.split(os.pathsep) if self.rpath is None: self.rpath = [] elif isinstance(self.rpath, str): self.rpath = self.rpath.split(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': # 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 sys.base_exec_prefix != sys.prefix: # Issue 16116 self.library_dirs.append(os.path.join(sys.base_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 if 0: # pypy has no config_h_filename directory from distutils.sysconfig import get_config_h_filename self.include_dirs.append(os.path.dirname(get_config_h_filename())) _sys_home = getattr(sys, '_home', None) if _sys_home: self.library_dirs.append(_sys_home) # Use the .lib files for the correct architecture if self.plat_name == 'win32': suffix = 'win32' 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) # pypy has no PCBuild directory # self.library_dirs.append(new_lib) # 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 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 = [(symbol, '1') for symbol in 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) if isinstance(self.parallel, str): try: self.parallel = int(self.parallel) except ValueError: raise DistutilsOptionError("parallel should be an integer")
def test_get_config_h_filename(self): config_h = sysconfig.get_config_h_filename() self.assertTrue(os.path.isfile(config_h), config_h)
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) # If in a virtualenv, add its include directory # Issue 16116 if sys.exec_prefix != sys.base_exec_prefix: self.include_dirs.append(os.path.join(sys.exec_prefix, 'include')) # 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 isinstance(self.library_dirs, str): self.library_dirs = self.library_dirs.split(os.pathsep) if self.rpath is None: self.rpath = [] elif isinstance(self.rpath, str): self.rpath = self.rpath.split(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': # 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 sys.base_exec_prefix != sys.prefix: # Issue 16116 self.library_dirs.append(os.path.join(sys.base_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.dirname(get_config_h_filename())) _sys_home = getattr(sys, '_home', None) if _sys_home: self.library_dirs.append(_sys_home) 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')) # 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 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 = [(symbol, '1') for symbol in 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)
# # The full license is in the file COPYING.txt, distributed with this software. #----------------------------------------------------------------------------- # distutils module requires Makefile and pyconfig.h files from Python # installation. import os import sys import time from distutils import sysconfig config_h = sysconfig.get_config_h_filename() print(('pyconfig.h: ' + config_h)) files = [config_h] # On Windows Makefile does not exist. if not sys.platform.startswith('win'): makefile = sysconfig.get_makefile_filename() print(('Makefile: ' + makefile)) files.append(makefile) for f in files: if not os.path.exists(f): raise SystemExit('File does not exist: %s' % f)
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'), ('parallel', 'parallel'), ('plat_name', 'plat_name')) if self.package is None: self.package = self.distribution.ext_package self.extensions = self.distribution.ext_modules 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) if sys.exec_prefix != sys.base_exec_prefix: self.include_dirs.append(os.path.join(sys.exec_prefix, 'include')) self.include_dirs.append(py_include) if plat_py_include != py_include: self.include_dirs.append(plat_py_include) self.ensure_string_list('libraries') self.ensure_string_list('link_objects') if self.libraries is None: self.libraries = [] if self.library_dirs is None: self.library_dirs = [] elif isinstance(self.library_dirs, str): self.library_dirs = self.library_dirs.split(os.pathsep) if self.rpath is None: self.rpath = [] elif isinstance(self.rpath, str): self.rpath = self.rpath.split(os.pathsep) if os.name == 'nt': self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) if sys.base_exec_prefix != sys.prefix: self.library_dirs.append( os.path.join(sys.base_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') self.include_dirs.append(os.path.dirname(get_config_h_filename())) _sys_home = getattr(sys, '_home', None) if _sys_home: self.library_dirs.append(_sys_home) if self.plat_name == 'win32': suffix = 'win32' else: 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) if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos': if sys.executable.startswith(os.path.join(sys.exec_prefix, 'bin')): self.library_dirs.append( os.path.join(sys.prefix, 'lib', 'python' + get_python_version(), 'config')) else: self.library_dirs.append('.') if sysconfig.get_config_var('Py_ENABLE_SHARED'): if not sysconfig.python_build: self.library_dirs.append(sysconfig.get_config_var('LIBDIR')) else: self.library_dirs.append('.') if self.define: defines = self.define.split(',') self.define = [(symbol, '1') for symbol in defines] 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(' ') 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) if isinstance(self.parallel, str): try: self.parallel = int(self.parallel) except ValueError: raise DistutilsOptionError('parallel should be an integer')
def test_get_config_h_filename(self): config_h = sysconfig.get_config_h_filename() self.assert_(os.path.isfile(config_h), config_h)
go. self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs')) if sys.base_exec_prefix != sys.prefix: # Issue 16116 self.library_dirs.append(os.path.join(sys.base_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.dirname(get_config_h_filename())) self.library_dirs.append(sys.base_exec_prefix) # Use the .lib files for the correct architecture if self.plat_name == 'win32': suffix = 'win32' else: # win-amd64 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) # For extensions under Cygwin, Python's library directory must be # appended to library_dirs
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 isinstance(self.library_dirs, str): self.library_dirs = self.library_dirs.split(os.pathsep) if self.rpath is None: self.rpath = [] elif isinstance(self.rpath, str): self.rpath = self.rpath.split(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": # 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.dirname(get_config_h_filename())) _sys_home = getattr(sys, "_home", None) if _sys_home: self.library_dirs.append(_sys_home) 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": 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 or Solaris with a shared Python library, # Python's library directory must be appended to library_dirs sysconfig.get_config_var("Py_ENABLE_SHARED") if sys.platform.startswith(("linux", "gnu", "sunos")) 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 = self.define.split(",") self.define = [(symbol, "1") for symbol in 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)
return copy_file_orig(src, dst, *args, **kwargs) def copy_tree(*args, **kwargs): outputs = copy_tree_orig(*args, **kwargs) for i in range(len(outputs)): if outputs[i].endswith("bin/smart.py"): outputs[i] = outputs[i][:-3] return outputs distutils.file_util.copy_file = copy_file distutils.dir_util.copy_tree = copy_tree # Some Python sysconfig use different directories for different prefixes EXEC_PREFIX = get_config_var('exec_prefix') PYTHONLIB = get_python_lib(plat_specific=1, standard_lib=0, prefix=EXEC_PREFIX).replace(EXEC_PREFIX+os.sep, "") config_h = sysconfig.get_config_h_filename() config_h_vars = sysconfig.parse_config_h(open(config_h)) ext_modules = [ Extension("smart.ccache", ["smart/ccache.c"]), Extension("smart.backends.rpm.crpmver", ["smart/backends/rpm/crpmver.c"]), Extension("smart.backends.deb.cdebver", ["smart/backends/deb/cdebver.c"]), Extension("smart.backends.deb._base", ["smart/backends/deb/_base.c"]), Extension("smart.util.ctagfile", ["smart/util/ctagfile.c"]), Extension("smart.util.cdistance", ["smart/util/cdistance.c"]) ]
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 isinstance(self.library_dirs, str): self.library_dirs = self.library_dirs.split(os.pathsep) if self.rpath is None: self.rpath = [] elif isinstance(self.rpath, str): self.rpath = self.rpath.split(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': # 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.dirname(get_config_h_filename())) _sys_home = getattr(sys, '_home', None) if _sys_home: self.library_dirs.append(_sys_home) 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': 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 or Solaris with a shared Python library, # Python's library directory must be appended to library_dirs sysconfig.get_config_var('Py_ENABLE_SHARED') if (sys.platform.startswith(('linux', 'gnu', 'sunos')) 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 = self.define.split(',') self.define = [(symbol, '1') for symbol in 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)
if sys.platform == "win32": # HAVE_MEMMOVE is not in PC/pyconfig.h define_macros.extend([ ('HAVE_MEMMOVE', '1'), ('XML_STATIC', ''), ]) include_dirs = ['extensions/expat/lib'] sources.extend([ 'extensions/expat/lib/xmlparse.c', 'extensions/expat/lib/xmlrole.c', 'extensions/expat/lib/xmltok.c', ]) libraries = [] library_dirs = [] config_h = get_config_h_filename() config_h_vars = parse_config_h(open(config_h)) for feature_macro in ['HAVE_MEMMOVE', 'HAVE_BCOPY']: if config_h_vars.has_key(feature_macro): define_macros.append((feature_macro, '1')) ext_modules.append( Extension(xml('.parsers.pyexpat'), define_macros=define_macros, include_dirs=include_dirs, library_dirs=library_dirs, libraries=libraries, extra_link_args=LDFLAGS, sources=sources ))
"""distutils.cygwinccompiler