Beispiel #1
0
    def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
        """Compile 'src' to product 'obj'."""
        src_flags = {}
        if is_f_file(src) and not has_f90_header(src):
            flavor = ":f77"
            compiler = self.compiler_f77
            src_flags = get_f77flags(src)
            extra_compile_args = self.extra_f77_compile_args or []
        elif is_free_format(src):
            flavor = ":f90"
            compiler = self.compiler_f90
            if compiler is None:
                raise DistutilsExecError(
                    "f90 not supported by %s needed for %s"
                    % (self.__class__.__name__, src)
                )
            extra_compile_args = self.extra_f90_compile_args or []
        else:
            flavor = ":fix"
            compiler = self.compiler_fix
            if compiler is None:
                raise DistutilsExecError(
                    "f90 (fixed) not supported by %s needed for %s"
                    % (self.__class__.__name__, src)
                )
            extra_compile_args = self.extra_f90_compile_args or []
        if self.object_switch[-1] == " ":
            o_args = [self.object_switch.strip(), obj]
        else:
            o_args = [self.object_switch.strip() + obj]

        assert self.compile_switch.strip()
        s_args = [self.compile_switch, src]

        if extra_compile_args:
            log.info(
                "extra %s options: %r" % (flavor[1:], " ".join(extra_compile_args))
            )

        extra_flags = src_flags.get(self.compiler_type, [])
        if extra_flags:
            log.info("using compile options from source: %r" % " ".join(extra_flags))

        command = (
            compiler
            + cc_args
            + extra_flags
            + s_args
            + o_args
            + extra_postargs
            + extra_compile_args
        )

        display = "%s: %s" % (os.path.basename(compiler[0]) + flavor, src)
        try:
            self.spawn(command, display=display)
        except DistutilsExecError:
            msg = str(get_exception())
            raise CompileError(msg)
Beispiel #2
0
    def finalize_options(self):
        # if a test dir isn't specified explicitly try to find one
        if self.test_dir is None:
            for path in (os.path.join(REPODIR, 'test',
                                      'module'), os.path.join(REPODIR, 'test'),
                         os.path.join(REPODIR, 'tests', 'module'),
                         os.path.join(REPODIR, 'tests'),
                         os.path.join(MODULEDIR, 'test'),
                         os.path.join(MODULEDIR, 'tests')):
                if os.path.exists(path):
                    self.test_dir = path
                    break
            else:
                raise DistutilsExecError(
                    'cannot automatically determine test directory')

        self.test_args = []
        if self.targets is not None:
            targets = [
                os.path.join(self.test_dir, x) for x in self.targets.split()
            ]
            self.test_args.extend(targets)
        else:
            self.test_args.append(self.test_dir)
        self.coverage = bool(self.coverage)
        self.skip_build = bool(self.skip_build)
        if self.verbose:
            self.test_args.append('-v')
        if self.match is not None:
            self.test_args.extend(['-k', self.match])

        if self.coverage or self.report:
            try:
                import pytest_cov
                self.test_args.extend(['--cov', MODULE_NAME])
            except ImportError:
                raise DistutilsExecError(
                    'install pytest-cov for coverage support')

            coveragerc = os.path.join(REPODIR, '.coveragerc')
            if os.path.exists(coveragerc):
                self.test_args.extend(['--cov-config', coveragerc])

            if self.report is None:
                # disable coverage report output
                self.test_args.extend(['--cov-report='])
            else:
                self.test_args.extend(['--cov-report', self.report])

        if self.jobs is not None:
            try:
                import xdist
                self.test_args.extend(['-n', self.jobs])
            except ImportError:
                raise DistutilsExecError(
                    'install pytest-xdist for -j/--jobs support')

        # add custom pytest args
        self.test_args.extend(shlex.split(self.pytest_args))
def get_mysql_config_info(mysql_config):
    """Get MySQL information using mysql_config tool

    Returns a dict.
    """
    options = ['cflags', 'include', 'libs', 'libs_r', 'plugindir', 'version']

    cmd = [mysql_config] + ["--{0}".format(opt) for opt in options]

    try:
        proc = Popen(cmd, stdout=PIPE, universal_newlines=True)
        stdout, _ = proc.communicate()
    except OSError as exc:
        raise DistutilsExecError("Failed executing mysql_config: {0}".format(
            str(exc)))

    info = {}
    for option, line in zip(options, stdout.split('\n')):
        info[option] = line.strip()

    info['version'] = tuple([int(v) for v in info['version'].split('.')[0:3]])
    libs = shlex.split(info['libs'])
    info['lib_dir'] = libs[0].replace('-L', '')
    info['libs'] = [lib.replace('-l', '') for lib in libs[1:]]

    libs = shlex.split(info['libs_r'])
    info['lib_r_dir'] = libs[0].replace('-L', '')
    info['libs_r'] = [lib.replace('-l', '') for lib in libs[1:]]

    info['include'] = info['include'].replace('-I', '')

    # Try to figure out the architecture
    info['arch'] = None
    if os.name == 'posix':
        pathname = os.path.join(info['lib_dir'], 'lib' + info['libs'][0]) + '*'
        lib = glob(pathname)[0]

        stdout = None
        try:
            proc = Popen(['file', lib], stdout=PIPE, universal_newlines=True)
            stdout, _ = proc.communicate()
        except OSError as exc:
            raise DistutilsExecError(
                "Although the system seems POSIX, the file-command could not "
                "be executed: {0}".format(str(exc)))

        if stdout:
            if '64' in stdout:
                info['arch'] = "x86_64"
            else:
                info['arch'] = "i386"
        else:
            raise DistutilsExecError(
                "Failed getting out put from the file-command")
    else:
        raise DistutilsExecError(
            "Cannot determine architecture on {0} systems".format(os.name))

    return info
Beispiel #4
0
def spawn(cmd, search_path=1, verbose=0, dry_run=0, env=None):
    """Run another program, specified as a command list 'cmd', in a new process.

    'cmd' is just the argument list for the new process, ie.
    cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
    There is no way to run a program with a name different from that of its
    executable.

    If 'search_path' is true (the default), the system's executable
    search path will be used to find the program; otherwise, cmd[0]
    must be the exact path to the executable.  If 'dry_run' is true,
    the command will not actually be run.

    Raise DistutilsExecError if running the program fails in any way; just
    return on success.
    """
    # cmd is documented as a list, but just in case some code passes a tuple
    # in, protect our %-formatting code against horrible death
    cmd = list(cmd)

    log.info(subprocess.list2cmdline(cmd))
    if dry_run:
        return

    if search_path:
        executable = find_executable(cmd[0])
        if executable is not None:
            cmd[0] = executable

    env = env if env is not None else dict(os.environ)

    if sys.platform == 'darwin':
        from distutils.util import MACOSX_VERSION_VAR, get_macosx_target_ver

        macosx_target_ver = get_macosx_target_ver()
        if macosx_target_ver:
            env[MACOSX_VERSION_VAR] = macosx_target_ver

    try:
        proc = subprocess.Popen(cmd, env=env)
        proc.wait()
        exitcode = proc.returncode
    except OSError as exc:
        if not DEBUG:
            cmd = cmd[0]
        raise DistutilsExecError("command %r failed: %s" %
                                 (cmd, exc.args[-1])) from exc

    if exitcode:
        if not DEBUG:
            cmd = cmd[0]
        raise DistutilsExecError("command %r failed with exit code %s" %
                                 (cmd, exitcode))
Beispiel #5
0
def write_pkgcore_ebd_funclists(root, target, scripts_dir, python_base='.'):
    "Generate bash function lists from ebd implementation for env filtering." ""
    ebd_dir = target
    if root != '/':
        ebd_dir = os.path.join(root, target.lstrip('/'))
    log.info("Writing ebd function lists to %s" %
             os.path.join(ebd_dir, 'funcnames'))
    try:
        os.makedirs(os.path.join(ebd_dir, 'funcnames'))
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise

    # Add scripts dir to PATH and set the current python binary for filter-env
    # usage in global scope.
    env = {
        'PATH':
        os.pathsep.join(
            [os.path.abspath(scripts_dir),
             os.environ.get('PATH', '')]),
        'PKGCORE_PYTHON_BINARY':
        sys.executable,
        'PKGCORE_PYTHONPATH':
        os.path.abspath(python_base),
    }

    # generate global function list
    with open(os.path.join(ebd_dir, 'funcnames', 'global'), 'w') as f:
        if subprocess.call([
                os.path.join(os.getcwd(), 'ebd',
                             'generate_global_func_list.bash')
        ],
                           cwd=ebd_dir,
                           env=env,
                           stdout=f):
            raise DistutilsExecError("generating global function list failed")

    # generate EAPI specific function lists
    eapis = (x.split('.')[0]
             for x in os.listdir(os.path.join(os.getcwd(), 'ebd', 'eapi'))
             if x.split('.')[0].isdigit())
    for eapi in sorted(eapis):
        with open(os.path.join(ebd_dir, 'funcnames', eapi), 'w') as f:
            if subprocess.call([
                    os.path.join(os.getcwd(), 'ebd',
                                 'generate_eapi_func_list.bash'), eapi
            ],
                               cwd=ebd_dir,
                               env=env,
                               stdout=f):
                raise DistutilsExecError(
                    "generating EAPI %s function list failed" % eapi)
Beispiel #6
0
def write_pkgcore_ebd_cmdlists(root, target):
    "Generate bash function lists from ebd implementation for env filtering." ""
    ebd_dir = target
    if root != '/':
        ebd_dir = os.path.join(root, target.lstrip('/'))
    os.makedirs(os.path.join(ebd_dir, 'cmds'), exist_ok=True)

    # generate EAPI specific command lists
    with pkgdist.syspath(pkgdist.PACKAGEDIR):
        from pkgcore.ebuild.eapi import EAPI
        for eapi_obj in EAPI.known_eapis.values():
            eapi = str(eapi_obj)
            os.makedirs(os.path.join(ebd_dir, 'cmds', eapi), exist_ok=True)

            path = os.path.join(ebd_dir, 'cmds', eapi, 'banned')
            log.info(f'writing EAPI {eapi} banned command list: {path!r}')
            with open(path, 'w') as f:
                if subprocess.call([
                        os.path.join(pkgdist.REPODIR, 'ebd',
                                     'generate_eapi_cmd_list'), '-b', eapi
                ],
                                   cwd=ebd_dir,
                                   stdout=f):
                    raise DistutilsExecError(
                        f'generating EAPI {eapi} banned command list failed')

            path = os.path.join(ebd_dir, 'cmds', eapi, 'deprecated')
            log.info(f'writing EAPI {eapi} deprecated command list: {path!r}')
            with open(path, 'w') as f:
                if subprocess.call([
                        os.path.join(pkgdist.REPODIR, 'ebd',
                                     'generate_eapi_cmd_list'), '-d', eapi
                ],
                                   cwd=ebd_dir,
                                   stdout=f):
                    raise DistutilsExecError(
                        f'generating EAPI {eapi} deprecated command list failed'
                    )

            path = os.path.join(ebd_dir, 'cmds', eapi, 'internal')
            log.info(f'writing EAPI {eapi} internal command list: {path!r}')
            with open(path, 'w') as f:
                if subprocess.call([
                        os.path.join(pkgdist.REPODIR, 'ebd',
                                     'generate_eapi_cmd_list'), '-i', eapi
                ],
                                   cwd=ebd_dir,
                                   stdout=f):
                    raise DistutilsExecError(
                        f'generating EAPI {eapi} internal command list failed')
Beispiel #7
0
 def run(self):
     import subprocess
     try:
         # Hide stdout but allow stderr
         subprocess.check_call(["pandoc", "-v"], stdout=open(os.devnull))
     except subprocess.CalledProcessError:
         raise DistutilsExecError(
             "rst2ipynb requires the Haskell program 'pandoc'. It seems to be installed, but it did not work properly."
         )
     except OSError:
         raise DistutilsExecError(
             "rst2ipynb requires the Haskell program 'pandoc'. You need to install it on your system."
         )
     install.run(self)
Beispiel #8
0
def write_pkgcore_ebd_eapi_libs(root,
                                target,
                                scripts_dir=None,
                                python_base='.'):
    "Generate bash EAPI scope libs for sourcing." ""
    if scripts_dir is None:
        scripts_dir = os.path.join(pkgdist.REPODIR, 'bin')
    ebd_dir = target
    if root != '/':
        ebd_dir = os.path.join(root, target.lstrip('/'))
    log.info("Writing ebd libs %s" % os.path.join(ebd_dir, 'libs'))

    # Add scripts dir to PATH and set the current python binary for filter-env
    # usage in global scope.
    env = {
        'PATH':
        os.pathsep.join([pkgdist.SCRIPTS_DIR,
                         os.environ.get('PATH', '')]),
        'PKGCORE_PYTHON_BINARY': sys.executable,
        'PKGCORE_PYTHONPATH': os.path.abspath(python_base),
    }

    script = os.path.join(pkgdist.REPODIR, 'ebd', 'generate_eapi_lib')
    with pkgdist.syspath(pkgdist.PACKAGEDIR):
        from pkgcore.ebuild.eapi import EAPI
        for eapi_obj in EAPI.known_eapis.values():
            eapi = str(eapi_obj)
            os.makedirs(os.path.join(ebd_dir, 'libs', eapi), exist_ok=True)

            # generate global scope lib
            with open(os.path.join(ebd_dir, 'libs', eapi, 'global'), 'w') as f:
                if subprocess.call([script, eapi],
                                   cwd=ebd_dir,
                                   env=env,
                                   stdout=f):
                    raise DistutilsExecError(
                        f"generating global scope EAPI {eapi} lib failed")

            for phase in eapi_obj.phases.values():
                # generate phase scope lib
                with open(os.path.join(ebd_dir, 'libs', eapi, phase),
                          'w') as f:
                    if subprocess.call([script, '-s', phase, eapi],
                                       cwd=ebd_dir,
                                       env=env,
                                       stdout=f):
                        raise DistutilsExecError(
                            f"generating {phase} phase scope EAPI {eapi} lib failed"
                        )
Beispiel #9
0
    def build_extension(self, ext):
        if not isinstance(ext, Executable):
            build_ext.build_extension(self, ext)
            return

        cmd = [sys.executable, ext.script] + ext.options + [ext.target]
        if self.force:
            cmd += ["--force"]
        log.debug("running '{}'".format(" ".join(cmd)))
        if not self.dry_run:
            env = self._compiler_env.copy()
            if ext.env:
                env.update(ext.env)
            p = subprocess.run(cmd, cwd=ext.cwd, env=env)
            if p.returncode != 0:
                from distutils.errors import DistutilsExecError

                raise DistutilsExecError("running '{}' script failed".format(
                    ext.script))

        exe_fullpath = os.path.join(ext.output_dir, ext.target)

        dest_path = self.get_ext_fullpath(ext.name)
        mkpath(os.path.dirname(dest_path),
               verbose=self.verbose,
               dry_run=self.dry_run)

        copy_file(exe_fullpath,
                  dest_path,
                  verbose=self.verbose,
                  dry_run=self.dry_run)
Beispiel #10
0
def CCompiler_spawn(self, cmd, display=None):
    """
    Execute a command in a sub-process.

    Parameters
    ----------
    cmd : str
        The command to execute.
    display : str or sequence of str, optional
        The text to add to the log file kept by `numpy.distutils`.
        If not given, `display` is equal to `cmd`.

    Returns
    -------
    None

    Raises
    ------
    DistutilsExecError
        If the command failed, i.e. the exit status was not 0.

    """
    if display is None:
        display = cmd
        if is_sequence(display):
            display = ' '.join(list(display))
    log.info(display)
    try:
        subprocess.check_output(cmd)
    except subprocess.CalledProcessError as exc:
        o = exc.output
        s = exc.returncode
    except OSError:
        # OSError doesn't have the same hooks for the exception
        # output, but exec_command() historically would use an
        # empty string for EnvironmentError (base class for
        # OSError)
        o = b''
        # status previously used by exec_command() for parent
        # of OSError
        s = 127
    else:
        # use a convenience return here so that any kind of
        # caught exception will execute the default code after the
        # try / except block, which handles various exceptions
        return None

    if is_sequence(cmd):
        cmd = ' '.join(list(cmd))
    try:
        print(o)
    except UnicodeError:
        # When installing through pip, `o` can contain non-ascii chars
        pass
    if re.search(b'Too many open files', o):
        msg = '\nTry rerunning setup command until build succeeds.'
    else:
        msg = ''
    raise DistutilsExecError('Command "%s" failed with exit status %d%s' %
                            (cmd, s, msg))
Beispiel #11
0
def _spawn_openvms(cmd, search_path=1, verbose=0, dry_run=0):
    log.info(' '.join(cmd))
    if dry_run:
        return
    try:
        proc = subprocess.Popen(cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
    except OSError:
        proc = subprocess.Popen(cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE,
                                shell=True)
    data, error = proc.communicate()
    rc = proc.wait()
    if data:
        data = data.decode()
    else:
        data = ''
    if error:
        error = error.decode()
    else:
        error = ''
    if verbose:
        log.info(data)
        log.info(error)
    if rc:
        if error == '':
            error = data
        raise DistutilsExecError("command %r failed: %r" % (cmd, error))
Beispiel #12
0
    def check_version(self, required_version, this_version):
        this_version = tuple(this_version)
        #print("req '%s' this '%s'" %(required_version, this_version))
        min_length = min(len(required_version), len(this_version))
        for pos in range(min_length):
            t_val = this_version[pos]
            test_val = required_version[pos]
            #print("\t %d: req '%s' this '%s'" %( pos, test_val, t_val))

            this_type = type(t_val)
            if this_type == type(" "):
                t_val = int(t_val)

            if type(test_val) == type(" "):
                test_val = int(test_val)

            if t_val > test_val:
                # already larger
                return 1
            elif t_val == test_val:
                continue
            elif t_val < test_val:
                return 0
            else:
                raise DistutilsExecError("incorrect version specification")
        # problematic: 0.9 < 0.9.0, but assures that 0.9.1 > 0.9
        if len(required_version) > len(this_version): return 0
        return 1
Beispiel #13
0
def spawn(cmd, search_path=1, verbose=0, dry_run=0):
    """Run another program, specified as a command list 'cmd', in a new process.

    'cmd' is just the argument list for the new process, ie.
    cmd[0] is the program to run and cmd[1:] are the rest of its arguments.
    There is no way to run a program with a name different from that of its
    executable.

    If 'search_path' is true (the default), the system's executable
    search path will be used to find the program; otherwise, cmd[0]
    must be the exact path to the executable.  If 'dry_run' is true,
    the command will not actually be run.

    Raise DistutilsExecError if running the program fails in any way; just
    return on success.
    """
    # cmd is documented as a list, but just in case some code passes a tuple
    # in, protect our %-formatting code against horrible death
    cmd = list(cmd)

    log.info(' '.join(cmd))
    if dry_run:
        return

    if search_path:
        executable = find_executable(cmd[0])
        if executable is not None:
            cmd[0] = executable

    env = None
    if sys.platform == 'darwin':
        global _cfg_target, _cfg_target_split
        if _cfg_target is None:
            from distutils import sysconfig
            _cfg_target = sysconfig.get_config_var(
                'MACOSX_DEPLOYMENT_TARGET') or ''
            if _cfg_target:
                _cfg_target_split = [int(x) for x in _cfg_target.split('.')]
        if _cfg_target:
            # ensure that the deployment target of build process is not less
            # than that used when the interpreter was built. This ensures
            # extension modules are built with correct compatibility values
            cur_target = os.environ.get('MACOSX_DEPLOYMENT_TARGET',
                                        _cfg_target)
            if _cfg_target_split > [int(x) for x in cur_target.split('.')]:
                my_msg = ('$MACOSX_DEPLOYMENT_TARGET mismatch: '
                          'now "%s" but "%s" during configure' %
                          (cur_target, _cfg_target))
                raise DistutilsPlatformError(my_msg)
            env = dict(os.environ, MACOSX_DEPLOYMENT_TARGET=cur_target)

    proc = subprocess.Popen(cmd, env=env)
    proc.wait()
    exitcode = proc.returncode

    if exitcode:
        if not DEBUG:
            cmd = cmd[0]
        raise DistutilsExecError("command %r failed with exit code %s" %
                                 (cmd, exitcode))
Beispiel #14
0
def _spawn_qnx(cmd, search_path=1, verbose=0, dry_run=0):
    log.info(' '.join(cmd))
    if dry_run:
        return
    try:
        if search_path:
            rc = os.spawnvp(os.P_WAIT, cmd[0], cmd)
        else:
            rc = os.spawnv(os.P_WAIT, cmd[0], cmd)
    except OSError as exc:
        raise DistutilsExecError("command '%s' failed: %s" %
                                 (cmd[0], exc.args[-1]))
    if rc != 0:
        msg = "command '%s' failed with exit status %d" % (cmd[0], rc)
        log.debug(msg)
        raise DistutilsExecError(msg)
Beispiel #15
0
def write_pkgcore_lookup_configs(python_base, install_prefix, injected_bin_path=()):
    """Generate file of install path constants."""
    path = os.path.join(python_base, "pkgcore", "_const.py")
    try:
        os.makedirs(os.path.dirname(path))
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise
    log.info("writing lookup config to %r" % path)

    with open(path, "w") as f:
        os.chmod(path, 0o644)
        # write more dynamic _const file for wheel installs
        if install_prefix != os.path.abspath(sys.prefix):
            import textwrap
            f.write(textwrap.dedent("""\
                import os.path as osp
                import sys

                from snakeoil import process

                INSTALL_PREFIX = osp.abspath(sys.prefix)
                DATA_PATH = osp.join(INSTALL_PREFIX, {!r})
                CONFIG_PATH = osp.join(INSTALL_PREFIX, {!r})
                LIBDIR_PATH = osp.join(INSTALL_PREFIX, {!r})
                EBD_PATH = osp.join(INSTALL_PREFIX, {!r})
                INJECTED_BIN_PATH = ()
                CP_BINARY = process.find_binary('cp')
            """.format(
                DATA_INSTALL_OFFSET, CONFIG_INSTALL_OFFSET,
                LIBDIR_INSTALL_OFFSET, EBD_INSTALL_OFFSET)))
        else:
            f.write("INSTALL_PREFIX=%r\n" % install_prefix)
            f.write("DATA_PATH=%r\n" %
                    os.path.join(install_prefix, DATA_INSTALL_OFFSET))
            f.write("CONFIG_PATH=%r\n" %
                    os.path.join(install_prefix, CONFIG_INSTALL_OFFSET))
            f.write("LIBDIR_PATH=%r\n" %
                    os.path.join(install_prefix, LIBDIR_INSTALL_OFFSET))
            f.write("EBD_PATH=%r\n" %
                    os.path.join(install_prefix, EBD_INSTALL_OFFSET))

            # This is added to suppress the default behaviour of looking
            # within the repo for a bin subdir.
            f.write("INJECTED_BIN_PATH=%r\n" % (tuple(injected_bin_path),))

            # Static paths for various utilities.
            from snakeoil import process
            required_progs = ('cp',)
            try:
                for prog in required_progs:
                    prog_path = process.find_binary(prog)
                    f.write("%s_BINARY=%r\n" % (prog.upper(), prog_path))
            except process.CommandNotFound:
                raise DistutilsExecError(
                    "generating lookup config failed: required utility %r missing from PATH" % (prog,))

            f.close()
            byte_compile([path], prefix=python_base)
            byte_compile([path], optimize=2, prefix=python_base)
Beispiel #16
0
 def compile(self,
             sources,
             output_dir=None,
             macros=None,
             include_dirs=None,
             debug=0,
             extra_preargs=None,
             extra_postargs=None,
             depends=None):
     if output_dir:
         try:
             os.makedirs(output_dir)
         except OSError:
             pass
     objects = []
     for src in sources:
         file, ext = os.path.splitext(src)
         if output_dir:
             obj = os.path.join(output_dir, os.path.basename(file) + ".o")
         else:
             obj = file + ".o"
         if ext == ".f90":
             self.compiler_so = ["gfortran"]
             #cc_args = ["-O", "-c", "-ffree-form"]
             cc_args = ["-c"]
             extra_postargs = []
         try:
             self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
                        extra_postargs)
         except DistutilsExecError(msg):
             raise CompileError(msg)
         objects.append(obj)
     return objects
Beispiel #17
0
    def preprocess(self, source, output_file=None, macros=None,
                   include_dirs=None, extra_preargs=None, extra_postargs=None):
        fixed_args = self._fix_compile_args(None, macros, include_dirs)
        ignore, macros, include_dirs = fixed_args
        pp_opts = gen_preprocess_options(macros, include_dirs)
        pp_args = self.preprocessor + pp_opts
        if output_file:
            pp_args.extend(['-o', output_file])
        if extra_preargs:
            pp_args[:0] = extra_preargs
        if extra_postargs:
            pp_args.extend(extra_postargs)
        pp_args.append(source)

        # We need to preprocess: either we're being forced to, or we're
        # generating output to stdout, or there's a target output file and
        # the source file is newer than the target (or the target doesn't
        # exist).
        if self.force or output_file is None or newer(source, output_file):
            if output_file:
                self.mkpath(os.path.dirname(output_file))
            try:
                # iOS: since clang is not available, we send a nicer error message:
                if (sys.platform == 'darwin' and os.uname().machine.startswith('iP')):
                    raise DistutilsExecError("There are no preprocessors available on iOS, sorry. Command was: ", pp_args)                
                #        
                self.spawn(pp_args)
            except DistutilsExecError as msg:
                raise CompileError(msg)
Beispiel #18
0
    def run(self):
        try:
            import pytest
        except ImportError:
            raise DistutilsExecError('pytest is not installed')

        if self.skip_build:
            builddir = MODULEDIR
        else:
            # build extensions and byte-compile python
            build_ext = self.reinitialize_command('build_ext')
            build_py = self.reinitialize_command('build_py')
            build_ext.ensure_finalized()
            build_py.ensure_finalized()
            self.run_command('build_ext')
            self.run_command('build_py')
            builddir = os.path.abspath(build_py.build_lib)

        # force reimport of project from builddir
        sys.modules.pop(MODULE_NAME, None)

        with syspath(builddir):
            from snakeoil.contexts import chdir
            # Change the current working directory to the builddir during testing
            # so coverage paths are correct.
            with chdir(builddir):
                ret = pytest.main(self.test_args)
        sys.exit(ret)
Beispiel #19
0
    def compile_ts():
        lang_dir = pjoin('build', 'lang')
        if not os.path.isdir(lang_dir):
            os.makedirs(lang_dir)

        lres = find_executable('lrelease-qt4') or find_executable('lrelease')
        if not lres:
            raise DistutilsExecError('lrelease not found')

        trans = [
            os.path.basename(i).split('.')[0]
            for i in glob(pjoin('translation', '*.ts'))
        ]
        for i in trans:
            spawn([
                lres,
                pjoin('translation', i + '.ts'), '-qm',
                pjoin(lang_dir, i + '.qm')
            ])

        # copy corresponding Qt translations to build/lang
        if sys.platform != 'win32':
            # linux have complete qt library, so don't include; ignore warnings when compile_rc
            return
        pyside_dir = pjoin(get_python_lib(), 'PySide')
        for i in trans:
            target = pjoin(lang_dir, 'qt_%s.qm' % i)
            if not os.path.isfile(target):
                print('copy to ' + target)
                shutil.copy(pjoin(pyside_dir, 'translations', 'qt_%s.qm' % i),
                            target)
def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
    """Create a zip file from all the files under 'base_dir'.

    The output zip file will be named 'base_name' + ".zip".  Uses either the
    "zipfile" Python module (if available) or the InfoZIP "zip" utility
    (if installed and found on the default search path).  If neither tool is
    available, raises DistutilsExecError.  Returns the name of the output zip
    file.
    """
    zip_filename = base_name + ".zip"
    mkpath(os.path.dirname(zip_filename), dry_run=dry_run)

    # If zipfile module is not available, try spawning an external
    # 'zip' command.
    if zipfile is None:
        if verbose:
            zipoptions = "-r"
        else:
            zipoptions = "-rq"

        try:
            spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run)
        except DistutilsExecError:
            # XXX really should distinguish between "couldn't find
            # external 'zip' command" and "zip failed".
            raise DistutilsExecError(
                ("unable to create zip file '%s': "
                 "could neither import the 'zipfile' module nor "
                 "find a standalone zip utility") % zip_filename)

    else:
        log.info("creating '%s' and adding '%s' to it", zip_filename, base_dir)

        if not dry_run:
            try:
                zip = zipfile.ZipFile(zip_filename,
                                      "w",
                                      compression=zipfile.ZIP_DEFLATED)
            except RuntimeError:
                zip = zipfile.ZipFile(zip_filename,
                                      "w",
                                      compression=zipfile.ZIP_STORED)

            if base_dir != os.curdir:
                path = os.path.normpath(os.path.join(base_dir, ''))
                zip.write(path, path)
                log.info("adding '%s'", path)
            for dirpath, dirnames, filenames in os.walk(base_dir):
                for name in dirnames:
                    path = os.path.normpath(os.path.join(dirpath, name, ''))
                    zip.write(path, path)
                    log.info("adding '%s'", path)
                for name in filenames:
                    path = os.path.normpath(os.path.join(dirpath, name))
                    if os.path.isfile(path):
                        zip.write(path, path)
                        log.info("adding '%s'", path)
            zip.close()

    return zip_filename
Beispiel #21
0
    def create_static_lib(self, objects, output_libname,
                          output_dir=None, debug=0, target_lang=None):
        objects, output_dir = self._fix_object_args(objects, output_dir)

        output_filename = \
            self.library_filename(output_libname, output_dir=output_dir)

        if self._need_link(objects, output_filename):
            self.mkpath(os.path.dirname(output_filename))
            self.spawn(self.archiver +
                       [output_filename] +
                       objects + self.objects)

            # Not many Unices required ranlib anymore -- SunOS 4.x is, I
            # think the only major Unix that does.  Maybe we need some
            # platform intelligence here to skip ranlib if it's not
            # needed -- or maybe Python's configure script took care of
            # it for us, hence the check for leading colon.
            if self.ranlib:
                try:
                    # iOS: since clang is not available, we send a nicer error message:
                    if (sys.platform == 'darwin' and os.uname().machine.startswith('iP')):
                        raise DistutilsExecError("There are no static linkers available on iOS, sorry.")
                    #
                    self.spawn(self.ranlib + [output_filename])
                except DistutilsExecError as msg:
                    raise LibError(msg)
        else:
            log.debug("skipping %s (up-to-date)", output_filename)
Beispiel #22
0
 def run(self):
     """
     Run `lessc` for each file.
     """
     if not self.files:
         return
     # lessc --include-path=/home/ikus060/workspace/Minarca/rdiffweb.git/rdiffweb/static/less minarca_brand/main.less
     for f in self.files:
         args = ['lessc']
         if self.include_path:
             args.append('--include-path=' + self.include_path)
         if self.compress:
             args.append('--compress')
         # Source
         args.append(f)
         # Destination
         destination = f.replace('.less', '.css')
         if self.output_dir:
             destination = os.path.join(self.output_dir,
                                        os.path.basename(destination))
         args.append(destination)
         # Execute command line.
         try:
             subprocess.check_call(args)
         except:
             raise DistutilsExecError('fail to compile .less files into ' +
                                      f)
Beispiel #23
0
 def run(self):
     if not os.path.exists("epydoc.cfg"):
         return
     self.mkpath("doc/html")
     stat = os.system("epydoc --config epydoc.cfg %s/*.py" % (PACKAGE))
     if not stat == 0:
         raise DistutilsExecError("failed to run epydoc")
Beispiel #24
0
    def spawn(self, cmd, dry_run=False, cwd=None):
        cmd = list(cmd)

        log.info(' '.join(cmd))
        if dry_run:
            return

        try:
            exitcode = subprocess.call(cmd, cwd=cwd)
        except OSError as exc:
            raise DistutilsExecError("command %r failed: %s" %
                                     (cmd, exc.args[-1])) from exc

        if exitcode:
            raise DistutilsExecError("command %r failed with exit code %s" %
                                     (cmd, exitcode))
Beispiel #25
0
    def build_extension(self, ext):
        if not isinstance(ext, Executable):
            build_ext.build_extension(self, ext)
            return

        exe_fullpath = os.path.join(ext.output_dir, ext.target)
        cmd = ext.build_cmd
        log.debug("running '{}'".format(cmd))
        if not self.dry_run:
            env = self._compiler_env.copy()
            if ext.env:
                env.update(ext.env)
            p = subprocess.run(cmd, cwd=ext.cwd, env=env, shell=True)
            if p.returncode != 0:
                from distutils.errors import DistutilsExecError

                raise DistutilsExecError("running '{}' command failed".format(
                    ext.build_cmd))

        dest_path = self.get_ext_fullpath(ext.name)
        mkpath(os.path.dirname(dest_path),
               verbose=self.verbose,
               dry_run=self.dry_run)

        copy_file(exe_fullpath,
                  dest_path,
                  verbose=self.verbose,
                  dry_run=self.dry_run)
Beispiel #26
0
def _spawn_posix(cmd, search_path=1, verbose=0, dry_run=0):
    log.info(' '.join(cmd))
    if dry_run:
        return
    exec_fn = search_path and os.execvp or os.execv
    pid = os.fork()

    if pid == 0:  # in the child
        try:
            exec_fn(cmd[0], cmd)
        except OSError as e:
            sys.stderr.write("unable to execute %s: %s\n" %
                             (cmd[0], e.strerror))
            os._exit(1)

        sys.stderr.write("unable to execute %s for unknown reasons" % cmd[0])
        os._exit(1)
    else:  # in the parent
        # Loop until the child either exits or is terminated by a signal
        # (ie. keep waiting if it's merely stopped)
        while 1:
            try:
                pid, status = os.waitpid(pid, 0)
            except OSError as exc:
                import errno
                if exc.errno == errno.EINTR:
                    continue
                raise DistutilsExecError("command '%s' failed: %s" %
                                         (cmd[0], exc[-1]))
            if os.WIFSIGNALED(status):
                raise DistutilsExecError("command '%s' terminated by signal %d" % \
                      (cmd[0], os.WTERMSIG(status)))

            elif os.WIFEXITED(status):
                exit_status = os.WEXITSTATUS(status)
                if exit_status == 0:
                    return  # hey, it succeeded!
                else:
                    raise DistutilsExecError("command '%s' failed with exit status %d" % \
                          (cmd[0], exit_status))

            elif os.WIFSTOPPED(status):
                continue

            else:
                raise DistutilsExecError("unknown error executing '%s': termination status %d" % \
                      (cmd[0], status))
Beispiel #27
0
    def run(self):
        # make sure we're testing the latest
        self.run_command('build')

        # setup java classpath
        version = self.distribution.metadata.get_version()
        classpath = os.path.join(self.java_build, 'jep-' + version + '.jar')
        classpath += os.pathsep + os.path.join(self.java_build, 'jep-' + version + '-test.jar')
        classpath += os.pathsep + 'src/test/python/lib/sqlitejdbc-v056.jar'
        classpath += os.pathsep + 'src/test/python/lib/fakenetty.jar'

        # setup environment variables
        environment = {}
        if not is_osx() and not is_windows():
            environment['LD_LIBRARY_PATH'] = sysconfig.get_config_var('LIBDIR')
        # http://bugs.python.org/issue20614
        if is_windows():
            environment['SYSTEMROOT'] = os.environ['SYSTEMROOT']

        java_path = os.path.join(get_java_home(), 'bin')
        # if multiple versions of python are installed, this helps ensure the right
        # version is used
        executable = sys.executable
        if executable:
            py_path = os.path.dirname(executable)
            # java_path before python_path because py_path might point to a
            # default system path, like /usr/bin, which can contain other java
            # executables. Since all the subprocesses are Java running jep it
            # is very important to get the right java.
            environment['PATH'] = java_path + os.pathsep + py_path + os.pathsep + os.environ['PATH']
        else:
            environment['PATH'] = java_path + os.pathsep + os.environ['PATH']
        venv = hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix)
        if not venv:
            # PYTHONHOME helps locate libraries but should not be set in a virtual env
            prefix = sysconfig.get_config_var('prefix')
            exec_prefix = sysconfig.get_config_var('exec_prefix')
            if prefix == exec_prefix:
                environment['PYTHONHOME'] = prefix
            else:
                environment['PYTHONHOME'] = prefix + ':' + exec_prefix

        # find the jep library and makes sure it's named correctly
        build_ext = self.get_finalized_command('build_ext')
        jep_lib = build_ext.get_outputs()[0]
        built_dir = os.path.dirname(jep_lib)
        link_native_lib(built_dir, jep_lib)
        
        environment['PYTHONPATH'] = self.get_finalized_command('build').build_lib

        # actually kick off the tests
        import subprocess
        args = [os.path.join(java_path, 'java'),
                '-classpath', '{0}'.format(classpath),
                'jep.Run', 'src/test/python/runtests.py']
        p = subprocess.Popen(args, env=environment)
        rc = p.wait()
        if rc != 0:
            raise DistutilsExecError("Unit tests failed with exit status %d" % (rc))
Beispiel #28
0
def _spawn_java(cmd, search_path=1, verbose=0, dry_run=0):
    executable = cmd[0]
    cmd = ' '.join(_nt_quote_args(cmd))
    log.info(cmd)
    if not dry_run:
        try:
            rc = os.system(cmd) >> 8
        except OSError as exc:
            # this seems to happen when the command isn't found
            raise DistutilsExecError("command '%s' failed: %s" %
                                     (executable, exc[-1]))
        if rc != 0:
            # and this reflects the command running but failing
            print(
                ("command '%s' failed with exit status %d" % (executable, rc)))
            raise DistutilsExecError(
                "command '%s' failed with exit status %d" % (executable, rc))
Beispiel #29
0
    def run(self) -> None:
        warnings.warn('setup.py build_sphinx is deprecated.',
                      RemovedInSphinx70Warning,
                      stacklevel=2)

        if not color_terminal():
            nocolor()
        if not self.verbose:  # type: ignore
            status_stream = StringIO()
        else:
            status_stream = sys.stdout  # type: ignore
        confoverrides: Dict[str, Any] = {}
        if self.project:
            confoverrides['project'] = self.project
        if self.version:
            confoverrides['version'] = self.version
        if self.release:
            confoverrides['release'] = self.release
        if self.today:
            confoverrides['today'] = self.today
        if self.copyright:
            confoverrides['copyright'] = self.copyright
        if self.nitpicky:
            confoverrides['nitpicky'] = self.nitpicky

        for builder, builder_target_dir in self.builder_target_dirs:
            app = None

            try:
                confdir = self.config_dir or self.source_dir
                with patch_docutils(confdir), docutils_namespace():
                    app = Sphinx(self.source_dir,
                                 self.config_dir,
                                 builder_target_dir,
                                 self.doctree_dir,
                                 builder,
                                 confoverrides,
                                 status_stream,
                                 freshenv=self.fresh_env,
                                 warningiserror=self.warning_is_error,
                                 verbosity=self.verbosity,
                                 keep_going=self.keep_going)
                    app.build(force_all=self.all_files)
                    if app.statuscode:
                        raise DistutilsExecError('caused by %s builder.' %
                                                 app.builder.name)
            except Exception as exc:
                handle_exception(app, self, exc, sys.stderr)
                if not self.pdb:
                    raise SystemExit(1) from exc

            if not self.link_index:
                continue

            src = app.config.root_doc + app.builder.out_suffix  # type: ignore
            dst = app.builder.get_outfilename('index')  # type: ignore
            os.symlink(src, dst)
Beispiel #30
0
 def run(self):
     cmd = ['invoke', 'css']
     if self.minify:
         cmd.append('--minify')
     if self.force:
         cmd.append('--force')
     try:
         p = Popen(cmd,
                   cwd=pjoin(repo_root, "jupyter_notebook"),
                   stderr=PIPE)
     except OSError:
         raise DistutilsExecError(
             "invoke is required to rebuild css (pip install invoke)")
     out, err = p.communicate()
     if p.returncode:
         if sys.version_info[0] >= 3:
             err = err.decode('utf8', 'replace')
         raise DistutilsExecError(err.strip())