コード例 #1
0
ファイル: BDistInno.py プロジェクト: H1d3r/binary_blobs
    def finalize_options(self):
        if self.bdist_dir is None:
            bdist_base = self.get_finalized_command('bdist').bdist_base
            self.bdist_dir = os.path.join(bdist_base, 'inno')

        self.set_undefined_options('bdist',
                                   ('keep_temp', 'keep_temp'),
                                   ('dist_dir', 'dist_dir'),
                                   ('skip_build', 'skip_build'))

        if not self.target_version:
            self.target_version = get_python_version()
        if not self.skip_build and (self.distribution.has_ext_modules() or
                                    self.distribution.has_scripts()):
            short_version = get_python_version()
            if self.target_version != short_version:
                raise DistutilsOptionError(
                    "target version can only be %s, or the '--skip_build'"
                    " option must be specified" % short_version)
            self.target_version = short_version

        self.license_file = self.distribution.license_file
        if self.license_file:
            self.license_file = util.convert_path(self.license_file)

        self.output_basename = '%s.win32'
        return
コード例 #2
0
ファイル: setup.py プロジェクト: pressel/mpi4py
def configure_pyexe(exe, config_cmd):
    from distutils import sysconfig
    if sys.platform.startswith('win'):
        return
    if (sys.platform == 'darwin' and
        ('Anaconda' in sys.version or
         'Continuum Analytics' in sys.version)):
        py_version = sysconfig.get_python_version()
        py_abiflags = getattr(sys, 'abiflags', '')
        exe.libraries += ['python' + py_version + py_abiflags]
        return
    #
    from distutils.util import split_quoted
    cfg_vars = sysconfig.get_config_vars()
    libraries = []
    library_dirs = []
    link_args = []
    if not sysconfig.get_config_var('Py_ENABLE_SHARED'):
        py_version = sysconfig.get_python_version()
        py_abiflags = getattr(sys, 'abiflags', '')
        libraries = ['python' + py_version + py_abiflags]
    if sys.platform == 'darwin':
        fwkdir = cfg_vars.get('PYTHONFRAMEWORKDIR')
        if (fwkdir and fwkdir != 'no-framework' and
            fwkdir in cfg_vars.get('LINKFORSHARED', '')):
            del libraries[:]
    for var in ('LIBDIR', 'LIBPL'):
        library_dirs += split_quoted(cfg_vars.get(var, ''))
    for var in ('LDFLAGS',
                'LIBS', 'MODLIBS', 'SYSLIBS',
                'LDLAST'):
        link_args += split_quoted(cfg_vars.get(var, ''))
    exe.libraries += libraries
    exe.library_dirs += library_dirs
    exe.extra_link_args += link_args
コード例 #3
0
ファイル: build.py プロジェクト: aimylios/calibre
def init_env():
    from setup.build_environment import msvc, is64bit, win_inc, win_lib, NMAKE
    from distutils import sysconfig
    linker = None
    if isunix:
        cc = os.environ.get('CC', 'gcc')
        cxx = os.environ.get('CXX', 'g++')
        debug = ''
        # debug = '-ggdb'
        cflags = os.environ.get('OVERRIDE_CFLAGS',
            '-Wall -DNDEBUG %s -fno-strict-aliasing -pipe' % debug)
        cflags = shlex.split(cflags) + ['-fPIC']
        ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall')
        ldflags = shlex.split(ldflags)
        cflags += shlex.split(os.environ.get('CFLAGS', ''))
        ldflags += shlex.split(os.environ.get('LDFLAGS', ''))
        cflags += ['-fvisibility=hidden']

    if islinux:
        cflags.append('-pthread')
        ldflags.append('-shared')
        cflags.append('-I'+sysconfig.get_python_inc())
        ldflags.append('-lpython'+sysconfig.get_python_version())

    if isbsd:
        cflags.append('-pthread')
        ldflags.append('-shared')
        cflags.append('-I'+sysconfig.get_python_inc())
        ldflags.append('-lpython'+sysconfig.get_python_version())

    if ishaiku:
        cflags.append('-lpthread')
        ldflags.append('-shared')
        cflags.append('-I'+sysconfig.get_python_inc())
        ldflags.append('-lpython'+sysconfig.get_python_version())

    if isosx:
        cflags.append('-D_OSX')
        ldflags.extend('-bundle -undefined dynamic_lookup'.split())
        cflags.extend(['-fno-common', '-dynamic'])
        cflags.append('-I'+sysconfig.get_python_inc())

    if iswindows:
        cc = cxx = msvc.cc
        cflags = '/c /nologo /MD /W3 /EHsc /DNDEBUG'.split()
        ldflags = '/DLL /nologo /INCREMENTAL:NO /NODEFAULTLIB:libcmt.lib'.split()
        # cflags = '/c /nologo /Ox /MD /W3 /EHsc /Zi'.split()
        # ldflags = '/DLL /nologo /INCREMENTAL:NO /DEBUG'.split()
        if is64bit:
            cflags.append('/GS-')

        for p in win_inc:
            cflags.append('-I'+p)
        for p in win_lib:
            ldflags.append('/LIBPATH:'+p)
        cflags.append('-I%s'%sysconfig.get_python_inc())
        ldflags.append('/LIBPATH:'+os.path.join(sysconfig.PREFIX, 'libs'))
        linker = msvc.linker
    return namedtuple('Environment', 'cc cxx cflags ldflags linker make')(
        cc=cc, cxx=cxx, cflags=cflags, ldflags=ldflags, linker=linker, make=NMAKE if iswindows else 'make')
コード例 #4
0
    def run(self):
        """Run the distutils command"""
        log.info("installing library code to %s" % self.bdist_dir)
        
        self.dist_name = get_dist_name(self.distribution,
                                       source_only_dist=True,
                                       python_version=get_python_version()[0])
        self.dist_target = os.path.join(self.dist_dir, self.dist_name)
        log.info("distribution will be available as '%s'" % self.dist_target)
        
        # build command: just to get the build_base
        cmdbuild = self.get_finalized_command("build")
        self.build_base = cmdbuild.build_base
        
        # install command
        install = self.reinitialize_command('install_lib',
                                            reinit_subcommands=1)
        install.compile = False
        install.warn_dir = 0
        install.install_dir = self.bdist_dir
        
        log.info("installing to %s" % self.bdist_dir)
        self.run_command('install_lib')

        # install extra files
        extra_files = {
            'version.py': os.path.join(
                self.bdist_dir, os.path.normpath('mysql/connector/version.py')),
        }
        for src, dest in extra_files.items():
            self.copy_file(src, dest)
        
        # install_egg_info command
        cmd_egginfo = self.get_finalized_command('install_egg_info')
        cmd_egginfo.install_dir = self.bdist_dir
        self.run_command('install_egg_info')
        # we need the py2.x converted to py2 in the filename
        old_egginfo = cmd_egginfo.get_outputs()[0]
        new_egginfo = old_egginfo.replace(
            '-py' + sys.version[:3],
            '-py' + get_python_version()[0])
        move_file(old_egginfo, new_egginfo)
        
        # create distribution
        info_files = [
            ('README', 'README.txt'),
            ('COPYING', 'COPYING.txt')
        ]
        copy_tree(self.bdist_dir, self.dist_target)
        pkg_info = mkpath(os.path.join(self.dist_target))
        for src, dst in info_files:
            if dst is None:
                copy_file(src, self.dist_target)
            else:
                copy_file(src, os.path.join(self.dist_target, dst))

        if not self.keep_temp:
            remove_tree(self.build_base, dry_run=self.dry_run)
コード例 #5
0
ファイル: setup.py プロジェクト: doru1004/FFC
def find_python_library():
    "Return the full path to the Python library (empty string if not found)"
    pyver = sysconfig.get_python_version()
    libpython_names = [
        "python%s" % pyver.replace(".", ""),
        "python%smu" % pyver,
        "python%sm" % pyver,
        "python%su" % pyver,
        "python%s" % pyver,
        ]
    dirs = [
        "%s/lib" % os.environ.get("PYTHON_DIR", ""),
        "%s" % sysconfig.get_config_vars().get("LIBDIR", ""),
        "/usr/lib/%s" % sysconfig.get_config_vars().get("MULTIARCH", ""),
        "/usr/local/lib",
        "/opt/local/lib",
        "/usr/lib",
        "/usr/lib64",
        ]
    libpython = None
    cc = new_compiler()
    for name in libpython_names:
        libpython = cc.find_library_file(dirs, name)
        if libpython is not None:
            break
    return libpython or ""
コード例 #6
0
ファイル: bdist_msi.py プロジェクト: Cinnz/python
    def finalize_options(self):
        if self.bdist_dir is None:
            bdist_base = self.get_finalized_command("bdist").bdist_base
            self.bdist_dir = os.path.join(bdist_base, "msi")
        short_version = get_python_version()
        if self.target_version:
            if not self.skip_build and self.distribution.has_ext_modules() and self.target_version != short_version:
                raise DistutilsOptionError, "target version can only be %s, or the '--skip_build'" " option must be specified" % (
                    short_version,
                )
        else:
            self.target_version = short_version

        self.set_undefined_options("bdist", ("dist_dir", "dist_dir"), ("plat_name", "plat_name"))

        if self.pre_install_script:
            raise DistutilsOptionError, "the pre-install-script feature is not yet implemented"

        if self.install_script:
            for script in self.distribution.scripts:
                if self.install_script == os.path.basename(script):
                    break
            else:
                raise DistutilsOptionError, "install_script '%s' not found in scripts" % self.install_script
        self.install_script_key = None
コード例 #7
0
ファイル: bdist_wininst.py プロジェクト: goutham414/kali-n900
    def get_exe_bytes(self):
        # If a target-version other than the current version has been
        # specified, then using the MSVC version from *this* build is no good.
        # Without actually finding and executing the target version and parsing
        # its sys.version, we just hard-code our knowledge of old versions.
        # NOTE: Possible alternative is to allow "--target-version" to
        # specify a Python executable rather than a simple version string.
        # We can then execute this program to obtain any info we need, such
        # as the real sys.version string for the build.
        cur_version = get_python_version()

        # If the target version is *later* than us, then we assume they
        # use what we use
        # string compares seem wrong, but are what sysconfig.py itself uses
        if self.target_version and self.target_version < cur_version:
            if self.target_version < "2.4":
                bv = 6.0
            elif self.target_version == "2.4":
                bv = 7.1
            elif self.target_version == "2.5":
                bv = 8.0
            elif self.target_version <= "3.2":
                bv = 9.0
            elif self.target_version <= "3.4":
                bv = 10.0
            else:
                bv = 14.0
        else:
            # for current version - use authoritative check.
            try:
                from msvcrt import CRT_ASSEMBLY_VERSION
            except ImportError:
                # cross-building, so assume the latest version
                bv = 14.0
            else:
                bv = float('.'.join(CRT_ASSEMBLY_VERSION.split('.', 2)[:2]))


        # wininst-x.y.exe is in the same directory as this file
        directory = os.path.dirname(__file__)
        # we must use a wininst-x.y.exe built with the same C compiler
        # used for python.  XXX What about mingw, borland, and so on?

        # if plat_name starts with "win" but is not "win32"
        # we want to strip "win" and leave the rest (e.g. -amd64)
        # for all other cases, we don't want any suffix
        if self.plat_name != 'win32' and self.plat_name[:3] == 'win':
            sfix = self.plat_name[3:]
        else:
            sfix = ''

        filename = os.path.join(directory, "wininst-%.1f%s.exe" % (bv, sfix))
        try:
            f = open(filename, "rb")
        except IOError as e:
            raise DistutilsFileError(str(e) + ', %s not included in the Debian packages.' % filename)
        try:
            return f.read()
        finally:
            f.close()
コード例 #8
0
ファイル: baseconf.py プロジェクト: cstausland/ppde_chris
 def finalize_options(self):
     _build_ext.finalize_options(self)
     self.set_undefined_options('build',
                                ('petsc_dir',  'petsc_dir'),
                                ('petsc_arch', 'petsc_arch'))
     import sys, os
     from distutils import sysconfig
     if ((sys.platform.startswith('linux') or
          sys.platform.startswith('gnu') or
          sys.platform.startswith('sunos')) and
         sysconfig.get_config_var('Py_ENABLE_SHARED')):
         py_version = sysconfig.get_python_version()
         bad_pylib_dir = os.path.join(sys.prefix, "lib",
                                      "python" + py_version,
                                      "config")
         try:
             self.library_dirs.remove(bad_pylib_dir)
         except ValueError:
             pass
         pylib_dir = sysconfig.get_config_var("LIBDIR")
         if pylib_dir not in self.library_dirs:
             self.library_dirs.append(pylib_dir)
         if pylib_dir not in self.rpath:
             self.rpath.append(pylib_dir)
         if sys.exec_prefix == '/usr':
             self.library_dirs.remove(pylib_dir)
             self.rpath.remove(pylib_dir)
コード例 #9
0
ファイル: bdist_wininst.py プロジェクト: B-Rich/breve
    def get_exe_bytes(self):
        from distutils.msvccompiler import get_build_version

        # If a target-version other than the current version has been
        # specified, then using the MSVC version from *this* build is no good.
        # Without actually finding and executing the target version and parsing
        # its sys.version, we just hard-code our knowledge of old versions.
        # NOTE: Possible alternative is to allow "--target-version" to
        # specify a Python executable rather than a simple version string.
        # We can then execute this program to obtain any info we need, such
        # as the real sys.version string for the build.
        cur_version = get_python_version()
        if self.target_version and self.target_version != cur_version:
            # If the target version is *later* than us, then we assume they
            # use what we use
            # string compares seem wrong, but are what sysconfig.py itself uses
            if self.target_version > cur_version:
                bv = get_build_version()
            else:
                if self.target_version < "2.4":
                    bv = "6"
                else:
                    bv = "7.1"
        else:
            # for current version - use authoritative check.
            bv = get_build_version()

        # wininst-x.y.exe is in the same directory as this file
        directory = os.path.dirname(__file__)
        # we must use a wininst-x.y.exe built with the same C compiler
        # used for python.  XXX What about mingw, borland, and so on?
        filename = os.path.join(directory, "wininst-%s.exe" % bv)
        return open(filename, "rb").read()
コード例 #10
0
ファイル: req_install.py プロジェクト: MichaelAquilina/pip
    def get_install_args(self, global_options, record_filename, root, prefix):
        install_args = [sys.executable, "-u"]
        install_args.append('-c')
        install_args.append(SETUPTOOLS_SHIM % self.setup_py)
        install_args += list(global_options) + \
            ['install', '--record', record_filename]

        if not self.as_egg:
            install_args += ['--single-version-externally-managed']

        if root is not None:
            install_args += ['--root', root]
        if prefix is not None:
            install_args += ['--prefix', prefix]

        if self.pycompile:
            install_args += ["--compile"]
        else:
            install_args += ["--no-compile"]

        if running_under_virtualenv():
            py_ver_str = 'python' + sysconfig.get_python_version()
            install_args += ['--install-headers',
                             os.path.join(sys.prefix, 'include', 'site',
                                          py_ver_str, self.name)]

        return install_args
コード例 #11
0
ファイル: setup.py プロジェクト: datawrangling/mpi4py
def executables():
    import sys
    from distutils import sysconfig
    libraries = []
    library_dirs = []
    compile_args = []
    link_args = []
    py_version = sysconfig.get_python_version()
    cfgDict = sysconfig.get_config_vars()
    if not sys.platform.startswith('win'):
        if '-pthread' in cfgDict.get('CC', ''):
            compile_args.append('-pthread')
        libraries = ['python' + py_version]
        for var in ('LIBDIR', 'LIBPL'):
            library_dirs += cfgDict.get(var, '').split()
        if '-pthread' in cfgDict.get('LINKCC', ''):
            link_args.append('-pthread')
        for var in ('LDFLAGS',
                    'LIBS', 'MODLIBS', 'SYSLIBS',
                    'LDLAST'):
            link_args += cfgDict.get(var, '').split()
    # MPI-enabled Python interpreter
    pyexe = dict(name='python%s-mpi' % py_version,
                 sources=['src/python.c'],
                 libraries=libraries,
                 library_dirs=library_dirs,
                 extra_compile_args=compile_args,
                 extra_link_args=link_args)
    return [pyexe]
コード例 #12
0
ファイル: dist_egg.py プロジェクト: vaddanak/challenges
    def finalize_options(self):
        """Finalize the options"""
        if self.bdist_dir is None:
            bdist_base = self.get_finalized_command("bdist").bdist_base
            self.bdist_dir = os.path.join(bdist_base, "egg")

        self.set_undefined_options("bdist", ("dist_dir", "dist_dir"), ("plat_name", "plat_name"))

        commercial_license = "Other/Proprietary License"
        self.distribution.metadata.license = commercial_license

        python_version = get_python_version()
        if self.include_sources:
            pyver = python_version[0:2]
        else:
            pyver = python_version

        # Change classifiers
        new_classifiers = []
        for classifier in self.distribution.metadata.classifiers:
            if classifier.startswith("License ::"):
                classifier = "License :: " + commercial_license
            elif classifier.startswith("Programming Language ::") and (pyver not in classifier):
                log.info("removing classifier %s" % classifier)
                continue
            new_classifiers.append(classifier)
        self.distribution.metadata.classifiers = new_classifiers
コード例 #13
0
ファイル: bdist_egg.py プロジェクト: akkmzack/RIOS-8.5
    def finalize_options(self):
        ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
        self.egg_info = ei_cmd.egg_info

        if self.bdist_dir is None:
            bdist_base = self.get_finalized_command("bdist").bdist_base
            self.bdist_dir = os.path.join(bdist_base, "egg")

        if self.plat_name is None:
            self.plat_name = get_build_platform()

        self.set_undefined_options("bdist", ("dist_dir", "dist_dir"))

        if self.egg_output is None:

            # Compute filename of the output egg
            basename = Distribution(
                None,
                None,
                ei_cmd.egg_name,
                ei_cmd.egg_version,
                get_python_version(),
                self.distribution.has_ext_modules() and self.plat_name,
            ).egg_name()

            self.egg_output = os.path.join(self.dist_dir, basename + ".egg")
コード例 #14
0
    def finalize_options(self):
        if self.bdist_dir is None:
            bdist_base = self.get_finalized_command('bdist').bdist_base
            self.bdist_dir = os.path.join(bdist_base, 'msi')
        short_version = get_python_version()
        if (not self.target_version) and self.distribution.has_ext_modules():
            self.target_version = short_version
        if self.target_version:
            self.versions = [self.target_version]
            if not self.skip_build and self.distribution.has_ext_modules()\
               and self.target_version != short_version:
                raise DistutilsOptionError(
                      "target version can only be %s, or the '--skip-build'"
                      " option must be specified" % (short_version,))
        else:
            self.versions = list(self.all_versions)

        self.set_undefined_options('bdist',
                                   ('dist_dir', 'dist_dir'),
                                   ('plat_name', 'plat_name'),
                                   )

        if self.pre_install_script:
            raise DistutilsOptionError(
                  "the pre-install-script feature is not yet implemented")

        if self.install_script:
            for script in self.distribution.scripts:
                if self.install_script == os.path.basename(script):
                    break
            else:
                raise DistutilsOptionError(
                      "install_script '%s' not found in scripts"
                      % self.install_script)
        self.install_script_key = None
コード例 #15
0
ファイル: bdist_venv.py プロジェクト: mgood/bdist_venv
    def finalize_options(self):
        ei_cmd = self.get_finalized_command('egg_info')
        self.egg_info = ei_cmd.egg_info

        if self.bdist_dir is None:
            bdist_base = self.get_finalized_command('bdist').bdist_base
            self.bdist_dir = os.path.join(bdist_base, 'venv')

        if self.no_plat_name:
            self.plat_name = ''
        elif self.plat_name is None:
            self.plat_name = get_build_platform()

        if self.requirements is None and os.path.exists('requirements.txt'):
            self.requirements = 'requirements.txt'

        if self.no_archive_root:
            self.archive_root = '.'
        elif self.archive_root is None:
            self.archive_root = self.distribution.get_fullname()
        elif not self.archive_root:
            self.archive_root = '.'

        self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))

        basename = self.distribution.get_fullname()
        if self.plat_name:
            basename = '%s.%s-py%s' % (basename, self.plat_name,
                                       get_python_version())

        self.venv_output = os.path.join(self.dist_dir, basename + '.tar.gz')
コード例 #16
0
ファイル: bdist_wininst.py プロジェクト: GeezerGeek/PyVHDL
    def finalize_options (self):
        if self.bdist_dir is None:
            if self.skip_build and self.plat_name:
                # If build is skipped and plat_name is overridden, bdist will
                # not see the correct 'plat_name' - so set that up manually.
                bdist = self.distribution.get_command_obj('bdist')
                bdist.plat_name = self.plat_name
                # next the command will be initialized using that name
            bdist_base = self.get_finalized_command('bdist').bdist_base
            self.bdist_dir = os.path.join(bdist_base, 'wininst')
        if not self.target_version:
            self.target_version = ""
        if not self.skip_build and self.distribution.has_ext_modules():
            short_version = get_python_version()
            if self.target_version and self.target_version != short_version:
                raise DistutilsOptionError, \
                      "target version can only be %s, or the '--skip_build'" \
                      " option must be specified" % (short_version,)
            self.target_version = short_version

        self.set_undefined_options('bdist',
                                   ('dist_dir', 'dist_dir'),
                                   ('plat_name', 'plat_name'),
                                  )

        if self.install_script:
            for script in self.distribution.scripts:
                if self.install_script == os.path.basename(script):
                    break
            else:
                raise DistutilsOptionError, \
                      "install_script '%s' not found in scripts" % \
                      self.install_script
コード例 #17
0
ファイル: setup.py プロジェクト: stockrt/gpgen
def rpmbuild(sname, sversion, srpmdata):
    try:
        # Default .spec
        os.system('./setup.py bdist_rpm --spec-only')
        # Default tarball
        os.system('./setup.py sdist --dist-dir ~/rpmbuild/SOURCES/')
        # Python Lib dir and Version
        pylib = get_python_lib()
        pyver = get_python_version()
        # Applying the changes to the .spec (%files/%config/%dir/%post):
        # Initialize spec with the basic
        newspec = brpmdata
        for l in open('dist/%s.spec' % sname).readlines():
            # Remove the defaults:
            # '%files -f INSTALLED_FILES'
            # '%defattr(-,root,root,-)'
            if '%files -f INSTALLED_FILES' not in l and '%defattr' not in l:
                newspec += l
        # Insert the user defined specs (%files/%config/%dir/%post):
        newspec += srpmdata
        # Replace the Python Lib dir and Version by the real ones
        newspec = newspec.replace('@@PYLIB_MARKER@@', pylib)
        newspec = newspec.replace('@@PYVER_MARKER@@', pyver)
        open('dist/%s.spec' % sname, 'w').write(newspec)
        # Create the new RPM
        os.system('rpmbuild -bb dist/%s.spec' % sname)
        # Copy the created RPM to dist/
        os.system('/bin/cp ~/rpmbuild/RPMS/noarch/%s-%s-*.rpm dist/' % (sname, sversion))
    except Exception, why:
        print 'ERR: Error building the RPM with custom .spec file: [%s]' % why
コード例 #18
0
ファイル: bdist_venv.py プロジェクト: mgood/bdist_venv
    def run(self):
        # generate the metadata first
        self.run_command('egg_info')

        venv_dir = self.bdist_dir

        virtualenv.create_environment(
            venv_dir,
            never_download=True,
        )

        pip_cmd = [os.path.join(venv_dir, 'bin', 'pip'), 'install', '.']
        if self.requirements:
            pip_cmd.extend(['-r', self.requirements])
        subprocess.check_call(pip_cmd)

        self.copy_file(os.path.join(self.egg_info, 'PKG-INFO'), venv_dir)

        virtualenv.make_environment_relocatable(venv_dir)

        log.info("creating '%s' and adding '%s' to it", self.venv_output,
                 venv_dir)
        mkpath(os.path.dirname(self.venv_output))

        with closing(tarfile.open(self.venv_output, 'w:gz')) as tar:
            tar.add(venv_dir, self.archive_root)

        self.distribution.dist_files.append(('bdist_venv', get_python_version(),
                                             self.venv_output))

        if not self.keep_temp:
            remove_tree(venv_dir)
コード例 #19
0
ファイル: dist_msi.py プロジェクト: vaddanak/challenges
    def finalize_options(self):
        self.set_undefined_options('build',
                                   ('build_base', 'build_base'))
        self.set_undefined_options('bdist',
                                   ('dist_dir', 'dist_dir'))

        if not self.prefix:
            self.prefix = os.path.join(self.build_base, 'wininst')

        supported = ['2.6', '2.7', '3.3', '3.4']
        if self.python_version not in supported:
            raise DistutilsOptionError(
                "The --python-version should be a supported version, one "
                "of %s" % ','.join(supported))

        if self.python_version[0] != get_python_version()[0]:
            raise DistutilsError(
                "Python v3 distributions need to be build with a "
                "supported Python v3 installation.")

        if self.with_mysql_capi:
            cmd_build = self.get_finalized_command('build')
            self.connc_lib = os.path.join(cmd_build.build_temp, 'connc', 'lib')
            self.connc_include = os.path.join(cmd_build.build_temp,
                                              'connc', 'include')

            self._finalize_connector_c(self.with_mysql_capi)
        else:
            self.connc_lib = None
            self.connc_lib = None
コード例 #20
0
ファイル: setup.py プロジェクト: KeeganRen/dlib
    def build_dlib():
        """use cmake to build and install the extension
        """
        if cmake_path is None:
            raise DistutilsSetupError("Cannot find cmake in the path. Please specify its path with --cmake parameter.")

        platform_arch = platform.architecture()[0]
        log.info("Detected Python architecture: %s" % platform_arch)

        # make sure build artifacts are generated for the version of Python currently running
        cmake_extra_arch = []
        if sys.version_info >= (3, 0):
            cmake_extra_arch += ["-DPYTHON3=yes"]

        if platform_arch == "64bit" and sys.platform == "win32":
            # 64bit build on Windows

            if not generator_set:
                # see if we can deduce the 64bit default generator
                cmake_extra_arch += get_msvc_win64_generator()

            # help cmake to find Python library in 64bit Python in Windows
            #  because cmake is 32bit and cannot find PYTHON_LIBRARY from registry.
            inc_dir = get_python_inc()
            cmake_extra_arch += ["-DPYTHON_INCLUDE_DIR={inc}".format(inc=inc_dir)]

            # this imitates cmake in path resolution
            py_ver = get_python_version()
            for ext in [py_ver.replace(".", "") + ".lib", py_ver + "mu.lib", py_ver + "m.lib", py_ver + "u.lib"]:
                py_lib = os.path.abspath(os.path.join(inc_dir, "../libs/", "python" + ext))
                if os.path.exists(py_lib):
                    cmake_extra_arch += ["-DPYTHON_LIBRARY={lib}".format(lib=py_lib)]
                    break

        build_dir = os.path.join(script_dir, "./tools/python/build")
        if os.path.exists(build_dir):
            log.info("Removing build directory %s" % build_dir)
            rmtree(build_dir)

        try:
            os.makedirs(build_dir)
        except OSError:
            pass

        # cd build
        os.chdir(build_dir)
        log.info("Configuring cmake ...")
        cmake_cmd = [cmake_path, ".."] + cmake_extra + cmake_extra_arch
        if run_process(cmake_cmd):
            raise DistutilsSetupError("cmake configuration failed!")

        log.info("Build using cmake ...")

        cmake_cmd = [cmake_path, "--build", ".", "--config", cmake_config, "--target", "install"]

        if run_process(cmake_cmd):
            raise DistutilsSetupError("cmake build failed!")

        # cd back where setup awaits
        os.chdir(script_dir)
コード例 #21
0
ファイル: setup.py プロジェクト: evolvedmicrobe/ConsensusCore
def configure():
    """
    Look up the dependencies
     - Python.h
     - numpy headers
     - boost headers (from configuration flag)

    meanwhile, pass through any config-looking arguments (ex: --boost=...)
    """
    # Python.h
    python_inc = sysconfig.get_python_inc()

    # Libpython
    python_libdir = join(sysconfig.get_python_lib(standard_lib=True), "config")
    python_lib = "python" + sysconfig.get_python_version()

    if '--version' in sys.argv:
        return "--version"
    # numpy headers
    try:
        import numpy
        numpy_inc = numpy.get_include()
    except ImportError:
        die("Requires numpy >= 1.6.0")

    configArgs = []
    for arg in sys.argv[:]:
        if arg.startswith("-") and arg not in ["--help", "--version"]:
            configArgs.append(arg)
            sys.argv.remove(arg)

    configArgs.append("--python-include=%s " % python_inc)
    configArgs.append("--numpy-include=%s "  % numpy_inc)

    return " ".join(configArgs)
コード例 #22
0
ファイル: cc.py プロジェクト: vuuvv/vuuvv-server
def get_python_lib_dirs():
	lib_dirs = []

	if os.name == 'nt':
		lib_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
	elif os.name == 'os2':
		lib_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
	
	if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
		if sys.excutable.startswith(os.path.join(sys.exec_prefix, "bin")):
			lib_dirs.append(os.path.join(sys.prefix, "lib", 
				"python" + sysconfig.get_python_version(), "config"))
		else:
			lib_dirs.append(".")

	sysconfig.get_config_var('Py_ENABLE_SHARED')
	if ((sys.platform.startswith('linux') or sys.platform.startswith('gnu')
		 or sys.platform.startswith('sunos'))
		and sysconfig.get_config_var('Py_ENABLE_SHARED')):
		if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
			# building third party extensions
			lib_dirs.append(sysconfig.get_config_var('LIBDIR'))
		else:
			# building python standard extensions
			lib_dirs.append('.')
	return lib_dirs
コード例 #23
0
def _exists():
    """PolyBoRi convention: checking optional components for prerequisites here

    >>> _exists()
    True
    """
    from distutils.sysconfig import get_python_version
    return float(get_python_version()) > 2.4
コード例 #24
0
ファイル: setup.py プロジェクト: paulromano/pyne
def cpp_ext(name, sources, libs=None, use_hdf5=False):
    """Helper function for setting up extension dictionary.

    Parameters
    ----------
    name : str
        Module name
    sources : list of str
        Files to compile
    libs : list of str
        Additional files to link against
    use_hdf5 : bool
        Link against hdf5?
    """
    ext = {'name': name}

    ext['sources'] = [os.path.join(cpp_dir, s) for s in sources if s.endswith('cpp')] + \
                     [os.path.join(pyt_dir, s) for s in sources if s.endswith('pyx')] + \
                     [s for s in sources if not any([s.endswith(suf) for suf in ['cpp', 'pyx']])]

    ext["libraries"] = []
    ext['include_dirs'] = [pyt_dir, cpp_dir, numpy_include]
    ext['language'] = "c++"

    # may need to be more general
    ext['library_dirs'] = ['build/lib/pyne/lib',
                           'build/lib.{0}-{1}/pyne/lib'.format(get_platform(), get_python_version()),
                           ]
    # perfectly general, thanks to dynamic runtime linking of $ORIGIN
    #ext['runtime_library_dirs'] = ['${ORIGIN}/lib', '${ORIGIN}']
    ext['runtime_library_dirs'] = ['${ORIGIN}/lib', '${ORIGIN}', '${ORIGIN}/.', 
                                   '${ORIGIN}/../lib', '${ORIGIN}/..',]
    #ext['runtime_library_dirs'] = ['${ORIGIN}/lib', '${ORIGIN}', '${ORIGIN}/.'] + \
    #                              [os.path.abspath(p) for p in ext['library_dirs']] + \
    #                              [os.path.abspath(p + '/pyne/lib') for p in sys.path] + \
    #                              [os.path.abspath(p + '/pyne') for p in sys.path] + \
    #                              [os.path.abspath(p) for p in sys.path]

    if os.name == 'posix':
        #ext["extra_compile_args"] = ["-Wno-strict-prototypes"]
        ext["undef_macros"] = ["NDEBUG"]
        if use_hdf5:
            ext["libraries"] += posix_hdf5_libs
        if libs is not None:
            ext["libraries"] += libs
    elif os.name == 'nt':
        ext["extra_compile_args"] = ["/EHsc"]
        ext["define_macros"] = [("_WIN32", None)]

        if use_hdf5:
            ext["libraries"] += nt_hdf5_libs
            ext["extra_compile_args"] += nt_hdf5_extra_compile_args
            ext["define_macros"] += nt_hdf5_macros

        if libs is not None:
            ext["libraries"] += libs

    return ext
コード例 #25
0
ファイル: bdist.py プロジェクト: vaddanak/challenges
 def _get_fullname():
     if not self.include_sources:
         pyver = '-py' + get_python_version()
     return "{name}-commercial-{version}{edition}{pyver}".format(
         name=self.distribution.get_name(),
         version=self.distribution.get_version(),
         edition=self.edition or '',
         pyver=pyver
     )
コード例 #26
0
 def initialize_options (self):
     """Initialize the options"""
     self.bdist_dir = None
     self.keep_temp = 0
     self.dist_dir = None
     self.include_sources = True
     self.wix_install = WIX_INSTALL
     self.python_version = get_python_version()[:3]
     self.edition = EDITION
コード例 #27
0
ファイル: python.py プロジェクト: gatgui/excons
def Version():
  po = excons.GetArgument("with-python")

  if po is not None:
    rv = _GetPythonSpec(po)
    if rv is not None:
      return rv[0]

  return str(sysconfig.get_python_version())
コード例 #28
0
ファイル: BDistEgg.py プロジェクト: H1d3r/binary_blobs
 def get_egg_filename(self):
     def make_egg_safe(name):
         return re.sub('[^a-zA-Z0-9.]+', '_', name)
     name = make_egg_safe(self.distribution.get_name())
     version = make_egg_safe(self.distribution.get_version())
     platform = get_python_version()
     if self.distribution.has_ext_modules():
         platform += '-' + self.plat_name
     return '%s-%s-py%s.egg' % (name, version, platform)
コード例 #29
0
ファイル: setup.py プロジェクト: pferreir/indico-backup
    def finalize_options(self):
        ei_cmd = self.ei_cmd = self.get_finalized_command("egg_info")
        self.egg_info = ei_cmd.egg_info

        basename = pkg_resources.Distribution(
            None, None, ei_cmd.egg_name, ei_cmd.egg_version,
            get_python_version(),
            self.distribution.has_ext_modules() and pkg_utils.get_build_platform).egg_name()

        print basename
コード例 #30
0
ファイル: python.py プロジェクト: btanasoi/fvm
def generate(env):
    cv = get_config_vars()
    pylib = 'python'+get_python_version()
    pylibpath = [cv[var] for var in ('LIBDIR', 'LIBPL')]
    env.Append(CPPPATH=[get_python_inc(),numpy.get_include()])
    if Arch.isWindows():
        env.Append(LIBS=pylib.replace(".",""))
        env.Append(LIBPATH=pylibpath)
    else:
        env.Append(LIBS=pylib)
        env.Append(LIBPATH=pylibpath)
コード例 #31
0
    def install(self, install_options, global_options=(), root=None):
        if self.editable:
            self.install_editable(install_options, global_options)
            return
        if self.is_wheel:
            version = pip.wheel.wheel_version(self.source_dir)
            pip.wheel.check_compatibility(version, self.name)

            self.move_wheel_files(self.source_dir, root=root)
            self.install_succeeded = True
            return

        temp_location = tempfile.mkdtemp('-record', 'pip-')
        record_filename = os.path.join(temp_location, 'install-record.txt')
        try:
            install_args = [sys.executable]
            install_args.append('-c')
            install_args.append(
                "import setuptools, tokenize;__file__=%r;"
                "exec(compile(getattr(tokenize, 'open', open)(__file__).read()"
                ".replace('\\r\\n', '\\n'), __file__, 'exec'))" % self.setup_py
            )
            install_args += list(global_options) + \
                ['install', '--record', record_filename]

            if not self.as_egg:
                install_args += ['--single-version-externally-managed']

            if root is not None:
                install_args += ['--root', root]

            if self.pycompile:
                install_args += ["--compile"]
            else:
                install_args += ["--no-compile"]

            if running_under_virtualenv():
                # FIXME: I'm not sure if this is a reasonable location;
                # probably not but we can't put it in the default location, as
                # that is a virtualenv symlink that isn't writable
                py_ver_str = 'python' + sysconfig.get_python_version()
                install_args += ['--install-headers',
                                 os.path.join(sys.prefix, 'include', 'site',
                                              py_ver_str)]
            logger.notify('Running setup.py install for %s' % self.name)
            logger.indent += 2
            try:
                call_subprocess(
                    install_args + install_options,
                    cwd=self.source_dir,
                    filter_stdout=self._filter_install,
                    show_stdout=False,
                )
            finally:
                logger.indent -= 2
            if not os.path.exists(record_filename):
                logger.notify('Record file %s not found' % record_filename)
                return
            self.install_succeeded = True
            if self.as_egg:
                # there's no --always-unzip option we can pass to install
                # command so we unable to save the installed-files.txt
                return

            def prepend_root(path):
                if root is None or not os.path.isabs(path):
                    return path
                else:
                    return change_root(root, path)

            f = open(record_filename)
            for line in f:
                line = line.strip()
                if line.endswith('.egg-info'):
                    egg_info_dir = prepend_root(line)
                    break
            else:
                logger.warn(
                    'Could not find .egg-info directory in install record for '
                    '%s' % self
                )
                f.close()
                # FIXME: put the record somewhere
                # FIXME: should this be an error?
                return
            f.close()
            new_lines = []
            f = open(record_filename)
            for line in f:
                filename = line.strip()
                if os.path.isdir(filename):
                    filename += os.path.sep
                new_lines.append(
                    make_path_relative(prepend_root(filename), egg_info_dir)
                )
            f.close()
            f = open(os.path.join(egg_info_dir, 'installed-files.txt'), 'w')
            f.write('\n'.join(new_lines) + '\n')
            f.close()
        finally:
            if os.path.exists(record_filename):
                os.remove(record_filename)
            os.rmdir(temp_location)
コード例 #32
0
class _MSIDist(Command):
    """"Create a MSI distribution"""

    user_options = [
        ('bdist-dir=', 'd',
         "temporary directory for creating the distribution"),
        ('keep-temp', 'k', "keep the pseudo-installation tree around after " +
         "creating the distribution archive"),
        ('dist-dir=', 'd', "directory to put final built distributions in"),
        ('wix-install=', None,
         "location of the Windows Installer XML installation"
         "(default: %s)" % wix.WIX_INSTALL_PATH),
        ('wix-required-version=', None,
         "required version the Windows Installer XML installation"
         "(default: %s)" % wix.WIX_REQUIRED_VERSION),
        ('python-version=', None, "target Python version"),
        ('prepare-stage', 'p',
         "only stage installation for this python {} version, used later for"
         "a single msi".format(get_python_version()[:3])),
        ('combine-stage', 'c',
         "Unify the prepared msi stages to only one single msi"),
    ] + COMMON_USER_OPTIONS + CEXT_OPTIONS

    boolean_options = [
        'keep-temp', 'include-sources', 'prepare-stage', 'combine-stage'
    ]

    negative_opt = {}

    def initialize_options(self):
        self.prefix = None
        self.build_base = None
        self.bdist_dir = None
        self.keep_temp = 0
        self.dist_dir = None
        self.include_sources = True
        self.wix_install = wix.WIX_INSTALL_PATH
        self.wix_required_version = wix.WIX_REQUIRED_VERSION
        self.python_version = get_python_version()[:3]
        self.edition = EDITION
        self.with_mysql_capi = None
        self.with_protobuf_include_dir = None
        self.with_protobuf_lib_dir = None
        self.with_protoc = None
        self.with_cext = False
        self.extra_compile_args = None
        self.extra_link_args = None
        self.connc_lib = None
        self.connc_lib = None
        self.prepare_stage = False
        self.combine_stage = False

    def finalize_options(self):
        self.set_undefined_options('build', ('build_base', 'build_base'))
        self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))

        if not self.prefix:
            self.prefix = os.path.join(
                self.build_base,
                DIST_PATH_FORMAT.format(self.python_version[0],
                                        self.python_version[2]))

        self.supported_versions = ['2.7', '3.4', '3.5', '3.6', '3.7', '3.8']

        self.dist_path = {}

        for py_ver in self.supported_versions:
            self.dist_path[py_ver] = os.path.join(
                self.build_base, DIST_PATH_FORMAT.format(*py_ver.split('.')))

        if self.python_version not in self.supported_versions:
            raise DistutilsOptionError(
                "The --python-version should be a supported version, one "
                "of %s" % ','.join(self.supported_versions))

        if self.python_version[0] != get_python_version()[0]:
            raise DistutilsError(
                "Python v3 distributions need to be build with a "
                "supported Python v3 installation.")

        self.with_cext = any(
            (self.with_mysql_capi, self.with_protobuf_include_dir,
             self.with_protobuf_lib_dir, self.with_protoc))

        if self.with_cext:
            if not self.with_mysql_capi or \
               not os.path.isdir(self.with_mysql_capi):
                log.error("Location of MySQL C API (Connector/C) must be "
                          "provided.")
                sys.exit(1)
            else:
                cmd_build = self.get_finalized_command('build')
                self.connc_lib = os.path.join(cmd_build.build_temp, 'connc',
                                              'lib')
                self.connc_include = os.path.join(cmd_build.build_temp,
                                                  'connc', 'include')

                self._finalize_connector_c(self.with_mysql_capi)

            if not self.with_protobuf_include_dir or \
               not os.path.isdir(self.with_protobuf_include_dir):
                log.error("Location of Protobuf include directory must be "
                          "provided.")
                sys.exit(1)
            else:
                self.with_protobuf_include_dir = \
                    os.path.abspath(self.with_protobuf_include_dir)

            if not self.with_protobuf_lib_dir or \
               not os.path.isdir(self.with_protobuf_lib_dir):
                log.error("Location of Protobuf library directory must be "
                          "provided.")
                sys.exit(1)
            else:
                self.with_protobuf_lib_dir = \
                    os.path.abspath(self.with_protobuf_lib_dir)

            if not self.with_protoc or not os.path.isfile(self.with_protoc):
                log.error("Protobuf protoc binary is not valid.")
                sys.exit(1)
            else:
                self.with_protoc = os.path.abspath(self.with_protoc)

    def _finalize_connector_c(self, connc_loc):
        if not os.path.isdir(connc_loc):
            log.error("MySQL C API should be a directory")
            sys.exit(1)

        copy_tree(os.path.join(connc_loc, 'lib'), self.connc_lib)
        copy_tree(os.path.join(connc_loc, 'include'), self.connc_include)

        if ARCH_64BIT:
            for filename in ["libssl-1_1-x64.dll", "libcrypto-1_1-x64.dll"]:
                src = os.path.join(connc_loc, "bin", filename)
                dst = self.connc_lib
                log.info("copying {0} -> {1}".format(src, dst))
                shutil.copy(src, dst)
        else:
            for filename in ["libssl-1_1.dll", "libcrypto-1_1.dll"]:
                src = os.path.join(connc_loc, "bin", filename)
                dst = self.connc_lib
                log.info("copying {0} -> {1}".format(src, dst))
                shutil.copy(src, dst)

        for lib_file in os.listdir(self.connc_lib):
            if os.name == 'posix' and not lib_file.endswith('.a'):
                os.unlink(os.path.join(self.connc_lib, lib_file))

    def finalize_msi_descriptor(self):
        """Returns the finalized and customized path of the msi descriptor.
        """
        base_xml_path = os.path.join(MSIDATA_ROOT, "product.wxs")
        result_xml_path = os.path.join(MSIDATA_ROOT, 'cpy_product_desc.wxs')

        if get_platform() == 'win32':
            add_arch_dep_elems(base_xml_path,
                               result_xml_path,
                               for32=True,
                               log=log,
                               add_vs_redist=False)
        else:
            add_arch_dep_elems(base_xml_path,
                               result_xml_path,
                               log=log,
                               add_vs_redist=self.with_cext)

        return result_xml_path

    def _get_wixobj_name(self, myc_version=None, python_version=None):
        """Get the name for the wixobj-file

        Returns a string
        """
        raise NotImplementedError

    def find_bdist_paths(self):
        """Find compresed distribution files or valid distribution paths.
        """
        valid_bdist_paths = {}
        bdist_paths = {
            '2.7':
            os.path.join(os.path.abspath(self.dist_path['2.7']), 'Lib',
                         'site-packages'),
            '3.4':
            os.path.join(os.path.abspath(self.dist_path['3.4']), 'Lib',
                         'site-packages'),
            '3.5':
            os.path.join(os.path.abspath(self.dist_path['3.5']), 'Lib',
                         'site-packages'),
            '3.6':
            os.path.join(os.path.abspath(self.dist_path['3.6']), 'Lib',
                         'site-packages'),
            '3.7':
            os.path.join(os.path.abspath(self.dist_path['3.7']), 'Lib',
                         'site-packages'),
            '3.8':
            os.path.join(os.path.abspath(self.dist_path['3.8']), 'Lib',
                         'site-packages')
        }

        for py_ver in self.supported_versions:
            bdist_paths[py_ver] = os.path.join(
                os.path.abspath(self.dist_path[py_ver]), 'Lib',
                'site-packages')
            zip_fn = "{}.zip".format(
                DIST_PATH_FORMAT.format(*py_ver.split(".")))

            log.info("Locating zip: %s at %s", zip_fn, os.path.curdir)
            bdist_path = None
            if os.path.exists(zip_fn) and \
               zipfile.is_zipfile(zip_fn):
                with zipfile.ZipFile(zip_fn) as zip_f:
                    zip_f.extractall()
            else:
                log.warn("Unable to find zip: %s at %s", zip_fn,
                         os.path.curdir)
            if bdist_path is None:
                bdist_path = bdist_paths[py_ver]
                log.info("Checking for extracted distribution at %s",
                         bdist_path)
            if os.path.exists(bdist_path):
                valid_bdist_paths[py_ver] = bdist_path
                log.info("Distribution path found at %s", bdist_path)
            else:
                log.warn("Unable to find distribution path for %s", py_ver)

        return valid_bdist_paths

    def _create_msi(self, dry_run=0):
        """Create the Windows Installer using WiX

        Creates the Windows Installer using WiX and returns the name of
        the created MSI file.

        Raises DistutilsError on errors.

        Returns a string
        """
        # load the upgrade codes
        with open(os.path.join(MSIDATA_ROOT, 'upgrade_codes.json')) as fp:
            upgrade_codes = json.load(fp)

        # version variables for Connector/Python and Python
        mycver = self.distribution.metadata.version
        match = re.match("(\d+)\.(\d+).(\d+).*", mycver)
        if not match:
            raise ValueError("Failed parsing version from %s" % mycver)
        (major, minor, patch) = match.groups()
        pyver = self.python_version
        pymajor = pyver[0]
        pyminor = pyver[2]

        # check whether we have an upgrade code
        try:
            upgrade_code = upgrade_codes[mycver[0:3]][pyver]
        except KeyError:
            raise DistutilsError(
                "No upgrade code found for version v{cpy_ver}, "
                "Python v{py_ver}".format(cpy_ver=mycver, py_ver=pyver))
        log.info("upgrade code for v%s, Python v%s: %s" %
                 (mycver, pyver, upgrade_code))

        self.pyver_bdist_paths = self.find_bdist_paths()

        # wixobj's basename is the name of the installer
        wixobj = self._get_wixobj_name()
        msi = os.path.abspath(
            os.path.join(self.dist_dir, wixobj.replace('.wixobj', '.msi')))
        wixer = wix.WiX(self.wxs,
                        out=wixobj,
                        msi_out=msi,
                        base_path=self.build_base,
                        install=self.wix_install)

        # correct newlines and version in text files
        log.info("Fixing newlines in text files")
        info_files = []
        for txt_file_dest, txt_file_path in self.fix_txtfiles.items():
            txt_fixed = os.path.join(self.build_base, txt_file_dest)
            info_files.append(txt_fixed)
            content = open(txt_file_path, 'rb').read()

            if b'\r\n' not in content:
                log.info("converting newlines in %s", txt_fixed)
                content = content.replace(b'\n', b'\r\n')
                open(txt_fixed, 'wb').write(content)
            else:
                log.info("not converting newlines in %s, this is odd",
                         txt_fixed)
                open(txt_fixed, 'wb').write(content)

        digit_needle = 'Connector/Python \d{1,2}.\d{1,2}'
        xy_needle = 'Connector/Python X.Y'
        xy_sub = 'Connector/Python {0}.{1}'
        for info_file in info_files:
            log.info("correcting version in %s", info_file)
            with open(info_file, 'r+') as fp:
                content = fp.readlines()
                for i, line in enumerate(content):
                    content[i] = re.sub(digit_needle,
                                        xy_sub.format(*VERSION[0:2]), line)
                    line = content[i]
                    content[i] = re.sub(xy_needle,
                                        xy_sub.format(*VERSION[0:2]), line)
                fp.seek(0)
                fp.write(''.join(content))

        plat_type = 'x64' if ARCH_64BIT else 'x86'
        win64 = 'yes' if ARCH_64BIT else 'no'
        pyd_arch = 'win_amd64' if ARCH_64BIT else 'win32'
        directory_id = 'ProgramFiles64Folder' if ARCH_64BIT else \
            'ProgramFilesFolder'

        # For 3.5 the driver names are pretty complex, see
        # https://www.python.org/dev/peps/pep-0425/
        if pymajor == '3' and int(pyminor) >= 5:
            pyd_ext = ".cp%s%s-%s.pyd" % (pyver[0], 5, pyd_arch)
        else:
            pyd_ext = ".pyd"

        cext_lib_name = "_mysql_connector" + pyd_ext
        cext_xpb_name = "_mysqlxpb" + pyd_ext

        if self.connc_lib:
            if ARCH_64BIT:
                libcrypto_dll_path = os.path.join(
                    os.path.abspath(self.connc_lib), 'libcrypto-1_1-x64.dll')
                libssl_dll_path = os.path.join(os.path.abspath(self.connc_lib),
                                               'libssl-1_1-x64.dll')
            else:
                libcrypto_dll_path = os.path.join(
                    os.path.abspath(self.connc_lib), 'libcrypto-1_1.dll')
                libssl_dll_path = os.path.join(os.path.abspath(self.connc_lib),
                                               'libssl-1_1.dll')
        else:
            libcrypto_dll_path = ''
            libssl_dll_path = ''

        # WiX preprocessor variables
        params = {
            'Version': '.'.join([major, minor, patch]),
            'FullVersion': mycver,
            'PythonVersion': pyver,
            'PythonMajor': pymajor,
            'PythonMinor': pyminor,
            'Major_Version': major,
            'Minor_Version': minor,
            'Patch_Version': patch,
            'Platform': plat_type,
            'Directory_Id': directory_id,
            'PythonInstallDir': 'Python%s' % pyver.replace('.', ''),
            'PyExt': 'pyc' if not self.include_sources else 'py',
            'UpgradeCode': upgrade_code,
            'ManualPDF': os.path.abspath(
                os.path.join('docs', 'mysql-connector-python.pdf')),
            'ManualHTML': os.path.abspath(
                os.path.join('docs', 'mysql-connector-python.html')),
            'UpgradeCode': upgrade_code,
            'MagicTag': get_magic_tag(),
            'BuildDir': os.path.abspath(self.build_base),
            'LibMySQLDLL': os.path.join(
                os.path.abspath(self.connc_lib), 'libmysql.dll') \
                    if self.connc_lib else '',
            'LIBcryptoDLL': libcrypto_dll_path,
            'LIBSSLDLL': libssl_dll_path,
            'Win64': win64,
            'BitmapDir': os.path.join(os.getcwd(), "cpyint", "data",
                                      "MSWindows"),
        }
        for py_ver in self.supported_versions:
            ver = py_ver.split(".")
            params['BDist{}{}'.format(*ver)] = ""

            if ver[0] == '3' and int(ver[1]) >= 5:
                pyd_ext = ".cp%s%s-%s.pyd" % (ver[0], ver[1], pyd_arch)
            else:
                pyd_ext = ".pyd"

            params['CExtLibName{}{}'.format(*ver)] = \
               "_mysql_connector{}".format(pyd_ext)
            params['CExtXPBName{}{}'.format(*ver)] = \
               "_mysqlxpb{}".format(pyd_ext)
            params['HaveCExt{}{}'.format(*ver)] = 0

            if py_ver in self.pyver_bdist_paths:
                params['BDist{}{}'.format(*ver)] = \
                   self.pyver_bdist_paths[py_ver]
                if os.path.exists(
                        os.path.join(self.pyver_bdist_paths[py_ver],
                                     params['CExtLibName{}{}'.format(*ver)])):
                    params['HaveCExt{}{}'.format(*ver)] = 1

        log.info("### wixer params:")
        for param in params:
            log.info("  %s: %s", param, params[param])
        wixer.set_parameters(params)

        if not dry_run:
            try:
                wixer.compile()
                wixer.link()
            except DistutilsError:
                raise

        if not self.keep_temp and not dry_run:
            log.info('WiX: cleaning up')
            os.unlink(msi.replace('.msi', '.wixpdb'))

        return msi

    def _prepare(self):
        log.info("Preparing installation in %s", self.build_base)
        cmd_install = self.reinitialize_command('install',
                                                reinit_subcommands=1)
        cmd_install.prefix = self.prefix
        cmd_install.with_mysql_capi = self.with_mysql_capi
        cmd_install.with_protobuf_include_dir = self.with_protobuf_include_dir
        cmd_install.with_protobuf_lib_dir = self.with_protobuf_lib_dir
        cmd_install.with_protoc = self.with_protoc
        cmd_install.extra_compile_args = self.extra_compile_args
        cmd_install.extra_link_args = self.extra_link_args
        cmd_install.static = False
        cmd_install.ensure_finalized()
        cmd_install.run()

    def run(self):
        """Run the distutils command"""

        if os.name != 'nt':
            log.info("This command is only useful on Windows. "
                     "Forcing dry run.")
            self.dry_run = True

        log.info("generating INFO_SRC and INFO_BIN files")
        generate_info_files()

        if not self.combine_stage:
            self._prepare()

        if self.prepare_stage:
            zip_fn = os.path.join(
                self.dist_dir, "{}.zip".format(os.path.abspath(self.prefix)))
            log.info("generating stage: %s", zip_fn)
            with zipfile.ZipFile(zip_fn, "w", zipfile.ZIP_DEFLATED) as zip_f:
                # Read all directory, subdirectories and file lists
                for root, _, files in os.walk(self.prefix):
                    for filename in files:
                        # Create the full filepath by using os module.
                        filePath = os.path.join(root, filename)
                        log.info("  adding file: %s", filePath)
                        zip_f.write(filePath)
            log.info("stage created: %s", zip_fn)
        else:
            wix.check_wix_install(
                wix_install_path=self.wix_install,
                wix_required_version=self.wix_required_version,
                dry_run=self.dry_run)

            # create the Windows Installer
            msi_file = self._create_msi(dry_run=self.dry_run)
            log.info("created MSI as %s" % msi_file)

        if not self.keep_temp:
            remove_tree(self.build_base, dry_run=self.dry_run)
            if ARCH_64BIT:
                for filename in [
                        "libssl-1_1-x64.dll", "libcrypto-1_1-x64.dll"
                ]:
                    dll_file = os.path.join(os.getcwd(), filename)
                    if os.path.exists(dll_file):
                        os.unlink(dll_file)
            else:
                for filename in ["libssl-1_1.dll", "libcrypto-1_1.dll"]:
                    dll_file = os.path.join(os.getcwd(), filename)
                    if os.path.exists(dll_file):
                        os.unlink(dll_file)
コード例 #33
0
ファイル: bdist_rpm.py プロジェクト: mahmoudimus/WOT-0.9.20.0
    def run(self):
        if DEBUG:
            print 'before _get_package_data():'
            print 'vendor =', self.vendor
            print 'packager =', self.packager
            print 'doc_files =', self.doc_files
            print 'changelog =', self.changelog
        if self.spec_only:
            spec_dir = self.dist_dir
            self.mkpath(spec_dir)
        else:
            rpm_dir = {}
            for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
                rpm_dir[d] = os.path.join(self.rpm_base, d)
                self.mkpath(rpm_dir[d])

            spec_dir = rpm_dir['SPECS']
        spec_path = os.path.join(spec_dir,
                                 '%s.spec' % self.distribution.get_name())
        self.execute(write_file, (spec_path, self._make_spec_file()),
                     "writing '%s'" % spec_path)
        if self.spec_only:
            return
        else:
            saved_dist_files = self.distribution.dist_files[:]
            sdist = self.reinitialize_command('sdist')
            if self.use_bzip2:
                sdist.formats = ['bztar']
            else:
                sdist.formats = ['gztar']
            self.run_command('sdist')
            self.distribution.dist_files = saved_dist_files
            source = sdist.get_archive_files()[0]
            source_dir = rpm_dir['SOURCES']
            self.copy_file(source, source_dir)
            if self.icon:
                if os.path.exists(self.icon):
                    self.copy_file(self.icon, source_dir)
                else:
                    raise DistutilsFileError, "icon file '%s' does not exist" % self.icon
            log.info('building RPMs')
            rpm_cmd = ['rpm']
            if os.path.exists('/usr/bin/rpmbuild') or os.path.exists(
                    '/bin/rpmbuild'):
                rpm_cmd = ['rpmbuild']
            if self.source_only:
                rpm_cmd.append('-bs')
            elif self.binary_only:
                rpm_cmd.append('-bb')
            else:
                rpm_cmd.append('-ba')
            if self.rpm3_mode:
                rpm_cmd.extend([
                    '--define',
                    '_topdir %s' % os.path.abspath(self.rpm_base)
                ])
            if not self.keep_temp:
                rpm_cmd.append('--clean')
            if self.quiet:
                rpm_cmd.append('--quiet')
            rpm_cmd.append(spec_path)
            nvr_string = '%{name}-%{version}-%{release}'
            src_rpm = nvr_string + '.src.rpm'
            non_src_rpm = '%{arch}/' + nvr_string + '.%{arch}.rpm'
            q_cmd = "rpm -q --qf '%s %s\\n' --specfile '%s'" % (
                src_rpm, non_src_rpm, spec_path)
            out = os.popen(q_cmd)
            try:
                binary_rpms = []
                source_rpm = None
                while 1:
                    line = out.readline()
                    if not line:
                        break
                    l = string.split(string.strip(line))
                    if not len(l) == 2:
                        raise AssertionError
                        binary_rpms.append(l[1])
                        source_rpm = source_rpm is None and l[0]

                status = out.close()
                if status:
                    raise DistutilsExecError('Failed to execute: %s' %
                                             repr(q_cmd))
            finally:
                out.close()

            self.spawn(rpm_cmd)
            if not self.dry_run:
                pyversion = self.distribution.has_ext_modules(
                ) and get_python_version()
            else:
                pyversion = 'any'
            if not self.binary_only:
                srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
                if not os.path.exists(srpm):
                    raise AssertionError
                    self.move_file(srpm, self.dist_dir)
                    filename = os.path.join(self.dist_dir, source_rpm)
                    self.distribution.dist_files.append(
                        ('bdist_rpm', pyversion, filename))
                if not self.source_only:
                    for rpm in binary_rpms:
                        rpm = os.path.join(rpm_dir['RPMS'], rpm)
                        if os.path.exists(rpm):
                            self.move_file(rpm, self.dist_dir)
                            filename = os.path.join(self.dist_dir,
                                                    os.path.basename(rpm))
                            self.distribution.dist_files.append(
                                ('bdist_rpm', pyversion, filename))

            return
コード例 #34
0
ファイル: cy_build.py プロジェクト: jvierstra/pysam
 def _get_egg_name(self):
     ei_cmd = self.get_finalized_command("egg_info")
     return Distribution(
         None, None, ei_cmd.egg_name, ei_cmd.egg_version,
         get_python_version(),
         self.distribution.has_ext_modules() and self.plat_name).egg_name()
コード例 #35
0
    def run(self):
        """Run the distutils command"""
        log.info("installing library code to %s" % self.bdist_dir)

        log.info("generating INFO_SRC and INFO_BIN files")
        generate_info_files()

        self.dist_name = get_dist_name(self.distribution,
                                       source_only_dist=True,
                                       python_version=get_python_version()[0])
        self.dist_target = os.path.join(self.dist_dir, self.dist_name)
        log.info("distribution will be available as '%s'" % self.dist_target)

        # build command: just to get the build_base
        cmdbuild = self.get_finalized_command("build")
        self.build_base = cmdbuild.build_base

        # install command
        install = self.reinitialize_command('install_lib',
                                            reinit_subcommands=1)
        install.compile = False
        install.warn_dir = 0
        install.install_dir = self.bdist_dir

        log.info("installing to %s" % self.bdist_dir)
        self.run_command('install_lib')

        # install extra files
        extra_files = {}
        for src, dest in extra_files.items():
            self.copy_file(src, dest)

        # install_egg_info command
        cmd_egginfo = self.get_finalized_command('install_egg_info')
        cmd_egginfo.install_dir = self.bdist_dir
        self.run_command('install_egg_info')
        # we need the py2.x converted to py2 in the filename
        old_egginfo = cmd_egginfo.get_outputs()[0]
        new_egginfo = old_egginfo.replace('-py' + sys.version[:3],
                                          '-py' + get_python_version()[0])
        move_file(old_egginfo, new_egginfo)

        # create distribution
        info_files = [
            ('README.txt', 'README.txt'),
            ('LICENSE.txt', 'LICENSE.txt'),
            ('README.rst', 'README.rst'),
            ('CONTRIBUTING.rst', 'CONTRIBUTING.rst'),
            ('docs/INFO_SRC', 'INFO_SRC'),
            ('docs/INFO_BIN', 'INFO_BIN'),
        ]
        copy_tree(self.bdist_dir, self.dist_target)
        pkg_info = mkpath(os.path.join(self.dist_target))
        for src, dst in info_files:
            if dst is None:
                copy_file(src, self.dist_target)
            else:
                copy_file(src, os.path.join(self.dist_target, dst))

        if not self.keep_temp:
            remove_tree(self.build_base, dry_run=self.dry_run)
コード例 #36
0
    def run(self):
        # Generate metadata first
        self.run_command("egg_info")

        # We run install_lib before install_data, because some data hacks
        # pull their data path from the install_lib command.
        log.info("installing library code to %s" % self.bdist_dir)
        instcmd = self.get_finalized_command('install')
        old_root = instcmd.root
        instcmd.root = None
        cmd = self.call_command('install_lib', warn_dir=0)
        instcmd.root = old_root

        all_outputs, ext_outputs = self.get_ext_outputs()
        self.stubs = []
        to_compile = []
        for (p, ext_name) in enumerate(ext_outputs):
            filename, ext = os.path.splitext(ext_name)
            pyfile = os.path.join(self.bdist_dir,
                                  strip_module(filename) + '.py')
            self.stubs.append(pyfile)
            log.info("creating stub loader for %s" % ext_name)
            if not self.dry_run:
                write_stub(os.path.basename(ext_name), pyfile)
            to_compile.append(pyfile)
            ext_outputs[p] = ext_name.replace(os.sep, '/')

        to_compile.extend(self.make_init_files())
        if to_compile:
            cmd.byte_compile(to_compile)

        if self.distribution.data_files:
            self.do_install_data()

        # Make the EGG-INFO directory
        archive_root = self.bdist_dir
        egg_info = os.path.join(archive_root, 'EGG-INFO')
        self.mkpath(egg_info)
        if self.distribution.scripts:
            script_dir = os.path.join(egg_info, 'scripts')
            log.info("installing scripts to %s" % script_dir)
            self.call_command('install_scripts',
                              install_dir=script_dir,
                              no_ep=1)

        self.copy_metadata_to(egg_info)
        native_libs = os.path.join(egg_info, "native_libs.txt")
        if all_outputs:
            log.info("writing %s" % native_libs)
            if not self.dry_run:
                ensure_directory(native_libs)
                libs_file = open(native_libs, 'wt')
                libs_file.write('\n'.join(all_outputs))
                libs_file.write('\n')
                libs_file.close()
        elif os.path.isfile(native_libs):
            log.info("removing %s" % native_libs)
            if not self.dry_run:
                os.unlink(native_libs)

        write_safety_flag(os.path.join(archive_root, 'EGG-INFO'),
                          self.zip_safe())

        if os.path.exists(os.path.join(self.egg_info, 'depends.txt')):
            log.warn(
                "WARNING: 'depends.txt' will not be used by setuptools 0.6!\n"
                "Use the install_requires/extras_require setup() args instead."
            )

        if self.exclude_source_files:
            self.zap_pyfiles()

        # Make the archive
        make_zipfile(self.egg_output,
                     archive_root,
                     verbose=self.verbose,
                     dry_run=self.dry_run,
                     mode=self.gen_header())
        if not self.keep_temp:
            remove_tree(self.bdist_dir, dry_run=self.dry_run)

        # Add to 'Distribution.dist_files' so that the "upload" command works
        getattr(self.distribution, 'dist_files', []).append(
            ('bdist_egg', get_python_version(), self.egg_output))
コード例 #37
0
ファイル: setup.py プロジェクト: vicpopov/omim
 def get_boost_python_builddir(self):
     return os.path.join(
         self.omim_builddir,
         'boost-build-python{}'.format(get_python_version()),
     )
コード例 #38
0
    def run(self):
        if (sys.platform != "win32"
                and (self.distribution.has_ext_modules()
                     or self.distribution.has_c_libraries())):
            raise DistutilsPlatformError \
                  ("distribution contains extensions and/or C libraries; "
                   "must be compiled on a Windows 32 platform")

        if not self.skip_build:
            self.run_command('build')

        install = self.reinitialize_command('install', reinit_subcommands=1)
        install.root = self.bdist_dir
        install.skip_build = self.skip_build
        install.warn_dir = 0
        install.plat_name = self.plat_name

        install_lib = self.reinitialize_command('install_lib')
        # we do not want to main pyc or pyo files
        install_lib.compile = 0
        install_lib.optimize = 0

        if self.distribution.has_ext_modules():
            # If we are building an installer for a Python version other
            # than the one we are currently running, then we need to ensure
            # our build_lib reflects the other Python version rather than ours.
            # Note that for target_version!=sys.version, we must have skipped the
            # build step, so there is no issue with enforcing the build of this
            # version.
            target_version = self.target_version
            if not target_version:
                assert self.skip_build, "Should have already checked this"
                target_version = '%d.%d' % sys.version_info[:2]
            plat_specifier = ".%s-%s" % (self.plat_name, target_version)
            build = self.get_finalized_command('build')
            build.build_lib = os.path.join(build.build_base,
                                           'lib' + plat_specifier)

        # Use a custom scheme for the zip-file, because we have to decide
        # at installation time which scheme to use.
        for key in ('purelib', 'platlib', 'headers', 'scripts', 'data'):
            value = key.upper()
            if key == 'headers':
                value = value + '/Include/$dist_name'
            setattr(install, 'install_' + key, value)

        log.info("installing to %s", self.bdist_dir)
        install.ensure_finalized()

        # avoid warning of 'install_lib' about installing
        # into a directory not in sys.path
        sys.path.insert(0, os.path.join(self.bdist_dir, 'PURELIB'))

        install.run()

        del sys.path[0]

        # And make an archive relative to the root of the
        # pseudo-installation tree.
        from tempfile import mktemp
        archive_basename = mktemp()
        fullname = self.distribution.get_fullname()
        arcname = self.make_archive(archive_basename,
                                    "zip",
                                    root_dir=self.bdist_dir)
        # create an exe containing the zip-file
        self.create_exe(arcname, fullname, self.bitmap)
        if self.distribution.has_ext_modules():
            pyversion = get_python_version()
        else:
            pyversion = 'any'
        self.distribution.dist_files.append(
            ('bdist_wininst', pyversion,
             self.get_installer_filename(fullname)))
        # remove the zip-file again
        log.debug("removing temporary file '%s'", arcname)
        os.remove(arcname)

        if not self.keep_temp:
            remove_tree(self.bdist_dir, dry_run=self.dry_run)
コード例 #39
0
    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.extend(py_include.split(os.path.pathsep))
        if plat_py_include != py_include:
            self.include_dirs.extend(plat_py_include.split(os.path.pathsep))

        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
            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
                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
        if sys.platform[:6] == 'cygwin':
            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")
コード例 #40
0
    def install(self,
                install_options,
                global_options=[],
                root=None,
                prefix=None,
                strip_file_prefix=None):
        if self.editable:
            self.install_editable(install_options,
                                  global_options,
                                  prefix=prefix)
            return
        if self.is_wheel:
            version = pip.wheel.wheel_version(self.source_dir)
            pip.wheel.check_compatibility(version, self.name)

            self.move_wheel_files(self.source_dir,
                                  root=root,
                                  prefix=prefix,
                                  strip_file_prefix=strip_file_prefix)
            self.install_succeeded = True
            return

        # Extend the list of global and install options passed on to
        # the setup.py call with the ones from the requirements file.
        # Options specified in requirements file override those
        # specified on the command line, since the last option given
        # to setup.py is the one that is used.
        global_options += self.options.get('global_options', [])
        install_options += self.options.get('install_options', [])

        if self.isolated:
            global_options = list(global_options) + ["--no-user-cfg"]

        temp_location = tempfile.mkdtemp('-record', 'pip-')
        record_filename = os.path.join(temp_location, 'install-record.txt')
        try:
            install_args = [sys.executable, "-u"]
            install_args.append('-c')
            install_args.append(SETUPTOOLS_SHIM % self.setup_py)
            install_args += list(global_options) + \
                ['install', '--record', record_filename]

            if not self.as_egg:
                install_args += ['--single-version-externally-managed']

            if root is not None:
                install_args += ['--root', root]
            if prefix is not None:
                install_args += ['--prefix', prefix]

            if self.pycompile:
                install_args += ["--compile"]
            else:
                install_args += ["--no-compile"]

            if running_under_virtualenv():
                py_ver_str = 'python' + sysconfig.get_python_version()
                install_args += [
                    '--install-headers',
                    os.path.join(sys.prefix, 'include', 'site', py_ver_str,
                                 self.name)
                ]
            msg = 'Running setup.py install for %s' % (self.name, )
            with open_spinner(msg) as spinner:
                with indent_log():
                    call_subprocess(
                        install_args + install_options,
                        cwd=self.source_dir,
                        show_stdout=False,
                        spinner=spinner,
                    )

            if not os.path.exists(record_filename):
                logger.debug('Record file %s not found', record_filename)
                return
            self.install_succeeded = True
            if self.as_egg:
                # there's no --always-unzip option we can pass to install
                # command so we unable to save the installed-files.txt
                return

            def prepend_root(path):
                if root is None or not os.path.isabs(path):
                    return path
                else:
                    return change_root(root, path)

            with open(record_filename) as f:
                for line in f:
                    directory = os.path.dirname(line)
                    if directory.endswith('.egg-info'):
                        egg_info_dir = prepend_root(directory)
                        break
                else:
                    logger.warning(
                        'Could not find .egg-info directory in install record'
                        ' for %s',
                        self,
                    )
                    # FIXME: put the record somewhere
                    # FIXME: should this be an error?
                    return
            new_lines = []
            with open(record_filename) as f:
                for line in f:
                    filename = line.strip()
                    if os.path.isdir(filename):
                        filename += os.path.sep
                    new_lines.append(
                        os.path.relpath(prepend_root(filename), egg_info_dir))
            inst_files_path = os.path.join(egg_info_dir, 'installed-files.txt')
            with open(inst_files_path, 'w') as f:
                f.write('\n'.join(new_lines) + '\n')
        finally:
            if os.path.exists(record_filename):
                os.remove(record_filename)
            rmtree(temp_location)
コード例 #41
0
 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')
コード例 #42
0
ファイル: run_all.py プロジェクト: plin1112/QUIP
from distutils.sysconfig import get_python_version

if 'QUIP_ROOT' in os.environ:
    quip_root = os.environ['QUIP_ROOT']
else:
    quip_root = os.path.join(os.getcwd(), '..')

try:
    quip_arch = os.environ['QUIP_ARCH']
except KeyError:
    raise RuntimeError(
        'You need to define the architecture using the QUIP_ARCH variable. Check out the arch/ subdirectory.'
    )
print('QUIP_ARCH', quip_arch)

platform = '{0}-{1}'.format(get_platform(), get_python_version())
print('platform', platform)

# extend sys.path
print(os.path.join(quip_root, 'build/{0}/'.format(quip_arch)))
sys.path.insert(0, os.path.join(quip_root, 'build/{0}/'.format(quip_arch)))

import quippy
print('Successfully imported quippy3')

# find tests and run them
# ONLY RUNS ONE NOW, THE ONE THAT IS DONE
suite = unittest.defaultTestLoader.discover(
    os.getcwd())  # fixme run all tests not just one
unittest.TextTestRunner().run(suite)
コード例 #43
0
    def finalize_options (self):
        from distutils import sysconfig

        self.set_undefined_options('build',
                                   ('build_lib', 'build_lib'),
                                   ('build_temp', 'build_temp'),
                                   ('compiler', 'compiler'),
                                   ('debug', 'debug'),
                                   ('force', 'force'))

        if self.package is None:
            self.package = self.distribution.ext_package

        self.extensions = self.distribution.ext_modules


        # Make sure Python's include directories (for Python.h, pyconfig.h,
        # etc.) are in the include search path.
        py_include = sysconfig.get_python_inc()
        plat_py_include = sysconfig.get_python_inc(plat_specific=1)
        if self.include_dirs is None:
            self.include_dirs = self.distribution.include_dirs or []
        if type(self.include_dirs) is StringType:
            self.include_dirs = string.split(self.include_dirs, os.pathsep)

        # Put the Python "system" include dir at the end, so that
        # any local include dirs take precedence.
        self.include_dirs.append(py_include)
        if plat_py_include != py_include:
            self.include_dirs.append(plat_py_include)

        if type(self.libraries) is StringType:
            self.libraries = [self.libraries]

        # Life is easier if we're not forever checking for None, so
        # simplify these options to empty lists if unset
        if self.libraries is None:
            self.libraries = []
        if self.library_dirs is None:
            self.library_dirs = []
        elif type(self.library_dirs) is StringType:
            self.library_dirs = string.split(self.library_dirs, os.pathsep)

        if self.rpath is None:
            self.rpath = []
        elif type(self.rpath) is StringType:
            self.rpath = string.split(self.rpath, os.pathsep)

        # for extensions under windows use different directories
        # for Release and Debug builds.
        # also Python's library directory must be appended to library_dirs
        if os.name == 'nt':
            self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
            if self.debug:
                self.build_temp = os.path.join(self.build_temp, "Debug")
            else:
                self.build_temp = os.path.join(self.build_temp, "Release")

            # Append the source distribution include and library directories,
            # this allows distutils on windows to work in the source tree
            self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
            self.library_dirs.append(os.path.join(sys.exec_prefix, 'PCBuild'))

        # OS/2 (EMX) doesn't support Debug vs Release builds, but has the 
        # import libraries in its "Config" subdirectory
        if os.name == 'os2':
            self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))

        # for extensions under Cygwin and AtheOS Python's library directory must be
        # appended to library_dirs
        if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
            if string.find(sys.executable, sys.exec_prefix) != -1:
                # 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('.')

        # The argument parsing will result in self.define being a string, but
        # it has to be a list of 2-tuples.  All the preprocessor symbols
        # specified by the 'define' option will be set to '1'.  Multiple
        # symbols can be separated with commas.

        if self.define:
            defines = string.split(self.define, ',')
            self.define = map(lambda symbol: (symbol, '1'), defines)

        # The option for macros to undefine is also a string from the
        # option parsing, but has to be a list.  Multiple symbols can also
        # be separated with commas here.
        if self.undef:
            self.undef = string.split(self.undef, ',')
コード例 #44
0
    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')
        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 type(self.library_dirs) is StringType:
            self.library_dirs = string.split(self.library_dirs, os.pathsep)

        if self.rpath is None:
            self.rpath = []
        elif type(self.rpath) is StringType:
            self.rpath = string.split(self.rpath, os.pathsep)

        # for extensions under windows use different directories
        # for Release and Debug builds.
        # also Python's library directory must be appended to library_dirs
        if os.name == 'nt':
            # the 'libs' directory is for binary installs - we assume that
            # must be the *native* platform.  But we don't really support
            # cross-compiling via a binary install anyway, so we let it go.
            self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
            if self.debug:
                self.build_temp = os.path.join(self.build_temp, "Debug")
            else:
                self.build_temp = os.path.join(self.build_temp, "Release")

            # Append the source distribution include and library directories,
            # this allows distutils on windows to work in the source tree
            self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
            if MSVC_VERSION >= 9:
                # Use the .lib files for the correct architecture
                if self.plat_name == 'win32':
                    suffix = 'win32'
                else:
                    # win-amd64 or win-ia64
                    suffix = self.plat_name[4:]
                if MSVC_VERSION >= 14:
                    ldir = os.path.join(sys.exec_prefix, 'PCbuild')
                    if suffix != 'win32':
                        ldir = os.path.join(ldir, suffix)
                    self.library_dirs.append(ldir)
                else:
                    # We could have been built in one of two places; add both
                    for d in ('PCbuild',), ('PC', 'VS9.0'):
                        new_lib = os.path.join(sys.exec_prefix, *d)
                        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 building extensions with a shared Python library,
        # Python's library directory must be appended to library_dirs
        # See Issues: #1600860, #4366
        if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
            if not sysconfig.python_build:
                # building third party extensions
                self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
            else:
                # building python standard extensions
                self.library_dirs.append('.')

        # The argument parsing will result in self.define being a string, but
        # it has to be a list of 2-tuples.  All the preprocessor symbols
        # specified by the 'define' option will be set to '1'.  Multiple
        # symbols can be separated with commas.

        if self.define:
            defines = self.define.split(',')
            self.define = map(lambda symbol: (symbol, '1'), defines)

        # The option for macros to undefine is also a string from the
        # option parsing, but has to be a list.  Multiple symbols can also
        # be separated with commas here.
        if self.undef:
            self.undef = self.undef.split(',')

        if self.swig_opts is None:
            self.swig_opts = []
        else:
            self.swig_opts = self.swig_opts.split(' ')

        # Finally add the user include and library directories if requested
        if self.user:
            user_include = os.path.join(USER_BASE, "include")
            user_lib = os.path.join(USER_BASE, "lib")
            if os.path.isdir(user_include):
                self.include_dirs.append(user_include)
            if os.path.isdir(user_lib):
                self.library_dirs.append(user_lib)
                self.rpath.append(user_lib)
コード例 #45
0
    def build_dlib():
        """use cmake to build and install the extension
        """
        if cmake_path is None:
            raise DistutilsSetupError("Cannot find cmake in the path. Please specify its path with --cmake parameter.")

        platform_arch = platform.architecture()[0]
        log.info("Detected Python architecture: %s" % platform_arch)

        # make sure build artifacts are generated for the version of Python currently running
        cmake_extra_arch = []
        if sys.version_info >= (3, 0):
            cmake_extra_arch += ['-DPYTHON3=yes']

        if platform_arch == '64bit' and sys.platform == "win32":
            # 64bit build on Windows

            if not generator_set:
                # see if we can deduce the 64bit default generator
                cmake_extra_arch += get_msvc_win64_generator()

            # help cmake to find Python library in 64bit Python in Windows
            #  because cmake is 32bit and cannot find PYTHON_LIBRARY from registry.
            inc_dir = get_python_inc()
            cmake_extra_arch += ['-DPYTHON_INCLUDE_DIR={inc}'.format(inc=inc_dir)]

            # this imitates cmake in path resolution
            py_ver = get_python_version()
            for ext in [py_ver.replace(".", "") + '.lib', py_ver + 'mu.lib', py_ver + 'm.lib', py_ver + 'u.lib']:
                py_lib = os.path.abspath(os.path.join(inc_dir, '../libs/', 'python' + ext))
                if os.path.exists(py_lib):
                    cmake_extra_arch += ['-DPYTHON_LIBRARY={lib}'.format(lib=py_lib)]
                    break

        build_dir = os.path.join(script_dir, "./tools/python/build")
        if os.path.exists(build_dir):
            log.info('Removing build directory %s' % build_dir)
            rmtree(build_dir)

        try:
            os.makedirs(build_dir)
        except OSError:
            pass

        # cd build
        os.chdir(build_dir)
        log.info('Configuring cmake ...')
        cmake_cmd = [
            cmake_path,
            "..",
        ] + cmake_extra + cmake_extra_arch
        if run_process(cmake_cmd):
            raise DistutilsSetupError("cmake configuration failed!")

        log.info('Build using cmake ...')

        cmake_cmd = [
            cmake_path,
            "--build", ".",
            "--config", cmake_config,
            "--target", "install",
        ]

        if run_process(cmake_cmd):
            raise DistutilsSetupError("cmake build failed!")

        # cd back where setup awaits
        os.chdir(script_dir)
コード例 #46
0
    def run(self):
        if DEBUG:
            print("before _get_package_data():")
            print("vendor =", self.vendor)
            print("packager =", self.packager)
            print("doc_files =", self.doc_files)
            print("changelog =", self.changelog)

        # make directories
        if self.spec_only:
            spec_dir = self.dist_dir
            self.mkpath(spec_dir)
        else:
            rpm_dir = {}
            for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
                rpm_dir[d] = os.path.join(self.rpm_base, d)
                self.mkpath(rpm_dir[d])
            spec_dir = rpm_dir['SPECS']

        # Spec file goes into 'dist_dir' if '--spec-only specified',
        # build/rpm.<plat> otherwise.
        spec_path = os.path.join(spec_dir,
                                 "%s.spec" % self.distribution.get_name())
        self.execute(write_file, (spec_path, self._make_spec_file()),
                     "writing '%s'" % spec_path)

        if self.spec_only:  # stop if requested
            return

        # Make a source distribution and copy to SOURCES directory with
        # optional icon.
        saved_dist_files = self.distribution.dist_files[:]
        sdist = self.reinitialize_command('sdist')
        if self.use_bzip2:
            sdist.formats = ['bztar']
        else:
            sdist.formats = ['gztar']
        self.run_command('sdist')
        self.distribution.dist_files = saved_dist_files

        source = sdist.get_archive_files()[0]
        source_dir = rpm_dir['SOURCES']
        self.copy_file(source, source_dir)

        if self.icon:
            if os.path.exists(self.icon):
                self.copy_file(self.icon, source_dir)
            else:
                raise DistutilsFileError("icon file '%s' does not exist" %
                                         self.icon)

        # build package
        log.info("building RPMs")
        rpm_cmd = ['rpm']
        if os.path.exists('/usr/bin/rpmbuild') or \
           os.path.exists('/bin/rpmbuild'):
            rpm_cmd = ['rpmbuild']

        if self.source_only:  # what kind of RPMs?
            rpm_cmd.append('-bs')
        elif self.binary_only:
            rpm_cmd.append('-bb')
        else:
            rpm_cmd.append('-ba')
        if self.rpm3_mode:
            rpm_cmd.extend(
                ['--define',
                 '_topdir %s' % os.path.abspath(self.rpm_base)])
        if not self.keep_temp:
            rpm_cmd.append('--clean')

        if self.quiet:
            rpm_cmd.append('--quiet')

        rpm_cmd.append(spec_path)
        # Determine the binary rpm names that should be built out of this spec
        # file
        # Note that some of these may not be really built (if the file
        # list is empty)
        nvr_string = "%{name}-%{version}-%{release}"
        src_rpm = nvr_string + ".src.rpm"
        non_src_rpm = "%{arch}/" + nvr_string + ".%{arch}.rpm"
        q_cmd = r"rpm -q --qf '%s %s\n' --specfile '%s'" % (
            src_rpm, non_src_rpm, spec_path)

        out = os.popen(q_cmd)
        try:
            binary_rpms = []
            source_rpm = None
            while True:
                line = out.readline()
                if not line:
                    break
                l = line.strip().split()
                assert (len(l) == 2)
                binary_rpms.append(l[1])
                # The source rpm is named after the first entry in the spec file
                if source_rpm is None:
                    source_rpm = l[0]

            status = out.close()
            if status:
                raise DistutilsExecError("Failed to execute: %s" % repr(q_cmd))

        finally:
            out.close()

        self.spawn(rpm_cmd)

        if not self.dry_run:
            if self.distribution.has_ext_modules():
                pyversion = get_python_version()
            else:
                pyversion = 'any'

            if not self.binary_only:
                srpm = os.path.join(rpm_dir['SRPMS'], source_rpm)
                assert (os.path.exists(srpm))
                self.move_file(srpm, self.dist_dir)
                filename = os.path.join(self.dist_dir, source_rpm)
                self.distribution.dist_files.append(
                    ('bdist_rpm', pyversion, filename))

            if not self.source_only:
                for rpm in binary_rpms:
                    rpm = os.path.join(rpm_dir['RPMS'], rpm)
                    if os.path.exists(rpm):
                        self.move_file(rpm, self.dist_dir)
                        filename = os.path.join(self.dist_dir,
                                                os.path.basename(rpm))
                        self.distribution.dist_files.append(
                            ('bdist_rpm', pyversion, filename))
コード例 #47
0
ファイル: setup.py プロジェクト: yxliang/dlib
    def build_dlib():
        """use cmake to build and install the extension
        """
        if cmake_path is None:
            cmake_install_url = "https://cmake.org/install/"
            message = ("You can install cmake using the instructions at " +
                       cmake_install_url)
            msg_pkgmanager = ("You can install cmake on {0} using "
                              "`sudo {1} install cmake`.")
            if sys.platform == "darwin":
                pkgmanagers = ('brew', 'port')
                for manager in pkgmanagers:
                    if find_executable(manager) is not None:
                        message = msg_pkgmanager.format('OSX', manager)
                        break
            elif sys.platform.startswith('linux'):
                try:
                    import distro
                except ImportError as err:
                    import pip
                    pip_exit = pip.main(['install', '-q', 'distro'])
                    if pip_exit > 0:
                        log.debug("Unable to install `distro` to identify "
                                  "the recommended command. Falling back "
                                  "to default error message.")
                        distro = err
                    else:
                        import distro
                if not isinstance(distro, ImportError):
                    distname = distro.id()
                    if distname in ('debian', 'ubuntu'):
                        message = msg_pkgmanager.format(
                            distname.title(), 'apt-get')
                    elif distname in ('fedora', 'centos', 'redhat'):
                        pkgmanagers = ("dnf", "yum")
                        for manager in pkgmanagers:
                            if find_executable(manager) is not None:
                                message = msg_pkgmanager.format(
                                    distname.title(), manager)
                                break
            raise DistutilsSetupError(
                "Cannot find cmake, ensure it is installed and in the path.\n"
                + message + "\n"
                "You can also specify its path with --cmake parameter.")

        platform_arch = platform.architecture()[0]
        log.info("Detected Python architecture: %s" % platform_arch)

        # make sure build artifacts are generated for the version of Python currently running
        cmake_extra_arch = []

        inc_dir = get_python_inc()
        lib_dir = get_config_var('LIBDIR')
        if (inc_dir != None):
            cmake_extra_arch += ['-DPYTHON_INCLUDE_DIR=' + inc_dir]
        if (lib_dir != None):
            cmake_extra_arch += ['-DCMAKE_LIBRARY_PATH=' + lib_dir]

        if sys.version_info >= (3, 0):
            cmake_extra_arch += ['-DPYTHON3=yes']

        log.info("Detected platform: %s" % sys.platform)
        if sys.platform == "darwin":
            # build on OS X

            # by default, cmake will choose the system python lib in /usr/lib
            # this checks the sysconfig and will correctly pick up a brewed python lib
            # e.g. in /usr/local/Cellar
            py_ver = get_python_version()
            # check: in some virtual environments the libpython has the form "libpython_#m.dylib
            py_lib = os.path.join(get_config_var('LIBDIR'),
                                  'libpython' + py_ver + '.dylib')
            if not os.path.isfile(py_lib):
                py_lib = os.path.join(get_config_var('LIBDIR'),
                                      'libpython' + py_ver + 'm.dylib')

            cmake_extra_arch += ['-DPYTHON_LIBRARY={lib}'.format(lib=py_lib)]

        if sys.platform == "win32":
            if platform_arch == '64bit':
                cmake_extra_arch += ['-DCMAKE_GENERATOR_PLATFORM=x64']
                # Setting the cmake generator only works in versions of cmake >= 3.1
                if (LooseVersion(get_cmake_version(cmake_path)) <
                        LooseVersion("3.1.0")):
                    raise DistutilsSetupError(
                        "You need to install a newer version of cmake. Version 3.1 or newer is required."
                    )

            # this imitates cmake in path resolution
            py_ver = get_python_version()
            for ext in [
                    py_ver.replace(".", "") + '.lib', py_ver + 'mu.lib',
                    py_ver + 'm.lib', py_ver + 'u.lib'
            ]:
                py_lib = os.path.abspath(
                    os.path.join(inc_dir, '../libs/', 'python' + ext))
                if os.path.exists(py_lib):
                    cmake_extra_arch += [
                        '-DPYTHON_LIBRARY={lib}'.format(lib=py_lib)
                    ]
                    break

        build_dir = os.path.join(script_dir, "./tools/python/build")
        if os.path.exists(build_dir):
            log.info('Removing build directory %s' % build_dir)
            rmtree(build_dir)

        try:
            os.makedirs(build_dir)
        except OSError:
            pass

        # cd build
        os.chdir(build_dir)
        log.info('Configuring cmake ...')
        cmake_cmd = [
            cmake_path,
            "..",
        ] + cmake_extra + cmake_extra_arch
        if run_process(cmake_cmd):
            raise DistutilsSetupError("cmake configuration failed!")

        log.info('Build using cmake ...')

        cmake_cmd = [
            cmake_path,
            "--build",
            ".",
            "--config",
            cmake_config,
            "--target",
            "install",
        ]

        if run_process(cmake_cmd):
            raise DistutilsSetupError("cmake build failed!")

        # cd back where setup awaits
        os.chdir(script_dir)
コード例 #48
0
ファイル: bdist_rpm.py プロジェクト: thinhils/HackerToolBox
    def run(self):

        if DEBUG:
            print "before _get_package_data():"
            print "vendor =", self.vendor
            print "packager =", self.packager
            print "doc_files =", self.doc_files
            print "changelog =", self.changelog

        # make directories
        if self.spec_only:
            spec_dir = self.dist_dir
            self.mkpath(spec_dir)
        else:
            rpm_dir = {}
            for d in ('SOURCES', 'SPECS', 'BUILD', 'RPMS', 'SRPMS'):
                rpm_dir[d] = os.path.join(self.rpm_base, d)
                self.mkpath(rpm_dir[d])
            spec_dir = rpm_dir['SPECS']

        # Spec file goes into 'dist_dir' if '--spec-only specified',
        # build/rpm.<plat> otherwise.
        spec_path = os.path.join(spec_dir,
                                 "%s.spec" % self.distribution.get_name())
        self.execute(write_file, (spec_path, self._make_spec_file()),
                     "writing '%s'" % spec_path)

        if self.spec_only:  # stop if requested
            return

        # Make a source distribution and copy to SOURCES directory with
        # optional icon.
        saved_dist_files = self.distribution.dist_files[:]
        sdist = self.reinitialize_command('sdist')
        if self.use_bzip2:
            sdist.formats = ['bztar']
        else:
            sdist.formats = ['gztar']
        self.run_command('sdist')
        self.distribution.dist_files = saved_dist_files

        source = sdist.get_archive_files()[0]
        source_dir = rpm_dir['SOURCES']
        self.copy_file(source, source_dir)

        if self.icon:
            if os.path.exists(self.icon):
                self.copy_file(self.icon, source_dir)
            else:
                raise DistutilsFileError, \
                      "icon file '%s' does not exist" % self.icon

        # build package
        log.info("building RPMs")
        rpm_cmd = ['rpm']
        if os.path.exists('/usr/bin/rpmbuild') or \
           os.path.exists('/bin/rpmbuild'):
            rpm_cmd = ['rpmbuild']
        if self.source_only:  # what kind of RPMs?
            rpm_cmd.append('-bs')
        elif self.binary_only:
            rpm_cmd.append('-bb')
        else:
            rpm_cmd.append('-ba')
        if self.rpm3_mode:
            rpm_cmd.extend(
                ['--define',
                 '_topdir %s' % os.path.abspath(self.rpm_base)])
        if not self.keep_temp:
            rpm_cmd.append('--clean')
        rpm_cmd.append(spec_path)
        self.spawn(rpm_cmd)

        # XXX this is a nasty hack -- we really should have a proper way to
        # find out the names of the RPM files created; also, this assumes
        # that RPM creates exactly one source and one binary RPM.
        if not self.dry_run:
            if not self.binary_only:
                srpms = glob.glob(os.path.join(rpm_dir['SRPMS'], "*.rpm"))
                assert len(srpms) == 1, \
                       "unexpected number of SRPM files found: %s" % srpms
                dist_file = ('bdist_rpm', 'any', self._dist_path(srpms[0]))
                self.distribution.dist_files.append(dist_file)
                self.move_file(srpms[0], self.dist_dir)

            if not self.source_only:
                rpms = glob.glob(os.path.join(rpm_dir['RPMS'], "*/*.rpm"))
                debuginfo = glob.glob(
                    os.path.join(rpm_dir['RPMS'], "*/*debuginfo*.rpm"))
                if debuginfo:
                    rpms.remove(debuginfo[0])
                assert len(rpms) == 1, \
                       "unexpected number of RPM files found: %s" % rpms
                dist_file = ('bdist_rpm', get_python_version(),
                             self._dist_path(rpms[0]))
                self.distribution.dist_files.append(dist_file)
                self.move_file(rpms[0], self.dist_dir)
                if debuginfo:
                    dist_file = ('bdist_rpm', get_python_version(),
                                 self._dist_path(debuginfo[0]))
                    self.move_file(debuginfo[0], self.dist_dir)
コード例 #49
0
# Notes about STD_LIB_DIR
# Consider arch-specific installation for STD_LIB_DIR definition
# :mod:`distutils.sysconfig` contains to much hardcoded values to rely on
#
# :see: `Problems with /usr/lib64 builds <http://bugs.python.org/issue1294959>`_
# :see: `FHS <http://www.pathname.com/fhs/pub/fhs-2.3.html#LIBLTQUALGTALTERNATEFORMATESSENTIAL>`_
if sys.platform.startswith('win'):
    PY_SOURCE_EXTS = ('py', 'pyw')
    PY_COMPILED_EXTS = ('dll', 'pyd')
    STD_LIB_DIR = get_python_lib(standard_lib=1)
else:
    PY_SOURCE_EXTS = ('py', )
    PY_COMPILED_EXTS = ('so', )
    # extend lib dir with some arch-dependant paths
    STD_LIB_DIR = join(get_config_var("LIBDIR"),
                       "python%s" % get_python_version())

BUILTIN_MODULES = dict(
    zip(sys.builtin_module_names, [1] * len(sys.builtin_module_names)))


class NoSourceFile(Exception):
    """exception raised when we are not able to get a python
    source file for a precompiled file
    """


class LazyObject(object):
    def __init__(self, module, obj):
        self.module = module
        self.obj = obj
コード例 #50
0
ファイル: build.py プロジェクト: WilliamRJohns/glacier.io
def init_env():
    from setup.build_environment import msvc, is64bit, win_inc, win_lib, NMAKE
    from distutils import sysconfig
    linker = None
    if isunix:
        cc = os.environ.get('CC', 'gcc')
        cxx = os.environ.get('CXX', 'g++')
        debug = ''
        # debug = '-ggdb'
        cflags = os.environ.get(
            'OVERRIDE_CFLAGS',
            '-Wall -DNDEBUG %s -fno-strict-aliasing -pipe' % debug)
        cflags = shlex.split(cflags) + ['-fPIC']
        ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall')
        ldflags = shlex.split(ldflags)
        cflags += shlex.split(os.environ.get('CFLAGS', ''))
        ldflags += shlex.split(os.environ.get('LDFLAGS', ''))
        cflags += ['-fvisibility=hidden']

    if islinux:
        cflags.append('-pthread')
        ldflags.append('-shared')
        cflags.append('-I' + sysconfig.get_python_inc())
        ldflags.append('-lpython' + sysconfig.get_python_version())

    if isbsd:
        cflags.append('-pthread')
        ldflags.append('-shared')
        cflags.append('-I' + sysconfig.get_python_inc())
        ldflags.append('-lpython' + sysconfig.get_python_version())

    if ishaiku:
        cflags.append('-lpthread')
        ldflags.append('-shared')
        cflags.append('-I' + sysconfig.get_python_inc())
        ldflags.append('-lpython' + sysconfig.get_python_version())

    if isosx:
        cflags.append('-D_OSX')
        ldflags.extend('-bundle -undefined dynamic_lookup'.split())
        cflags.extend(['-fno-common', '-dynamic'])
        cflags.append('-I' + sysconfig.get_python_inc())

    if iswindows:
        cc = cxx = msvc.cc
        cflags = '/c /nologo /MD /W3 /EHsc /DNDEBUG'.split()
        ldflags = '/DLL /nologo /INCREMENTAL:NO /NODEFAULTLIB:libcmt.lib'.split(
        )
        # cflags = '/c /nologo /Ox /MD /W3 /EHsc /Zi'.split()
        # ldflags = '/DLL /nologo /INCREMENTAL:NO /DEBUG'.split()
        if is64bit:
            cflags.append('/GS-')

        for p in win_inc:
            cflags.append('-I' + p)
        for p in win_lib:
            ldflags.append('/LIBPATH:' + p)
        cflags.append('-I%s' % sysconfig.get_python_inc())
        ldflags.append('/LIBPATH:' + os.path.join(sysconfig.PREFIX, 'libs'))
        linker = msvc.linker
    return namedtuple('Environment', 'cc cxx cflags ldflags linker make')(
        cc=cc,
        cxx=cxx,
        cflags=cflags,
        ldflags=ldflags,
        linker=linker,
        make=NMAKE if iswindows else 'make')
コード例 #51
0
ファイル: setup.py プロジェクト: vicpopov/omim
 def get_boost_config_path(self):
     return os.path.join(
         self.omim_builddir,
         'python{}-config.jam'.format(get_python_version()),
     )
コード例 #52
0
ファイル: app.py プロジェクト: wengole/git-cola
# Copyright (C) 2009, 2010, 2011, 2012, 2013
# David Aguilar <*****@*****.**>
"""Provides the main() routine and ColaApplicaiton"""
from __future__ import division, absolute_import, unicode_literals

import argparse
import glob
import os
import signal
import sys

# Make homebrew work by default
if sys.platform == 'darwin':
    from distutils import sysconfig
    python_version = sysconfig.get_python_version()
    homebrew_mods = '/usr/local/lib/python%s/site-packages' % python_version
    if os.path.isdir(homebrew_mods):
        sys.path.append(homebrew_mods)

import sip
sip.setapi('QString', 1)
sip.setapi('QDate', 1)
sip.setapi('QDateTime', 1)
sip.setapi('QTextStream', 1)
sip.setapi('QTime', 1)
sip.setapi('QUrl', 1)
sip.setapi('QVariant', 1)

try:
    from PyQt4 import QtGui
    from PyQt4 import QtCore
コード例 #53
0
    def get_exe_bytes(self):
        # If a target-version other than the current version has been
        # specified, then using the MSVC version from *this* build is no good.
        # Without actually finding and executing the target version and parsing
        # its sys.version, we just hard-code our knowledge of old versions.
        # NOTE: Possible alternative is to allow "--target-version" to
        # specify a Python executable rather than a simple version string.
        # We can then execute this program to obtain any info we need, such
        # as the real sys.version string for the build.
        cur_version = get_python_version()

        # If the target version is *later* than us, then we assume they
        # use what we use
        # string compares seem wrong, but are what sysconfig.py itself uses
        if self.target_version and self.target_version < cur_version:
            if self.target_version < "2.4":
                bv = '6.0'
            elif self.target_version == "2.4":
                bv = '7.1'
            elif self.target_version == "2.5":
                bv = '8.0'
            elif self.target_version <= "3.2":
                bv = '9.0'
            elif self.target_version <= "3.4":
                bv = '10.0'
            else:
                bv = '14.0'
        else:
            # for current version - use authoritative check.
            try:
                from msvcrt import CRT_ASSEMBLY_VERSION
            except ImportError:
                # cross-building, so assume the latest version
                bv = '14.0'
            else:
                bv = '.'.join(CRT_ASSEMBLY_VERSION.split('.', 2)[:2])
                if bv == '14.11':
                    # v141 and v140 are binary compatible,
                    # so keep using the 14.0 stub.
                    bv = '14.0'

        # wininst-x.y.exe is in the same directory as this file
        directory = os.path.dirname(__file__)
        # we must use a wininst-x.y.exe built with the same C compiler
        # used for python.  XXX What about mingw, borland, and so on?

        # if plat_name starts with "win" but is not "win32"
        # we want to strip "win" and leave the rest (e.g. -amd64)
        # for all other cases, we don't want any suffix
        if self.plat_name != 'win32' and self.plat_name[:3] == 'win':
            sfix = self.plat_name[3:]
        else:
            sfix = ''

        filename = os.path.join(directory, "wininst-%s%s.exe" % (bv, sfix))
        try:
            f = open(filename, "rb")
        except IOError as e:
            raise DistutilsFileError(
                str(e) +
                ', %s not included in the Debian packages.' % filename)
        try:
            return f.read()
        finally:
            f.close()
コード例 #54
0
    def run(self):
        build_scripts = self.reinitialize_command('build_scripts')
        build_scripts.executable = 'python'

        if not self.skip_build:
            self.run_command('build')

        install = self.reinitialize_command('install', reinit_subcommands=True)
        install.root = self.bdist_dir
        install.compile = False
        install.skip_build = self.skip_build
        install.warn_dir = False

        # A wheel without setuptools scripts is more cross-platform.
        # Use the (undocumented) `no_ep` option to setuptools'
        # install_scripts command to avoid creating entry point scripts.
        install_scripts = self.reinitialize_command('install_scripts')
        install_scripts.no_ep = True

        # Use a custom scheme for the archive, because we have to decide
        # at installation time which scheme to use.
        for key in ('headers', 'scripts', 'data', 'purelib', 'platlib'):
            setattr(install, 'install_' + key,
                    os.path.join(self.data_dir, key))

        basedir_observed = ''

        if os.name == 'nt':
            # win32 barfs if any of these are ''; could be '.'?
            # (distutils.command.install:change_roots bug)
            basedir_observed = os.path.normpath(
                os.path.join(self.data_dir, '..'))
            self.install_libbase = self.install_lib = basedir_observed

        setattr(install,
                'install_purelib' if self.root_is_pure else 'install_platlib',
                basedir_observed)

        logger.info("installing to %s", self.bdist_dir)

        self.run_command('install')

        archive_basename = self.get_archive_basename()

        pseudoinstall_root = os.path.join(self.dist_dir, archive_basename)
        if not self.relative:
            archive_root = self.bdist_dir
        else:
            archive_root = os.path.join(
                self.bdist_dir, self._ensure_relative(install.install_base))

        self.set_undefined_options('install_egg_info',
                                   ('target', 'egginfo_dir'))
        self.distinfo_dir = os.path.join(self.bdist_dir,
                                         '%s.dist-info' % self.wheel_dist_name)
        self.egg2dist(self.egginfo_dir, self.distinfo_dir)

        self.write_wheelfile(self.distinfo_dir)

        self.write_record(self.bdist_dir, self.distinfo_dir)

        # Make the archive
        if not os.path.exists(self.dist_dir):
            os.makedirs(self.dist_dir)
        wheel_name = archive_wheelfile(pseudoinstall_root, archive_root)

        # Sign the archive
        if 'WHEEL_TOOL' in os.environ:
            subprocess.call([os.environ['WHEEL_TOOL'], 'sign', wheel_name])

        # Add to 'Distribution.dist_files' so that the "upload" command works
        getattr(self.distribution, 'dist_files', []).append(
            ('bdist_wheel', get_python_version(), wheel_name))

        if not self.keep_temp:
            if self.dry_run:
                logger.info('removing %s', self.bdist_dir)
            else:
                rmtree(self.bdist_dir)
コード例 #55
0
class SourceGPL(sdist):
    """Create source GNU GPLv2 distribution for specific Python version

    This class generates a source distribution GNU GPLv2 licensed for the
    Python version that is used. SourceGPL is used by other commands to
    generate RPM or other packages.
    """
    description = 'create a source distribution for Python v%s.x' % (
        get_python_version()[0])
    user_options = [
        ('debug', None, "turn debugging on"),
        ('bdist-dir=', 'd',
         "temporary directory for creating the distribution"),
        ('keep-temp', 'k', "keep the pseudo-installation tree around after " +
         "creating the distribution archive"),
        ('dist-dir=', 'd', "directory to put final built distributions in"),
    ]

    boolean_options = [
        'keep-temp',
    ]

    negative_opt = []

    def initialize_options(self):
        """Initialize the options"""
        self.bdist_dir = None
        self.keep_temp = 0
        self.dist_dir = None
        self.plat_name = ''
        self.debug = False

    def finalize_options(self):
        """Finalize the options"""
        if self.bdist_dir is None:
            bdist_base = self.get_finalized_command('bdist').bdist_base
            self.bdist_dir = os.path.join(bdist_base, 'dist')

        self.set_undefined_options(
            'bdist',
            ('dist_dir', 'dist_dir'),
        )

        python_version = get_python_version()
        pyver = python_version[0:2]

        # Change classifiers
        new_classifiers = []
        for classifier in self.distribution.metadata.classifiers:
            if (classifier.startswith("Programming Language ::")
                    and (pyver not in classifier)):
                log.info("removing classifier %s" % classifier)
                continue
            new_classifiers.append(classifier)
        self.distribution.metadata.classifiers = new_classifiers

        license = open('README.txt', 'r').read()
        self.distribution.metadata.long_description += "\n" + license

    def run(self):
        """Run the distutils command"""
        log.info("installing library code to %s" % self.bdist_dir)

        log.info("generating INFO_SRC and INFO_BIN files")
        generate_info_files()

        self.dist_name = get_dist_name(self.distribution,
                                       source_only_dist=True,
                                       python_version=get_python_version()[0])
        self.dist_target = os.path.join(self.dist_dir, self.dist_name)
        log.info("distribution will be available as '%s'" % self.dist_target)

        # build command: just to get the build_base
        cmdbuild = self.get_finalized_command("build")
        self.build_base = cmdbuild.build_base

        # install command
        install = self.reinitialize_command('install_lib',
                                            reinit_subcommands=1)
        install.compile = False
        install.warn_dir = 0
        install.install_dir = self.bdist_dir

        log.info("installing to %s" % self.bdist_dir)
        self.run_command('install_lib')

        # install extra files
        extra_files = {}
        for src, dest in extra_files.items():
            self.copy_file(src, dest)

        # install_egg_info command
        cmd_egginfo = self.get_finalized_command('install_egg_info')
        cmd_egginfo.install_dir = self.bdist_dir
        self.run_command('install_egg_info')
        # we need the py2.x converted to py2 in the filename
        old_egginfo = cmd_egginfo.get_outputs()[0]
        new_egginfo = old_egginfo.replace('-py' + sys.version[:3],
                                          '-py' + get_python_version()[0])
        move_file(old_egginfo, new_egginfo)

        # create distribution
        info_files = [
            ('README.txt', 'README.txt'),
            ('LICENSE.txt', 'LICENSE.txt'),
            ('README.rst', 'README.rst'),
            ('CONTRIBUTING.rst', 'CONTRIBUTING.rst'),
            ('docs/INFO_SRC', 'INFO_SRC'),
            ('docs/INFO_BIN', 'INFO_BIN'),
        ]
        copy_tree(self.bdist_dir, self.dist_target)
        pkg_info = mkpath(os.path.join(self.dist_target))
        for src, dst in info_files:
            if dst is None:
                copy_file(src, self.dist_target)
            else:
                copy_file(src, os.path.join(self.dist_target, dst))

        if not self.keep_temp:
            remove_tree(self.build_base, dry_run=self.dry_run)
コード例 #56
0
 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
     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)
     self.include_dirs.append(py_include)
     if plat_py_include != py_include:
         self.include_dirs.append(plat_py_include)
     self.ensure_string_list('libraries')
     if self.libraries is None:
         self.libraries = []
     if self.library_dirs is None:
         self.library_dirs = []
     elif type(self.library_dirs) is StringType:
         self.library_dirs = string.split(self.library_dirs, os.pathsep)
     if self.rpath is None:
         self.rpath = []
     elif type(self.rpath) is StringType:
         self.rpath = string.split(self.rpath, os.pathsep)
     if os.name == 'nt':
         self.library_dirs.append(os.path.join(sys.exec_prefix, 'libs'))
         if self.debug:
             self.build_temp = os.path.join(self.build_temp, 'Debug')
         else:
             self.build_temp = os.path.join(self.build_temp, 'Release')
         self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
         if MSVC_VERSION == 9:
             if self.plat_name == 'win32':
                 suffix = ''
             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)
         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'))
     if os.name == 'os2':
         self.library_dirs.append(os.path.join(sys.exec_prefix, 'Config'))
     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 sys.executable.startswith(os.path.join(sys.exec_prefix, 'bin')):
             self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
         else:
             self.library_dirs.append('.')
     if self.define:
         defines = self.define.split(',')
         self.define = map(lambda symbol: (symbol, '1'), 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)
     return
コード例 #57
0
    def run(self):
        """Run the distutils command"""
        log.info("installing library code to %s" % self.bdist_dir)

        log.info("generating INFO_SRC and INFO_BIN files")
        generate_info_files()

        dist_name = self.distribution.get_fullname()
        self.dist_target = os.path.join(self.dist_dir, dist_name)
        log.info("distribution will be available as '%s'" % self.dist_target)

        # build command: just to get the build_base
        cmdbuild = self.get_finalized_command("build")
        self.build_base = cmdbuild.build_base

        # install command
        install = self.reinitialize_command('install_lib',
                                            reinit_subcommands=1)
        install.compile = False
        install.warn_dir = 0
        install.install_dir = self.bdist_dir

        log.info("installing to %s" % self.bdist_dir)
        self.run_command('install_lib')

        # install extra files
        extra_files = {}
        for src, dest in extra_files.items():
            self.copy_file(src, dest)

        # install_egg_info command
        cmd_egginfo = self.get_finalized_command('install_egg_info')
        cmd_egginfo.install_dir = self.bdist_dir
        self.run_command('install_egg_info')

        installed_files = install.get_outputs()

        # remove the GPL license
        ignore = [
            os.path.join(self.bdist_dir,
                         os.path.normcase('mysql/__init__.py')),
            os.path.join(self.bdist_dir, 'mysql', 'connector', 'locales',
                         'eng', '__init__.py'),
            cmd_egginfo.target,
        ]
        django_backend = os.path.join('connector', 'django')
        for pyfile in installed_files:
            if '.py' not in pyfile:
                continue
            if pyfile not in ignore and django_backend not in pyfile:
                commercial.remove_gpl(pyfile, dry_run=self.dry_run)

        log.info("setting license information in version.py")
        loc_version_py = os.path.join(
            self.bdist_dir, os.path.normcase('mysql/connector/version.py'))
        version_py = open(loc_version_py, 'r').readlines()
        for (nr, line) in enumerate(version_py):
            if line.startswith('LICENSE'):
                version_py[nr] = 'LICENSE = "Commercial"\n'
        fp = open(loc_version_py, 'w')
        fp.write(''.join(version_py))
        fp.close()

        # compile and remove sources
        if not self.include_sources:
            util.byte_compile(installed_files,
                              optimize=0,
                              force=True,
                              prefix=install.install_dir)
            self._remove_sources()
            if get_python_version().startswith('3'):
                log.info("copying byte code from __pycache__")
                self._copy_from_pycache(os.path.join(self.bdist_dir, 'mysql'))
                self._copy_from_pycache(os.path.join(self.bdist_dir, 'mysqlx'))

        # create distribution
        info_files = [
            ('cpyint/data/commercial/README_COM.txt', 'README.txt'),
            ('cpyint/data/commercial/LICENSE_COM.txt', 'LICENSE.txt'),
            ('README.rst', 'README.rst'),
            ('CONTRIBUTING.rst', 'CONTRIBUTING.rst'),
            ('docs/INFO_SRC', 'INFO_SRC'),
            ('docs/INFO_BIN', 'INFO_BIN'),
        ]
        copy_tree(self.bdist_dir, self.dist_target)
        mkpath(os.path.join(self.dist_target))
        xy_needle = 'Connector/Python X.Y'
        xy_sub = 'Connector/Python {0}.{1}'
        for src, dst in info_files:
            if dst is None:
                dest_name, _ = copy_file(src, self.dist_target)
            else:
                dest_name, _ = copy_file(src,
                                         os.path.join(self.dist_target, dst))

            with open(dest_name, 'r+') as fp:
                content = fp.readlines()
                for i, line in enumerate(content):
                    if xy_needle in line:
                        content[i] = line.replace(xy_needle,
                                                  xy_sub.format(*VERSION[0:2]))

                fp.seek(0)
                fp.write(''.join(content))

        add_docs(os.path.join(self.dist_target, 'docs'))

        self._write_setuppy()

        if not self.keep_temp:
            remove_tree(self.build_base, dry_run=self.dry_run)
コード例 #58
0
ファイル: extensions.py プロジェクト: liwp-stephen/calibre
    debug = ''
    # debug = '-ggdb'
    cflags = os.environ.get(
        'OVERRIDE_CFLAGS',
        '-Wall -DNDEBUG %s -fno-strict-aliasing -pipe' % debug)
    cflags = shlex.split(cflags) + ['-fPIC']
    ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall')
    ldflags = shlex.split(ldflags)
    cflags += shlex.split(os.environ.get('CFLAGS', ''))
    ldflags += shlex.split(os.environ.get('LDFLAGS', ''))

if islinux:
    cflags.append('-pthread')
    ldflags.append('-shared')
    cflags.append('-I' + sysconfig.get_python_inc())
    ldflags.append('-lpython' + sysconfig.get_python_version())

if isbsd:
    cflags.append('-pthread')
    ldflags.append('-shared')
    cflags.append('-I' + sysconfig.get_python_inc())
    ldflags.append('-lpython' + sysconfig.get_python_version())

if isosx:
    cflags.append('-D_OSX')
    ldflags.extend('-bundle -undefined dynamic_lookup'.split())
    cflags.extend(['-fno-common', '-dynamic'])
    cflags.append('-I' + sysconfig.get_python_inc())

if iswindows:
    cc = cxx = msvc.cc
コード例 #59
0
    def finalize_options(self):
        self.set_undefined_options('build', ('build_base', 'build_base'))
        self.set_undefined_options('bdist', ('dist_dir', 'dist_dir'))

        if not self.prefix:
            self.prefix = os.path.join(
                self.build_base,
                DIST_PATH_FORMAT.format(self.python_version[0],
                                        self.python_version[2]))

        self.supported_versions = ['2.7', '3.4', '3.5', '3.6', '3.7', '3.8']

        self.dist_path = {}

        for py_ver in self.supported_versions:
            self.dist_path[py_ver] = os.path.join(
                self.build_base, DIST_PATH_FORMAT.format(*py_ver.split('.')))

        if self.python_version not in self.supported_versions:
            raise DistutilsOptionError(
                "The --python-version should be a supported version, one "
                "of %s" % ','.join(self.supported_versions))

        if self.python_version[0] != get_python_version()[0]:
            raise DistutilsError(
                "Python v3 distributions need to be build with a "
                "supported Python v3 installation.")

        self.with_cext = any(
            (self.with_mysql_capi, self.with_protobuf_include_dir,
             self.with_protobuf_lib_dir, self.with_protoc))

        if self.with_cext:
            if not self.with_mysql_capi or \
               not os.path.isdir(self.with_mysql_capi):
                log.error("Location of MySQL C API (Connector/C) must be "
                          "provided.")
                sys.exit(1)
            else:
                cmd_build = self.get_finalized_command('build')
                self.connc_lib = os.path.join(cmd_build.build_temp, 'connc',
                                              'lib')
                self.connc_include = os.path.join(cmd_build.build_temp,
                                                  'connc', 'include')

                self._finalize_connector_c(self.with_mysql_capi)

            if not self.with_protobuf_include_dir or \
               not os.path.isdir(self.with_protobuf_include_dir):
                log.error("Location of Protobuf include directory must be "
                          "provided.")
                sys.exit(1)
            else:
                self.with_protobuf_include_dir = \
                    os.path.abspath(self.with_protobuf_include_dir)

            if not self.with_protobuf_lib_dir or \
               not os.path.isdir(self.with_protobuf_lib_dir):
                log.error("Location of Protobuf library directory must be "
                          "provided.")
                sys.exit(1)
            else:
                self.with_protobuf_lib_dir = \
                    os.path.abspath(self.with_protobuf_lib_dir)

            if not self.with_protoc or not os.path.isfile(self.with_protoc):
                log.error("Protobuf protoc binary is not valid.")
                sys.exit(1)
            else:
                self.with_protoc = os.path.abspath(self.with_protoc)
コード例 #60
0
    def run(self):
        build_scripts = self.reinitialize_command('build_scripts')
        build_scripts.executable = 'python'
        build_scripts.force = True

        build_ext = self.reinitialize_command('build_ext')
        build_ext.inplace = False

        if not self.skip_build:
            self.run_command('build')

        install = self.reinitialize_command('install',
                                            reinit_subcommands=True)
        install.root = self.bdist_dir
        install.compile = False
        install.skip_build = self.skip_build
        install.warn_dir = False

        # A wheel without setuptools scripts is more cross-platform.
        # Use the (undocumented) `no_ep` option to setuptools'
        # install_scripts command to avoid creating entry point scripts.
        install_scripts = self.reinitialize_command('install_scripts')
        install_scripts.no_ep = True

        # Use a custom scheme for the archive, because we have to decide
        # at installation time which scheme to use.
        for key in ('headers', 'scripts', 'data', 'purelib', 'platlib'):
            setattr(install,
                    'install_' + key,
                    os.path.join(self.data_dir, key))

        basedir_observed = ''

        if os.name == 'nt':
            # win32 barfs if any of these are ''; could be '.'?
            # (distutils.command.install:change_roots bug)
            basedir_observed = os.path.normpath(os.path.join(self.data_dir, '..'))
            self.install_libbase = self.install_lib = basedir_observed

        setattr(install,
                'install_purelib' if self.root_is_pure else 'install_platlib',
                basedir_observed)

        logger.info("installing to %s", self.bdist_dir)

        self.run_command('install')

        impl_tag, abi_tag, plat_tag = self.get_tag()
        archive_basename = "{}-{}-{}-{}".format(self.wheel_dist_name, impl_tag, abi_tag, plat_tag)
        if not self.relative:
            archive_root = self.bdist_dir
        else:
            archive_root = os.path.join(
                self.bdist_dir,
                self._ensure_relative(install.install_base))

        self.set_undefined_options('install_egg_info', ('target', 'egginfo_dir'))
        distinfo_dirname = '{}-{}.dist-info'.format(
            safer_name(self.distribution.get_name()),
            safer_version(self.distribution.get_version()))
        distinfo_dir = os.path.join(self.bdist_dir, distinfo_dirname)
        self.egg2dist(self.egginfo_dir, distinfo_dir)

        self.write_wheelfile(distinfo_dir)

        # Make the archive
        if not os.path.exists(self.dist_dir):
            os.makedirs(self.dist_dir)

        wheel_path = os.path.join(self.dist_dir, archive_basename + '.whl')
        with WheelFile(wheel_path, 'w', self.compression) as wf:
            wf.write_files(archive_root)

        # Add to 'Distribution.dist_files' so that the "upload" command works
        getattr(self.distribution, 'dist_files', []).append(
            ('bdist_wheel', get_python_version(), wheel_path))

        if not self.keep_temp:
            logger.info('removing %s', self.bdist_dir)
            if not self.dry_run:
                rmtree(self.bdist_dir, onerror=remove_readonly)