예제 #1
0
def check_extensions():
    print(__file__)
    # This assumes pybuilddir.txt is in same directory as pyconfig.h.
    # In the case of out-of-tree builds, we can't assume pybuilddir.txt is
    # in the source folder.
    config_dir = os.path.dirname(sysconfig.get_config_h_filename())
    filename = os.path.join(config_dir, "pybuilddir.txt")
    try:
        with open(filename, encoding="utf-8") as fp:
            pybuilddir = fp.readline()
    except FileNotFoundError:
        print(f"Cannot check extensions because {filename} does not exist")
        return True

    print(f"Check extension modules from {pybuilddir} directory")
    builddir = os.path.join(config_dir, pybuilddir)
    nsymbol = 0
    for name in os.listdir(builddir):
        if not name.endswith(".so"):
            continue
        if IGNORED_EXTENSION in name:
            print()
            print(f"Ignore extension: {name}")
            continue

        print()
        filename = os.path.join(builddir, name)
        nsymbol += check_library(filename, dynamic=True)

    return nsymbol
예제 #2
0
def copy_python_framework(info, dst):
    # XXX - In this particular case we know exactly what we can
    #       get away with.. should this be extended to the general
    #       case?  Per-framework recipes?
    indir = os.path.dirname(os.path.join(info["location"], info["name"]))
    outdir = os.path.dirname(os.path.join(dst, info["name"]))
    mkpath(os.path.join(outdir, "Resources"))
    # Since python 3.2, the naming scheme for config files location has considerably
    # complexified. The old, simple way doesn't work anymore. Fortunately, a new module was
    # added to get such paths easily.

    # It's possible that virtualenv is messing with us here, so we only use the rightmost part of
    # each of the two paths below. For pyconfig_path, it's the last 3 elements of the path
    # (include/python3.2m/pyconfig.h) and for makefile_path it's the last 4
    # (lib/python3.2/config-3.2m/Makefile). Yes, this kind of location can change depending on the
    # platform, but we're only supporting Mac OS X eh? We'll take these last path parts and append
    # them to indir and we'll have our non-virtualenv paths.
    pyconfig_path = sysconfig.get_config_h_filename()
    makefile_path = sysconfig.get_makefile_filename()
    pyconfig_path = op.join(*pyconfig_path.split(os.sep)[-3:])
    makefile_path = op.join(*makefile_path.split(os.sep)[-4:])
    assert pyconfig_path.startswith("include")
    assert makefile_path.startswith("lib")

    # distutils looks for some files relative to sys.executable, which
    # means they have to be in the framework...
    mkpath(op.join(outdir, op.dirname(pyconfig_path)))
    mkpath(op.join(outdir, op.dirname(makefile_path)))
    fmwkfiles = [os.path.basename(info["name"]), "Resources/Info.plist", pyconfig_path, makefile_path]
    for fn in fmwkfiles:
        copy_file(os.path.join(indir, fn), os.path.join(outdir, fn))
예제 #3
0
 def test_get_config_h_filename(self):
     config_h = sysconfig.get_config_h_filename()
     # import_module skips the test when the CPython C Extension API
     # appears to not be supported
     self.assertTrue(
         os.path.isfile(config_h) or not import_module('_testcapi'),
         config_h)
예제 #4
0
def main():
    target = os.path.dirname(sysconfig.get_config_h_filename())

    try:
        source = os.readlink(target)
    except:
        print(target,
              "is not a symlink. Perhaps this script has already been run.")
        sys.exit(1)

    tmp = target + ".tmp"

    if os.path.exists(tmp):
        shutil.rmtree(tmp)

    os.mkdir(tmp)

    for i in os.listdir(source):
        if i == "pygame_sdl2":
            continue

        os.symlink(os.path.join(source, i), os.path.join(tmp, i))

    os.unlink(target)
    os.rename(tmp, target)
예제 #5
0
    def init_inc_lib_dirs(self):
        if (not CROSS_COMPILING and os.path.normpath(sys.base_prefix) != '/usr'
                and not sysconfig.get_config_var('PYTHONFRAMEWORK')):
            # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
            # (PYTHONFRAMEWORK is set) to avoid # linking problems when
            # building a framework with different architectures than
            # the one that is currently installed (issue #7473)
            add_dir_to_list(self.compiler.library_dirs,
                            sysconfig.get_config_var("LIBDIR"))
            add_dir_to_list(self.compiler.include_dirs,
                            sysconfig.get_config_var("INCLUDEDIR"))

        system_lib_dirs = ['/lib64', '/usr/lib64', '/lib', '/usr/lib']
        system_include_dirs = ['/usr/include']
        # lib_dirs and inc_dirs are used to search for files;
        # if a file is found in one of those directories, it can
        # be assumed that no additional -I,-L directives are needed.
        if not CROSS_COMPILING:
            self.lib_dirs = self.compiler.library_dirs + system_lib_dirs
            self.inc_dirs = self.compiler.include_dirs + system_include_dirs
        else:
            # Add the sysroot paths. 'sysroot' is a compiler option used to
            # set the logical path of the standard system headers and
            # libraries.
            self.lib_dirs = (self.compiler.library_dirs + sysroot_paths(
                ('LDFLAGS', 'CC'), system_lib_dirs))
            self.inc_dirs = (self.compiler.include_dirs + sysroot_paths(
                ('CPPFLAGS', 'CFLAGS', 'CC'), system_include_dirs))

        config_h = sysconfig.get_config_h_filename()
        with open(config_h) as file:
            self.config_h_vars = sysconfig.parse_config_h(file)

        # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
        if HOST_PLATFORM in ['osf1', 'unixware7', 'openunix8']:
            self.lib_dirs += ['/usr/ccs/lib']

        # HP-UX11iv3 keeps files in lib/hpux folders.
        if HOST_PLATFORM == 'hp-ux11':
            self.lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']

        if MACOS:
            # This should work on any unixy platform ;-)
            # If the user has bothered specifying additional -I and -L flags
            # in OPT and LDFLAGS we might as well use them here.
            #
            # NOTE: using shlex.split would technically be more correct, but
            # also gives a bootstrap problem. Let's hope nobody uses
            # directories with whitespace in the name to store libraries.
            cflags, ldflags = sysconfig.get_config_vars('CFLAGS', 'LDFLAGS')
            for item in cflags.split():
                if item.startswith('-I'):
                    self.inc_dirs.append(item[2:])

            for item in ldflags.split():
                if item.startswith('-L'):
                    self.lib_dirs.append(item[2:])
예제 #6
0
def get_config_h_filename():
    """Return full pathname of installed pyconfig.h file."""
    if python_build:
        if os.name == "nt":
            inc_dir = os.path.join(_sys_home or project_base, "PC")
        else:
            inc_dir = _sys_home or project_base
        return os.path.join(inc_dir, 'pyconfig.h')
    else:
        return sysconfig.get_config_h_filename()
예제 #7
0
    def build_executable(self, target, copyexts, script):
        # Build an executable for the target
        appdir, resdir, plist = self.create_bundle(target, script)
        self.appdir = appdir
        self.opts.plist = plist

        for src, dest in self.iter_data_files():
            dest = os.path.join(resdir, dest)
            mkpath(os.path.dirname(dest))
            copy_resource(src, dest, dry_run=self.opts.dry_run)

        bootfn = '__boot__'
        bootfile = open(os.path.join(resdir, bootfn + '.py'), 'w')
        for fn in target.prescripts:
            bootfile.write(get_bootstrap_data(fn))
            bootfile.write('\n\n')
        bootfile.write('_run(%r)\n' % (os.path.basename(script), ))
        bootfile.close()

        copy_file(script, resdir)
        pydir = os.path.join(resdir, 'lib', 'python' + sys.version[:3])
        mkpath(pydir)
        force_symlink('../../site.py', os.path.join(pydir, 'site.py'))
        realcfg = os.path.dirname(sysconfig.get_makefile_filename())
        cfgdir = os.path.join(resdir, os.path.relpath(realcfg, sys.prefix))
        mkpath(cfgdir)
        for fn in 'Makefile', 'Setup', 'Setup.local', 'Setup.config':
            rfn = os.path.join(realcfg, fn)
            if os.path.exists(rfn):
                copy_file(rfn, os.path.join(cfgdir, fn))

        # see copy_python_framework() for explanation.
        pyconfig_path = sysconfig.get_config_h_filename()
        pyconfig_path_relative = os.path.relpath(
            os.path.dirname(pyconfig_path), sys.prefix)
        inc_dir = os.path.join(resdir, pyconfig_path_relative)
        mkpath(inc_dir)
        copy_file(pyconfig_path, os.path.join(inc_dir, 'pyconfig.h'))

        copy_tree(self.folders.collect_dir, pydir)

        ext_dir = os.path.join(pydir, os.path.basename(self.folders.ext_dir))
        copy_tree(self.folders.ext_dir, ext_dir, preserve_symlinks=True)
        copy_tree(self.folders.framework_dir,
                  os.path.join(appdir, 'Contents', 'Frameworks'),
                  preserve_symlinks=True)
        for pkg in self.opts.packages:
            pkg = get_bootstrap(pkg)
            dst = os.path.join(pydir, os.path.basename(pkg))
            mkpath(dst)
            copy_tree(pkg, dst)
        self.copyexts(copyexts, ext_dir)

        target.appdir = appdir
        return appdir
예제 #8
0
    def build_executable(self, target, copyexts, script):
        # Build an executable for the target
        appdir, resdir, plist = self.create_bundle(target, script)
        self.appdir = appdir
        self.opts.plist = plist

        for src, dest in self.iter_data_files():
            dest = os.path.join(resdir, dest)
            mkpath(os.path.dirname(dest))
            copy_resource(src, dest, dry_run=self.opts.dry_run)

        bootfn = "__boot__"
        bootfile = open(os.path.join(resdir, bootfn + ".py"), "w")
        for fn in target.prescripts:
            bootfile.write(get_bootstrap_data(fn))
            bootfile.write("\n\n")
        bootfile.write("_run(%r)\n" % (os.path.basename(script),))
        bootfile.close()

        copy_file(script, resdir)
        pydir = os.path.join(resdir, "lib", "python" + sys.version[:3])
        mkpath(pydir)
        force_symlink("../../site.py", os.path.join(pydir, "site.py"))
        realcfg = os.path.dirname(sysconfig.get_makefile_filename())
        cfgdir = os.path.join(resdir, os.path.relpath(realcfg, sys.prefix))
        mkpath(cfgdir)
        for fn in "Makefile", "Setup", "Setup.local", "Setup.config":
            rfn = os.path.join(realcfg, fn)
            if os.path.exists(rfn):
                copy_file(rfn, os.path.join(cfgdir, fn))

        # see copy_python_framework() for explanation.
        pyconfig_path = sysconfig.get_config_h_filename()
        pyconfig_path_relative = os.path.relpath(os.path.dirname(pyconfig_path), sys.prefix)
        inc_dir = os.path.join(resdir, pyconfig_path_relative)
        mkpath(inc_dir)
        copy_file(pyconfig_path, os.path.join(inc_dir, "pyconfig.h"))

        copy_tree(self.folders.collect_dir, pydir)

        ext_dir = os.path.join(pydir, os.path.basename(self.folders.ext_dir))
        copy_tree(self.folders.ext_dir, ext_dir, preserve_symlinks=True)
        copy_tree(self.folders.framework_dir, os.path.join(appdir, "Contents", "Frameworks"), preserve_symlinks=True)
        for pkg in self.opts.packages:
            pkg = get_bootstrap(pkg)
            dst = os.path.join(pydir, os.path.basename(pkg))
            mkpath(dst)
            copy_tree(pkg, dst)
        self.copyexts(copyexts, ext_dir)

        target.appdir = appdir
        return appdir
예제 #9
0
def copy_sysconfig_files_for_embed(destpath):
    # This normally shouldn't be needed for Python 3.3+.
    makefile = sysconfig.get_makefile_filename()
    configh = sysconfig.get_config_h_filename()
    shutil.copy(makefile, destpath)
    shutil.copy(configh, destpath)
    with open(op.join(destpath, 'site.py'), 'w') as fp:
        fp.write("""
import os.path as op
from distutils import sysconfig
sysconfig.get_makefile_filename = lambda: op.join(op.dirname(__file__), 'Makefile')
sysconfig.get_config_h_filename = lambda: op.join(op.dirname(__file__), 'pyconfig.h')
""")
예제 #10
0
def build_cocoa(dev):
    build_localizations()
    build_cocoa_proxy_module()
    build_cocoa_bridging_interfaces()

    app_version = get_module_version('core')
    cocoa_project_path = 'cocoa'
    filereplace(op.join(cocoa_project_path, 'InfoTemplate.plist'),
                op.join('build', 'Info.plist'),
                version=app_version)
    copy_embeddable_python_dylib('build')
    if not op.exists('build/PythonHeaders'):
        os.symlink(op.dirname(sysconfig.get_config_h_filename()),
                   'build/PythonHeaders')
    build_help()

    pydep_folder = op.join('build', 'py')
    if not op.exists(pydep_folder):
        os.mkdir(pydep_folder)
    shutil.copy(op.join(cocoa_project_path, 'dg_cocoa.py'), 'build')
    tocopy = [
        'dupeguru/core',
        'dupeguru/hscommon',
        'cocoa/inter',
        'cocoalib/cocoa',
        'objp',
        'send2trash',
        'hsaudiotag',
    ]
    copy_packages(tocopy, pydep_folder, create_links=dev)
    sys.path.insert(0, 'build')
    # ModuleFinder can't seem to correctly detect the multiprocessing dependency, so we have
    # to manually specify it.
    extra_deps = ['multiprocessing']
    collect_stdlib_dependencies('build/dg_cocoa.py',
                                pydep_folder,
                                extra_deps=extra_deps)
    del sys.path[0]
    # Views are not referenced by python code, so they're not found by the collector.
    copy_all('build/inter/*.so', op.join(pydep_folder, 'inter'))
    if not dev:
        # Important: Don't ever run delete_files_with_pattern('*.py') on dev builds because you'll
        # be deleting all py files in symlinked folders.
        compileall.compile_dir(pydep_folder, force=True, legacy=True)
        delete_files_with_pattern(pydep_folder, '*.py')
        delete_files_with_pattern(pydep_folder, '__pycache__')

    print_and_do('xcodebuild')
예제 #11
0
파일: test_venv.py 프로젝트: nirs/cpython
 def test_sysconfig_symlinks(self):
     """
     Test that the sysconfig functions work in a virtual environment.
     """
     rmtree(self.env_dir)
     self.run_with_capture(venv.create, self.env_dir, symlinks=True)
     envpy = os.path.join(self.env_dir, self.bindir, self.exe)
     cmd = [envpy, '-c', None]
     for call, expected in (
         # installation scheme
         ('get_preferred_scheme("prefix")', 'venv'),
         ('get_default_scheme()', 'venv'),
         # build environment
         ('is_python_build()', str(sysconfig.is_python_build())),
         ('get_makefile_filename()', sysconfig.get_makefile_filename()),
         ('get_config_h_filename()', sysconfig.get_config_h_filename())):
         with self.subTest(call):
             cmd[2] = 'import sysconfig; print(sysconfig.%s)' % call
             out, err = check_output(cmd)
             self.assertEqual(out.strip(), expected.encode(), err)
예제 #12
0
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...
    # 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 IOError, exc:
        return (CONFIG_H_UNCERTAIN,
                "couldn't read '%s': %s" % (fn, exc.strerror))
예제 #13
0
def main():
    target = os.path.dirname(sysconfig.get_config_h_filename())

    try:
        source = os.readlink(target)
    except:
        print(target, "is not a symlink. Perhaps this script has already been run.")
        sys.exit(1)

    tmp = target + ".tmp"

    if os.path.exists(tmp):
        shutil.rmtree(tmp)

    os.mkdir(tmp)

    for i in os.listdir(source):
        if i == "pygame_sdl2":
            continue

        os.symlink(os.path.join(source, i), os.path.join(tmp, i))

    os.unlink(target)
    os.rename(tmp, target)
예제 #14
0
def copy_python_framework(info, dst):
    # XXX - In this particular case we know exactly what we can
    #       get away with.. should this be extended to the general
    #       case?  Per-framework recipes?
    indir = os.path.dirname(os.path.join(info['location'], info['name']))
    outdir = os.path.dirname(os.path.join(dst, info['name']))
    mkpath(os.path.join(outdir, 'Resources'))
    # Since python 3.2, the naming scheme for config files location has considerably
    # complexified. The old, simple way doesn't work anymore. Fortunately, a new module was
    # added to get such paths easily.

    # It's possible that virtualenv is messing with us here, so we only use the rightmost part of
    # each of the two paths below. For pyconfig_path, it's the last 3 elements of the path
    # (include/python3.2m/pyconfig.h) and for makefile_path it's the last 4
    # (lib/python3.2/config-3.2m/Makefile). Yes, this kind of location can change depending on the
    # platform, but we're only supporting Mac OS X eh? We'll take these last path parts and append
    # them to indir and we'll have our non-virtualenv paths.
    pyconfig_path = sysconfig.get_config_h_filename()
    makefile_path = sysconfig.get_makefile_filename()
    pyconfig_path = op.join(*pyconfig_path.split(os.sep)[-3:])
    makefile_path = op.join(*makefile_path.split(os.sep)[-4:])
    assert pyconfig_path.startswith('include')
    assert makefile_path.startswith('lib')

    # distutils looks for some files relative to sys.executable, which
    # means they have to be in the framework...
    mkpath(op.join(outdir, op.dirname(pyconfig_path)))
    mkpath(op.join(outdir, op.dirname(makefile_path)))
    fmwkfiles = [
        os.path.basename(info['name']),
        'Resources/Info.plist',
        pyconfig_path,
        makefile_path,
    ]
    for fn in fmwkfiles:
        copy_file(os.path.join(indir, fn), os.path.join(outdir, fn))
예제 #15
0
    def update_sources_depends(self):
        # Fix up the autodetected modules, prefixing all the source files
        # with Modules/.
        # Add dependencies from MODULE_{name}_DEPS variable
        moddirlist = [
            # files in Modules/ directory
            os.path.join(self.srcdir, 'Modules'),
            # files relative to build base, e.g. libmpdec.a, libexpat.a
            os.getcwd()
        ]

        # Python header files
        include_dir = escape(sysconfig.get_path('include'))
        headers = [sysconfig.get_config_h_filename()]
        headers.extend(glob(os.path.join(include_dir, "*.h")))
        headers.extend(glob(os.path.join(include_dir, "cpython", "*.h")))
        headers.extend(glob(os.path.join(include_dir, "internal", "*.h")))

        for ext in self.extensions:
            ext.sources = [
                find_module_file(filename, moddirlist)
                for filename in ext.sources
            ]
            # Update dependencies from Makefile
            makedeps = sysconfig.get_config_var(
                f"MODULE_{ext.name.upper()}_DEPS")
            if makedeps:
                # remove backslashes from line break continuations
                ext.depends.extend(dep for dep in makedeps.split()
                                   if dep != "\\")
            ext.depends = [
                find_module_file(filename, moddirlist)
                for filename in ext.depends
            ]
            # re-compile extensions if a header file has been changed
            ext.depends.extend(headers)
예제 #16
0
# Copyright (c) 2005-2021, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------

# distutils module requires Makefile and pyconfig.h files from Python
# installation.

import os
import sys
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)
예제 #17
0
print(sysconfig.get_config_var('LIBDIR'))

print(sysconfig.get_config_vars('posix_home', 'prefix'))

print(sysconfig.get_config_vars())

print(sysconfig.get_scheme_names())
"""
stdlib: directory containing the standard Python library files that are not platform-specific.
platstdlib: directory containing the standard Python library files that are platform-specific.
platlib: directory for site-specific, platform-specific files.
purelib: directory for site-specific, non-platform-specific files.
include: directory for non-platform-specific header files.
platinclude: directory for platform-specific header files.
scripts: directory for script files.
data: directory for data files.
"""
print(sysconfig.get_path_names())

print(sysconfig.get_path("data"))

print(sysconfig.get_paths("nt"))

print(sysconfig.get_python_version())

print(sysconfig.get_platform())
print(sysconfig.is_python_build())
print(sysconfig.get_config_h_filename())
print(sysconfig.get_makefile_filename())
예제 #18
0
파일: nodes.py 프로젝트: xxoolm/Ryven
 def update_event(self, inp=-1):
     self.set_output_val(0, sysconfig.get_config_h_filename())
예제 #19
0
    def build_extensions(self):

        # Detect which modules should be compiled
        old_so = self.compiler.shared_lib_extension
        # Workaround PEP 3149 stuff
        self.compiler.shared_lib_extension = os.environ.get("SO", ".so")
        try:
            missing = self.detect_modules()
        finally:
            self.compiler.shared_lib_extension = old_so

        # Remove modules that are present on the disabled list
        extensions = [
            ext for ext in self.extensions
            if ext.name not in disabled_module_list
        ]
        # move ctypes to the end, it depends on other modules
        ext_map = dict((ext.name, i) for i, ext in enumerate(extensions))
        if "_ctypes" in ext_map:
            ctypes = extensions.pop(ext_map["_ctypes"])
            extensions.append(ctypes)
        self.extensions = extensions

        # Fix up the autodetected modules, prefixing all the source files
        # with Modules/.
        srcdir = sysconfig.get_config_var('srcdir')
        if not srcdir:
            # Maybe running on Windows but not using CYGWIN?
            raise ValueError("No source directory; cannot proceed.")
        srcdir = os.path.abspath(srcdir)
        moddirlist = [os.path.join(srcdir, 'Modules')]

        # Fix up the paths for scripts, too
        self.distribution.scripts = [
            os.path.join(srcdir, filename)
            for filename in self.distribution.scripts
        ]

        # Python header files
        headers = [sysconfig.get_config_h_filename()]
        headers += glob(os.path.join(sysconfig.get_path('include'), "*.h"))

        for ext in self.extensions[:]:
            ext.sources = [
                find_module_file(filename, moddirlist)
                for filename in ext.sources
            ]
            if ext.depends is not None:
                ext.depends = [
                    find_module_file(filename, moddirlist)
                    for filename in ext.depends
                ]
            else:
                ext.depends = []
            # re-compile extensions if a header file has been changed
            ext.depends.extend(headers)

            # If a module has already been built statically,
            # don't build it here
            if ext.name in sys.builtin_module_names:
                self.extensions.remove(ext)

        # Parse Modules/Setup to figure out which
        # modules are turned on in the file.
        remove_modules = []
        for filename in ('Modules/Setup', ):
            input = text_file.TextFile(filename, join_lines=1)
            while 1:
                line = input.readline()
                if not line: break
                line = line.split()
                remove_modules.append(line[0])
            input.close()

        for ext in self.extensions[:]:
            if ext.name in remove_modules:
                self.extensions.remove(ext)

        # When you run "make CC=altcc" or something similar, you really want
        # those environment variables passed into the setup.py phase.  Here's
        # a small set of useful ones.
        compiler = os.environ.get('CC')
        args = {}
        # unfortunately, distutils doesn't let us provide separate C and C++
        # compilers
        if compiler is not None:
            (ccshared, cppflags, cflags) = \
                sysconfig.get_config_vars('CCSHARED', 'CPPFLAGS', 'CFLAGS')
            cppflags = ' '.join(
                [f for f in cppflags.split() if not f.startswith('-I')])
            args[
                'compiler_so'] = compiler + ' ' + ccshared + ' ' + cppflags + ' ' + cflags
        self.compiler.set_executables(**args)

        build_ext.build_extensions(self)

        longest = max([len(e.name) for e in self.extensions])
        if self.failed:
            longest = max(longest, max([len(name) for name in self.failed]))

        def print_three_column(lst):
            lst.sort(key=str.lower)
            # guarantee zip() doesn't drop anything
            while len(lst) % 3:
                lst.append("")
            for e, f, g in zip(lst[::3], lst[1::3], lst[2::3]):
                print("%-*s   %-*s   %-*s" %
                      (longest, e, longest, f, longest, g))

        if missing:
            print()
            print("Python build finished, but the necessary bits to build "
                  "these modules were not found:")
            print_three_column(missing)
            print("To find the necessary bits, look in setup.py in"
                  " detect_modules() for the module's name.")
            print()

        if self.failed:
            failed = self.failed[:]
            print()
            print("Failed to build these modules:")
            print_three_column(failed)
            print()
예제 #20
0
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------

# The 'sysconfig' module requires Makefile and pyconfig.h files from
# Python installation. 'sysconfig' parses these files to get some
# information from them.
# TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3.

import sysconfig
import os

from PyInstaller.utils.hooks import relpath_to_config_or_make
from PyInstaller.compat import is_win

_CONFIG_H = sysconfig.get_config_h_filename()
_MAKEFILE = sysconfig.get_makefile_filename()

datas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))]

# The Makefile does not exist on all platforms, eg. on Windows
if os.path.exists(_MAKEFILE):
    datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))

if not is_win and hasattr(sysconfig, '_get_sysconfigdata_name'):
    # Python 3.6 uses additional modules like
    # `_sysconfigdata_m_linux_x86_64-linux-gnu`, see
    # https://github.com/python/cpython/blob/3.6/Lib/sysconfig.py#L417
    # Note: Some versions of Anaconda backport this feature to before 3.6.
    # See issue #3105
    hiddenimports = [sysconfig._get_sysconfigdata_name()]
예제 #21
0
 def test_get_config_h_filename(self):
     config_h = sysconfig.get_config_h_filename()
     self.assertTrue(os.path.isfile(config_h), config_h)
예제 #22
0
def get_python_header_folder():
    return op.dirname(sysconfig.get_config_h_filename())
예제 #23
0
#Custom Properties:
#scene.hzg_file_name - name of zip file to write
#object.hzg_type - type of object to be populated by the reading program
#	- Defaults to "ENTITY"
#	- GEO_MIPMAP - Used for terrain geometry
#   - UI_ELEMENT - Drawn in the same position in front of the camera as UI elements
#   - INPUT_AREA - Polygons drawn over UI area to detect input 
#object.hzg_export_mode - how to export the data for this object
#	- V   - Write tightly packed vertex position data, no normals or texture coordinates (VVV)
#	- VC  - Write Vertex position and Texture Coordinates in VVVCC format.
#	- VNC - Write packed Vertex/Normal/TexCoord data in VVVNNNCC format
#object.hzg_round - integer, how many places to round decimals
#object.hzg_texture - texture name to use

import sysconfig
print(sysconfig.get_config_h_filename())

import bpy
import bmesh
import zipfile
import struct
import sys
import os
import mathutils
from scipy.spatial import ConvexHull

try:
    import zlib
    compression = zipfile.ZIP_DEFLATED
except:
    compression = zipfile.ZIP_STORED
예제 #24
0
 def test_get_config_h_filename(self):
     config_h = sysconfig.get_config_h_filename()
     self.assertTrue(os.path.isfile(config_h), config_h)
예제 #25
0
# coding=utf-8
# 使用sysconfig

import sysconfig

print sysconfig.get_config_var('Py_ENABLE_SHARED')
print sysconfig.get_config_var('LIBDIR')
print sysconfig.get_config_vars('AR', "CXX")

print sysconfig.get_scheme_names()
print sysconfig.get_path_names()

print sysconfig.get_python_version()
print sysconfig.get_platform()

# return true if current python installation was built from source
print sysconfig.is_python_build()

print sysconfig.get_config_h_filename()
print sysconfig._get_makefile_filename()
예제 #26
0
if cross_compiling:
    def _cross_cfg():
        ret = os.path.join(os.environ["PYTHONSRC"], "pyconfig.h")
        ret = os.path.abspath(ret)
        return ret

    sysconfig.get_config_h_filename = _cross_cfg

    for override in (
                     # ('CC', ),
                     # ('HOST_GNU_TYPE', ),
                     ('EXT_SUFFIX', ),
                     # ('SO', os.environ["EXT_SUFFIX"]),
                     ('srcdir',
                      os.path.dirname(sysconfig.get_config_h_filename())),
                     ):
        if len(override) == 1:
            v = override[0]
            v = os.environ[v]
        else:
            v = override[1]
        sysconfig.get_config_vars()[override[0]] = v

    for override in (
                     ('EXT_SUFFIX', ),
                     ('SOABI', ),
                     ):
        if len(override) == 1:
            v = override[0]
            v = os.environ[v]
예제 #27
0
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------

# Test standard module sysconfig (new in Python 2.7 and Python 3.2)

import os
import sys
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'):
    try:
        get_makefile_filename = sysconfig.get_makefile_filename
    except AttributeError:
        # In Python 2.7, get_makefile_filename was private
        get_makefile_filename = sysconfig._get_makefile_filename
    makefile = get_makefile_filename()
    print('Makefile: ' + makefile)
    files.append(makefile)
예제 #28
0
class FakeFile(file):
    """File sub-class that enforces the restrictions of production."""

    # A fake Enum b/c the enum package isn't available.
    class Visibility(object):
        """Visibility of the file to the sandboxed code.

    Visibility.OK is accessible; other values say why it's not accessible.
    """
        OK = 0
        CACHED_BLOCK = 1
        SKIP_BLOCK = 2
        STATIC_BLOCK = 3
        PATH_BLOCK = 4
        WRITE_BLOCK = 5

    ALLOWED_MODES = frozenset(['r', 'rb', 'U', 'rU'])

    # Individual files that are allowed to be accessed.
    ALLOWED_FILES = set(
        os.path.normcase(filename) for filename in mimetypes.knownfiles
        if os.path.isfile(filename))

    # Directories which are allowed to be accessed. All sub-directories are
    # also allowed.
    ALLOWED_DIRS = set([
        os.path.normcase(os.path.realpath(os.path.dirname(os.__file__))),
        os.path.normcase(os.path.abspath(os.path.dirname(os.__file__))),
        os.path.normcase(os.path.dirname(os.path.realpath(os.__file__))),
        os.path.normcase(os.path.dirname(os.path.abspath(os.__file__))),
    ])
    os_source_location = inspect.getsourcefile(os)
    # inspect.getsource may return None if it cannot find the os.py file.
    if os_source_location is not None:
        # Whitelist source file location to allow virtualenv to work.
        # This is necessary because the compiled bytecode may be in a different
        # location to the source code.
        ALLOWED_DIRS.update([
            os.path.normcase(
                os.path.realpath(os.path.dirname(os_source_location))),
            os.path.normcase(
                os.path.abspath(os.path.dirname(os_source_location))),
            os.path.normcase(
                os.path.dirname(os.path.realpath(os_source_location))),
            os.path.normcase(
                os.path.dirname(os.path.abspath(os_source_location))),
        ])

    # sysconfig requires access to config.h.
    if sysconfig:
        ALLOWED_DIRS.add(os.path.dirname(sysconfig.get_config_h_filename()))

    # Configuration - set_allowed_paths must be called to initialize them.
    _allowed_dirs = None  # List of accessible paths.
    _writeable_dirs = None  # Set of writeable paths

    # Configuration - set_skip_files must be called to initialize it.
    _skip_files = None  # Regex of skip files.
    # Configuration - set_static_files must be called to initialize it.
    _static_files = None  # Regex of static files.

    # Cache for results of is_file_accessible, {absolute filename: Boolean}
    _availability_cache = {}
    _availability_cache_lock = threading.Lock()

    @staticmethod
    def set_allowed_paths(root_path, application_paths, temp_path=None):
        """Configures which paths are allowed to be accessed.

    Must be called at least once before any file objects are created in the
    hardened environment.

    Args:
      root_path: Absolute path to the root of the application.
      application_paths: List of additional paths that the application may
        access, this must include the App Engine runtime but not the Python
        library directories.
      temp_path: Temporary root folder; writing to this folder will be allowed.
    """
        # Use os.path.realpath to flush out symlink-at-root issues.
        # (Deeper symlinks will not use realpath.)
        _application_paths = (
            set(os.path.realpath(path) for path in application_paths)
            | set(os.path.abspath(path) for path in application_paths))
        FakeFile._root_path = os.path.normcase(os.path.abspath(root_path))
        _application_paths.add(FakeFile._root_path)
        FakeFile._allowed_dirs = _application_paths | FakeFile.ALLOWED_DIRS

        FakeFile._writeable_dirs = set()
        if temp_path:
            FakeFile._writeable_dirs.add(temp_path)

        with FakeFile._availability_cache_lock:
            FakeFile._availability_cache = {}

    @staticmethod
    def set_skip_files(skip_files):
        """Configure the skip_files regex.

    Files that match this regex are inaccessible in the hardened environment.
    Must be called at least once before any file objects are created in the
    hardened environment.

    Args:
      skip_files: A str containing a regex to match against file paths.
    """
        FakeFile._skip_files = re.compile(skip_files)
        with FakeFile._availability_cache_lock:
            FakeFile._availability_cache = {}

    @staticmethod
    def set_static_files(static_files):
        """Configure the static_files regex.

    Files that match this regex are inaccessible in the hardened environment.
    Must be called at least once before any file objects are created in the
    hardened environment.

    Args:
      static_files: A str containing a regex to match against file paths.
    """
        FakeFile._static_files = re.compile(static_files)
        with FakeFile._availability_cache_lock:
            FakeFile._availability_cache = {}

    @staticmethod
    def is_file_accessible(filename, for_write=False):
        """Determines if a file is accessible.

    set_allowed_paths(), set_skip_files() and SetStaticFileConfigMatcher() must
    be called before this method or else all file accesses will raise an error.

    Args:
      filename: Path of the file to check (relative or absolute). May be a
        directory, in which case access for files inside that directory will
        be checked.
      for_write: If true, only include writeable files/directories.

    Returns:
      The visibility of the file. Visibility.OK means it's visible; other
      values describe why it isn't.

    Raises:
      TypeError: filename is not a basestring.
    """
        if not isinstance(filename, basestring):
            raise TypeError()
        # Blindly follow symlinks here. DO NOT use os.path.realpath. This approach
        # enables the application developer to create symlinks in their
        # application directory to any additional libraries they want to use.
        fixed_filename = os.path.normcase(os.path.abspath(filename))

        # Some of the access checks are expensive as they look through a list of
        # regular expressions for a match.  As long as app.yaml isn't changed the
        # answer will always be the same as it's only depending on the filename and
        # the configuration, not on which files do exist or not.
        cache_key = (fixed_filename, for_write)
        with FakeFile._availability_cache_lock:
            cached_result = FakeFile._availability_cache.get(cache_key)
        if cached_result is False:
            return FakeFile.Visibility.CACHED_BLOCK
        elif cached_result is True:
            return FakeFile.Visibility.OK
        assert cached_result is None, 'Unexpected value in availability cache'
        visibility = FakeFile.Visibility.OK
        if for_write:
            # Checking write access: Allow only _writeable_dirs
            if not _is_path_in_directories(fixed_filename,
                                           FakeFile._writeable_dirs):
                visibility = FakeFile.Visibility.WRITE_BLOCK
        else:
            # Checking read access: Allow only whitelisted files and dirs
            if not (fixed_filename in FakeFile.ALLOWED_FILES
                    or _is_path_in_directories(
                        fixed_filename,
                        FakeFile._allowed_dirs | FakeFile._writeable_dirs)):
                visibility = FakeFile.Visibility.PATH_BLOCK

            # Also exclude skipped or static files within the app
            if (_is_path_in_directories(fixed_filename, [FakeFile._root_path])
                    and fixed_filename != FakeFile._root_path):
                relative_filename = fixed_filename[len(FakeFile._root_path
                                                       ):].lstrip(os.path.sep)
                if FakeFile._skip_files.match(relative_filename):
                    visibility = FakeFile.Visibility.SKIP_BLOCK
                elif FakeFile._static_files.match(relative_filename):
                    visibility = FakeFile.Visibility.STATIC_BLOCK

        with FakeFile._availability_cache_lock:
            FakeFile._availability_cache[cache_key] = (
                visibility == FakeFile.Visibility.OK)
        return visibility

    def __init__(self, filename, mode='r', bufsize=-1, **kwargs):
        """Initializer. See file built-in documentation."""
        check_for_write = mode not in FakeFile.ALLOWED_MODES
        accessible = FakeFile.is_file_accessible(filename, check_for_write)
        if accessible != FakeFile.Visibility.OK:
            log_access_check_fail(filename, accessible)
            if accessible == FakeFile.Visibility.WRITE_BLOCK:
                raise IOError(errno.EROFS, 'Read-only file system', filename)
            raise IOError(errno.EACCES, 'file not accessible', filename)

        super(FakeFile, self).__init__(filename, mode, bufsize, **kwargs)
예제 #29
0
#-----------------------------------------------------------------------------

"""
`distutils`-specific post-import hook.

This hook freezes the external `Makefile` and `pyconfig.h` files bundled with
the active Python interpreter, which the `distutils.sysconfig` module parses at
runtime for platform-specific metadata.
"""

# TODO Verify that bundling Makefile and pyconfig.h is still required for Python 3.

import os
import sysconfig

from PyInstaller.utils.hooks import relpath_to_config_or_make

_CONFIG_H = sysconfig.get_config_h_filename()
if hasattr(sysconfig, 'get_makefile_filename'):
    # sysconfig.get_makefile_filename is missing in Python < 2.7.9
    _MAKEFILE = sysconfig.get_makefile_filename()
else:
    _MAKEFILE = sysconfig._get_makefile_filename()

# Data files in PyInstaller hook format.
datas = [(_CONFIG_H, relpath_to_config_or_make(_CONFIG_H))]

# The Makefile does not exist on all platforms, eg. on Windows
if os.path.exists(_MAKEFILE):
    datas.append((_MAKEFILE, relpath_to_config_or_make(_MAKEFILE)))
예제 #30
0
class FakeFile(file):
    """File sub-class that enforces the restrictions of production."""

    ALLOWED_MODES = frozenset(['r', 'rb', 'U', 'rU'])

    # Individual files that are allowed to be accessed.
    ALLOWED_FILES = set(
        os.path.normcase(filename) for filename in mimetypes.knownfiles
        if os.path.isfile(filename))

    # Directories which are allowed to be accessed. All sub-directories are
    # also allowed.
    ALLOWED_DIRS = set([
        os.path.normcase(os.path.realpath(os.path.dirname(os.__file__))),
        os.path.normcase(os.path.abspath(os.path.dirname(os.__file__))),
        os.path.normcase(os.path.dirname(os.path.realpath(os.__file__))),
        os.path.normcase(os.path.dirname(os.path.abspath(os.__file__))),
    ])
    os_source_location = inspect.getsourcefile(os)
    # inspect.getsource may return None if it cannot find the os.py file.
    if os_source_location is not None:
        # Whitelist source file location to allow virtualenv to work.
        # This is necessary because the compiled bytecode may be in a different
        # location to the source code.
        ALLOWED_DIRS.update([
            os.path.normcase(
                os.path.realpath(os.path.dirname(os_source_location))),
            os.path.normcase(
                os.path.abspath(os.path.dirname(os_source_location))),
            os.path.normcase(
                os.path.dirname(os.path.realpath(os_source_location))),
            os.path.normcase(
                os.path.dirname(os.path.abspath(os_source_location))),
        ])

    # sysconfig requires access to config.h.
    if sysconfig:
        ALLOWED_DIRS.add(os.path.dirname(sysconfig.get_config_h_filename()))

    # Configuration - set_allowed_paths must be called to initialize them.
    _allowed_dirs = None  # List of accessible paths.

    # Configuration - set_skip_files must be called to initialize it.
    _skip_files = None  # Regex of skip files.
    # Configuration - set_static_files must be called to initialize it.
    _static_files = None  # Regex of static files.

    # Cache for results of is_file_accessible, {absolute filename: Boolean}
    _availability_cache = {}
    _availability_cache_lock = threading.Lock()

    @staticmethod
    def set_allowed_paths(root_path, application_paths):
        """Configures which paths are allowed to be accessed.

    Must be called at least once before any file objects are created in the
    hardened environment.

    Args:
      root_path: Absolute path to the root of the application.
      application_paths: List of additional paths that the application may
        access, this must include the App Engine runtime but not the Python
        library directories.
    """
        # Use os.path.realpath to flush out symlink-at-root issues.
        # (Deeper symlinks will not use realpath.)
        _application_paths = (
            set(os.path.realpath(path) for path in application_paths)
            | set(os.path.abspath(path) for path in application_paths))
        FakeFile._root_path = os.path.normcase(os.path.abspath(root_path))
        _application_paths.add(FakeFile._root_path)
        FakeFile._allowed_dirs = _application_paths | FakeFile.ALLOWED_DIRS

        with FakeFile._availability_cache_lock:
            FakeFile._availability_cache = {}

    @staticmethod
    def set_skip_files(skip_files):
        """Configure the skip_files regex.

    Files that match this regex are inaccessible in the hardened environment.
    Must be called at least once before any file objects are created in the
    hardened environment.

    Args:
      skip_files: A str containing a regex to match against file paths.
    """
        FakeFile._skip_files = re.compile(skip_files)
        with FakeFile._availability_cache_lock:
            FakeFile._availability_cache = {}

    @staticmethod
    def set_static_files(static_files):
        """Configure the static_files regex.

    Files that match this regex are inaccessible in the hardened environment.
    Must be called at least once before any file objects are created in the
    hardened environment.

    Args:
      static_files: A str containing a regex to match against file paths.
    """
        FakeFile._static_files = re.compile(static_files)
        with FakeFile._availability_cache_lock:
            FakeFile._availability_cache = {}

    @staticmethod
    def is_file_accessible(filename):
        """Determines if a file is accessible.

    set_allowed_paths(), set_skip_files() and SetStaticFileConfigMatcher() must
    be called before this method or else all file accesses will raise an error.

    Args:
      filename: Path of the file to check (relative or absolute). May be a
        directory, in which case access for files inside that directory will
        be checked.

    Returns:
      True if the file is accessible, False otherwise.

    Raises:
      TypeError: filename is not a basestring.
    """
        if not isinstance(filename, basestring):
            raise TypeError()
        # Blindly follow symlinks here. DO NOT use os.path.realpath. This approach
        # enables the application developer to create symlinks in their
        # application directory to any additional libraries they want to use.
        fixed_filename = os.path.normcase(os.path.abspath(filename))

        # Some of the access checks are expensive as they look through a list of
        # regular expressions for a match.  As long as app.yaml isn't changed the
        # answer will always be the same as it's only depending on the filename and
        # the configuration, not on which files do exist or not.
        with FakeFile._availability_cache_lock:
            result = FakeFile._availability_cache.get(fixed_filename)
        if result is None:
            if (_is_path_in_directories(fixed_filename, [FakeFile._root_path])
                    and fixed_filename != FakeFile._root_path):
                relative_filename = fixed_filename[len(FakeFile._root_path
                                                       ):].lstrip(os.path.sep)
                block_access = (
                    FakeFile._skip_files.match(relative_filename)
                    or FakeFile._static_files.match(relative_filename))
            else:
                block_access = False
            result = not block_access and (
                fixed_filename in FakeFile.ALLOWED_FILES
                or _is_path_in_directories(fixed_filename,
                                           FakeFile._allowed_dirs))
            with FakeFile._availability_cache_lock:
                FakeFile._availability_cache[fixed_filename] = result
        return result

    def __init__(self, filename, mode='r', bufsize=-1, **kwargs):
        """Initializer. See file built-in documentation."""
        if mode not in FakeFile.ALLOWED_MODES:
            raise IOError(errno.EROFS, 'Read-only file system', filename)

        if not FakeFile.is_file_accessible(filename):
            raise IOError(errno.EACCES, 'file not accessible', filename)

        super(FakeFile, self).__init__(filename, mode, bufsize, **kwargs)
예제 #31
0
 def test_get_config_h_filename(self):
     config_h = sysconfig.get_config_h_filename()
     # import_module skips the test when the CPython C Extension API
     # appears to not be supported
     self.assertTrue(os.path.isfile(config_h) or
                     not import_module('_testcapi'), config_h)
# coding=utf-8
# 使用sysconfig

import sysconfig

print sysconfig.get_config_var('Py_ENABLE_SHARED')
print sysconfig.get_config_var('LIBDIR')
print sysconfig.get_config_vars('AR', "CXX")


print sysconfig.get_scheme_names()
print sysconfig.get_path_names()

print sysconfig.get_python_version()
print sysconfig.get_platform()

# return true if current python installation was built from source
print sysconfig.is_python_build()

print sysconfig.get_config_h_filename()
print sysconfig._get_makefile_filename()
예제 #33
0
def get_python_header_folder():
    return op.dirname(sysconfig.get_config_h_filename())
예제 #34
0
    def detect_modules(self):
        # On Debian /usr/local is always used, so we don't include it twice
        # only change this for cross builds for 3.3, issues on Mageia
        if cross_compiling:
            self.add_gcc_paths()
        self.add_multiarch_paths()

        # Add paths specified in the environment variables LDFLAGS and
        # CPPFLAGS for header and library files.
        # We must get the values from the Makefile and not the environment
        # directly since an inconsistently reproducible issue comes up where
        # the environment variable is not set even though the value were passed
        # into configure and stored in the Makefile (issue found on OS X 10.3).
        for env_var, arg_name, dir_list in (
            ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
            ('LDFLAGS', '-L', self.compiler.library_dirs),
            ('CPPFLAGS', '-I', self.compiler.include_dirs)):
            env_val = sysconfig.get_config_var(env_var)
            if env_val:
                # To prevent optparse from raising an exception about any
                # options in env_val that it doesn't know about we strip out
                # all double dashes and any dashes followed by a character
                # that is not for the option we are dealing with.
                #
                # Please note that order of the regex is important!  We must
                # strip out double-dashes first so that we don't end up with
                # substituting "--Long" to "-Long" and thus lead to "ong" being
                # used for a library directory.
                env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], ' ',
                                 env_val)
                parser = optparse.OptionParser()
                # Make sure that allowing args interspersed with options is
                # allowed
                parser.allow_interspersed_args = True
                parser.error = lambda msg: None
                parser.add_option(arg_name, dest="dirs", action="append")
                options = parser.parse_args(env_val.split())[0]
                if options.dirs:
                    for directory in reversed(options.dirs):
                        add_dir_to_list(dir_list, directory)

        if os.path.normpath(sys.base_prefix) != '/usr' \
                and not sysconfig.get_config_var('PYTHONFRAMEWORK'):
            # OSX note: Don't add LIBDIR and INCLUDEDIR to building a framework
            # (PYTHONFRAMEWORK is set) to avoid # linking problems when
            # building a framework with different architectures than
            # the one that is currently installed (issue #7473)
            add_dir_to_list(self.compiler.library_dirs,
                            sysconfig.get_config_var("LIBDIR"))
            add_dir_to_list(self.compiler.include_dirs,
                            sysconfig.get_config_var("INCLUDEDIR"))

        # lib_dirs and inc_dirs are used to search for files;
        # if a file is found in one of those directories, it can
        # be assumed that no additional -I,-L directives are needed.
        if not cross_compiling:
            lib_dirs = self.compiler.library_dirs + [
                '/lib64',
                '/usr/lib64',
                '/lib',
                '/usr/lib',
            ]
            inc_dirs = self.compiler.include_dirs + ['/usr/include']
        else:
            lib_dirs = self.compiler.library_dirs[:]
            inc_dirs = self.compiler.include_dirs[:]
        exts = []
        missing = []

        config_h = sysconfig.get_config_h_filename()
        with open(config_h) as file:
            config_h_vars = sysconfig.parse_config_h(file)

        srcdir = sysconfig.get_config_var('srcdir')

        # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
        if host_platform in ['osf1', 'unixware7', 'openunix8']:
            lib_dirs += ['/usr/ccs/lib']

        # HP-UX11iv3 keeps files in lib/hpux folders.
        if host_platform == 'hp-ux11':
            lib_dirs += ['/usr/lib/hpux64', '/usr/lib/hpux32']

        if host_platform == 'darwin':
            # This should work on any unixy platform ;-)
            # If the user has bothered specifying additional -I and -L flags
            # in OPT and LDFLAGS we might as well use them here.
            #
            # NOTE: using shlex.split would technically be more correct, but
            # also gives a bootstrap problem. Let's hope nobody uses
            # directories with whitespace in the name to store libraries.
            cflags, ldflags = sysconfig.get_config_vars('CFLAGS', 'LDFLAGS')
            for item in cflags.split():
                if item.startswith('-I'):
                    inc_dirs.append(item[2:])

            for item in ldflags.split():
                if item.startswith('-L'):
                    lib_dirs.append(item[2:])

        # Check for MacOS X, which doesn't need libm.a at all
        math_libs = ['m']
        if host_platform == 'darwin':
            math_libs = []

        # XXX Omitted modules: gl, pure, dl, SGI-specific modules

        # Anthony Baxter's gdbm module.  GNU dbm(3) will require -lgdbm:
        if (True or 'gdbm' in dbm_order
                and self.compiler.find_library_file(lib_dirs, 'gdbm')):
            exts.append(
                Extension('_gdbm', ['Modules/_gdbmmodule.c'],
                          libraries=['gdbm']))
        else:
            missing.append('_gdbm')

        self.extensions.extend(exts)

        # Call the method for detecting whether _tkinter can be compiled
        self.detect_tkinter(inc_dirs, lib_dirs)

        if '_tkinter' not in [e.name for e in self.extensions]:
            missing.append('_tkinter')

        return missing
예제 #35
0
파일: setup.py 프로젝트: davinirjr/pglib
def _get_settings():

    version = get_version()

    settings = { 'define_macros' : [ ('PGLIB_VERSION', version) ] }

    # This isn't the best or right way to do this, but I don't see how someone is supposed to sanely subclass the build
    # command.
    for option in ['assert', 'trace', 'leak-check']:
        try:
            sys.argv.remove('--%s' % option)
            settings['define_macros'].append(('PGLIB_%s' % option.replace('-', '_').upper(), 1))
        except ValueError:
            pass

    if os.name == 'nt':
        settings['extra_compile_args'] = ['/Wall',
                                          '/wd4668',
                                          '/wd4820',
                                          '/wd4711', # function selected for automatic inline expansion
                                          '/wd4100', # unreferenced formal parameter
                                          '/wd4127', # "conditional expression is constant" testing compilation constants
                                          '/wd4191', # casts to PYCFunction which doesn't have the keywords parameter
                                          ]

        if '--debug' in sys.argv:
            # TODO: The build command already has debug. Pass it in.
            sys.argv.remove('--debug')
            settings['extra_compile_args'].extend('/Od /Ge /GS /GZ /RTC1 /Wp64 /Yd'.split())

        settings['libraries'] = ['libpq', 'Ws2_32']


    elif sys.platform == 'darwin':
        # Apple is not making it easy for non-Xcode builds.  We'll always build with the latest
        # SDK we can find but we'll set the version we are targeting to the same one that
        # Python was built with.

        sdkpath = _get_osx_sdkpath()

        settings['include_dirs'] = [
            join(sdkpath, 'usr', 'include'),
            abspath(dirname(sysconfig.get_config_h_filename().strip())),
            subprocess.check_output(['pg_config', '--includedir']).strip().decode('utf-8')
        ]
        settings['library_dirs'] = [ subprocess.check_output(['pg_config', '--libdir']).strip().decode('utf-8') ]
        settings['libraries']    = ['pq']

        settings['define_macros'].append( ('MAC_OS_X_VERSION_10_7',) )

        settings['extra_compile_args'] = ['-Wall']


    else:
        # Other posix-like: Linux, Solaris, etc.

        settings['include_dirs'] = [ subprocess.check_output(['pg_config', '--includedir']).strip().decode('utf-8') ]
        settings['library_dirs'] = [ subprocess.check_output(['pg_config', '--libdir']).strip().decode('utf-8') ]
        settings['libraries']    = ['pq']

        # Python functions take a lot of 'char *' that really should be const.  gcc complains about this *a lot*
        settings['extra_compile_args'] = ['-Wno-write-strings']

    return settings
예제 #36
0
    def detect_modules(self):
        # Ensure that /usr/local is always used
        # On Debian /usr/local is always used, so we don't include it twice
        #add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
        #add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')

        # Add paths specified in the environment variables LDFLAGS and
        # CPPFLAGS for header and library files.
        # We must get the values from the Makefile and not the environment
        # directly since an inconsistently reproducible issue comes up where
        # the environment variable is not set even though the value were passed
        # into configure and stored in the Makefile (issue found on OS X 10.3).
        for env_var, arg_name, dir_list in (
            ('LDFLAGS', '-R', self.compiler.runtime_library_dirs),
            ('LDFLAGS', '-L', self.compiler.library_dirs),
            ('CPPFLAGS', '-I', self.compiler.include_dirs)):
            env_val = sysconfig.get_config_var(env_var)
            if env_val:
                # To prevent optparse from raising an exception about any
                # options in env_val that it doesn't know about we strip out
                # all double dashes and any dashes followed by a character
                # that is not for the option we are dealing with.
                #
                # Please note that order of the regex is important!  We must
                # strip out double-dashes first so that we don't end up with
                # substituting "--Long" to "-Long" and thus lead to "ong" being
                # used for a library directory.
                env_val = re.sub(r'(^|\s+)-(-|(?!%s))' % arg_name[1], ' ',
                                 env_val)
                parser = optparse.OptionParser()
                # Make sure that allowing args interspersed with options is
                # allowed
                parser.allow_interspersed_args = True
                parser.error = lambda msg: None
                parser.add_option(arg_name, dest="dirs", action="append")
                options = parser.parse_args(env_val.split())[0]
                if options.dirs:
                    for directory in reversed(options.dirs):
                        add_dir_to_list(dir_list, directory)

        if os.path.normpath(sys.prefix) != '/usr':
            add_dir_to_list(self.compiler.library_dirs,
                            sysconfig.get_config_var("LIBDIR"))
            add_dir_to_list(self.compiler.include_dirs,
                            sysconfig.get_config_var("INCLUDEDIR"))

        try:
            have_unicode = unicode
        except NameError:
            have_unicode = 0

        # lib_dirs and inc_dirs are used to search for files;
        # if a file is found in one of those directories, it can
        # be assumed that no additional -I,-L directives are needed.
        gnu_triplet = os.popen(
            'dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null || dpkg-architecture -qDEB_HOST_GNU_TYPE'
        ).readline()[:-1]
        lib_dirs = self.compiler.library_dirs + [
            os.path.join('/lib', gnu_triplet),
            os.path.join('/usr/lib', gnu_triplet),
            '/lib',
            '/usr/lib',
        ]
        inc_dirs = self.compiler.include_dirs + ['/usr/include']
        inc_dirs.append(os.path.join('/usr/include', gnu_triplet))
        exts = []
        missing = []

        config_h = sysconfig.get_config_h_filename()
        config_h_vars = sysconfig.parse_config_h(open(config_h))

        platform = self.get_platform()
        srcdir = sysconfig.get_config_var('srcdir')

        # Check for AtheOS which has libraries in non-standard locations
        if platform == 'atheos':
            lib_dirs += ['/system/libs', '/atheos/autolnk/lib']
            lib_dirs += os.getenv('LIBRARY_PATH', '').split(os.pathsep)
            inc_dirs += ['/system/include', '/atheos/autolnk/include']
            inc_dirs += os.getenv('C_INCLUDE_PATH', '').split(os.pathsep)

        # OSF/1 and Unixware have some stuff in /usr/ccs/lib (like -ldb)
        if platform in ['osf1', 'unixware7', 'openunix8']:
            lib_dirs += ['/usr/ccs/lib']

        if platform == 'darwin':
            # This should work on any unixy platform ;-)
            # If the user has bothered specifying additional -I and -L flags
            # in OPT and LDFLAGS we might as well use them here.
            #   NOTE: using shlex.split would technically be more correct, but
            # also gives a bootstrap problem. Let's hope nobody uses directories
            # with whitespace in the name to store libraries.
            cflags, ldflags = sysconfig.get_config_vars('CFLAGS', 'LDFLAGS')
            for item in cflags.split():
                if item.startswith('-I'):
                    inc_dirs.append(item[2:])

            for item in ldflags.split():
                if item.startswith('-L'):
                    lib_dirs.append(item[2:])

        # Check for MacOS X, which doesn't need libm.a at all
        math_libs = ['m']
        if platform in ['darwin', 'beos']:
            math_libs = []

        # XXX Omitted modules: gl, pure, dl, SGI-specific modules

        #
        # The following modules are all pretty straightforward, and compile
        # on pretty much any POSIXish platform.
        #

        dbm_order = ['gdbm']
        # Anthony Baxter's gdbm module.  GNU dbm(3) will require -lgdbm:
        if ('gdbm' in dbm_order
                and self.compiler.find_library_file(lib_dirs, 'gdbm')):
            exts.append(
                Extension('gdbm', ['Modules/gdbmmodule.c'],
                          libraries=['gdbm']))
        else:
            missing.append('gdbm')

        self.extensions.extend(exts)

        # Call the method for detecting whether _tkinter can be compiled
        self.detect_tkinter(inc_dirs, lib_dirs)

        if '_tkinter' not in [e.name for e in self.extensions]:
            missing.append('_tkinter')

        return missing