Ejemplo n.º 1
0
 def setactivity(self, name, msg):
     self.activity = name
     if msg:
         reporter.verbosity0("{} {}: {}".format(self.name, name, msg),
                             bold=True)
     else:
         reporter.verbosity1("{} {}: {}".format(self.name, name, msg),
                             bold=True)
Ejemplo n.º 2
0
def show_config(config):
    parser = configparser.ConfigParser()

    if not config.envlist_explicit or reporter.verbosity() >= reporter.Verbosity.INFO:
        tox_info(config, parser)
        version_info(parser)
    tox_envs_info(config, parser)

    content = StringIO()
    parser.write(content)
    value = content.getvalue().rstrip()
    reporter.verbosity0(value)
Ejemplo n.º 3
0
def tox_get_python_executable(envconfig):  # noqa: D103
    envname = envconfig.envname
    interpreter = envconfig.interpreter
    if interpreter:
        reporter.verbosity0(
            '{} base interpreter: {}'.format(envname, interpreter), bold=True,
        )
    else:
        reporter.verbosity0(
            '{} base interpreter: delegating to standard resolution'.format(
                envname,
            ),
            bold=True,
        )
    return interpreter
Ejemplo n.º 4
0
        def run_in_thread(tox_env, os_env, processes):
            output = None
            print_out = None
            env_name = tox_env.envconfig.envname
            status = "skipped tests" if config.option.notest else None
            try:
                os_env[str(PARALLEL_ENV_VAR_KEY_PRIVATE)] = str(env_name)
                os_env[str(PARALLEL_ENV_VAR_KEY_PUBLIC)] = str(env_name)
                args_sub = list(args)
                if hasattr(tox_env, "package"):
                    args_sub.insert(position, str(tox_env.package))
                    args_sub.insert(position, "--installpkg")
                if tox_env.get_result_json_path():
                    result_json_index = args_sub.index("--result-json")
                    args_sub[result_json_index + 1] = "{}".format(
                        tox_env.get_result_json_path())
                with tox_env.new_action("parallel {}".format(
                        tox_env.name)) as action:

                    def collect_process(process):
                        processes[tox_env] = (action, process)

                    print_out = not live_out and tox_env.envconfig.parallel_show_output
                    output = action.popen(
                        args=args_sub,
                        env=os_env,
                        redirect=not live_out,
                        capture_err=print_out,
                        callback=collect_process,
                        returnout=print_out,
                    )

            except InvocationError as err:
                status = "parallel child exit code {}".format(err.exit_code)
            finally:
                semaphore.release()
                finished.set()
                tox_env.status = status
                done.add(env_name)
                outcome = spinner.succeed
                if config.option.notest:
                    outcome = spinner.skip
                elif status is not None:
                    outcome = spinner.fail
                outcome(env_name)
                if print_out and output is not None:
                    reporter.verbosity0(output)
def tox_testenv_create(venv: "VirtualEnv",
                       action: "Action") -> None:  # noqa: D103
    envconfig: "TestenvConfig" = venv.envconfig

    if not envconfig.recreate:
        return

    recreate_hook = envconfig._reader.getstring("recreate_hook", '')

    if not recreate_hook.strip():
        return None

    config: "Config" = envconfig.config
    toxinidir = config.toxinidir

    # The whole process should take place within the toxinidir
    with in_directory(toxinidir):
        print(f"output = {recreate_hook}")
        print(config._cfg.path)
        code: CodeType = compile(f"output = {recreate_hook}",
                                 config._cfg.path,
                                 mode="single")

        hook_globals = {"builtin": tox_recreate_hook.hooks}

        # The first value in co_names will be the name of the module to import, if any
        if code.co_names:
            module_name = first(code.co_names, key=lambda x: x != "output")

            if module_name and module_name != "builtin":
                with append_to_sys_path(toxinidir):
                    hook_globals[module_name] = import_module(module_name)

        # Call the hook
        exec(code, hook_globals)  # pylint: disable=exec-used

        # Retrieve the output message from the hook and print it
        output = hook_globals.get("output", None)

        if output is not None:
            reporter.verbosity0(f"{envconfig.envname} recreate hook: {output}",
                                bold=True)
Ejemplo n.º 6
0
def run_parallel(config, venv_dict):
    """here we'll just start parallel sub-processes"""
    live_out = config.option.parallel_live
    disable_spinner = bool(os.environ.get("TOX_PARALLEL_NO_SPINNER") == "1")
    args = [sys.executable, MAIN_FILE] + config.args
    try:
        position = args.index("--")
    except ValueError:
        position = len(args)

    max_parallel = config.option.parallel
    if max_parallel is None:
        max_parallel = len(venv_dict)
    semaphore = Semaphore(max_parallel)
    finished = Event()

    show_progress = (not disable_spinner and not live_out
                     and reporter.verbosity() > reporter.Verbosity.QUIET)

    with Spinner(enabled=show_progress) as spinner:

        def run_in_thread(tox_env, os_env, processes):
            output = None
            print_out = None
            env_name = tox_env.envconfig.envname
            status = "skipped tests" if config.option.notest else None
            try:
                os_env[str(PARALLEL_ENV_VAR_KEY_PRIVATE)] = str(env_name)
                os_env[str(PARALLEL_ENV_VAR_KEY_PUBLIC)] = str(env_name)
                args_sub = list(args)
                if hasattr(tox_env, "package"):
                    args_sub.insert(position, str(tox_env.package))
                    args_sub.insert(position, "--installpkg")
                if tox_env.get_result_json_path():
                    result_json_index = args_sub.index("--result-json")
                    args_sub[result_json_index + 1] = "{}".format(
                        tox_env.get_result_json_path())
                with tox_env.new_action("parallel {}".format(
                        tox_env.name)) as action:

                    def collect_process(process):
                        processes[tox_env] = (action, process)

                    print_out = not live_out and tox_env.envconfig.parallel_show_output
                    output = action.popen(
                        args=args_sub,
                        env=os_env,
                        redirect=not live_out,
                        capture_err=print_out,
                        callback=collect_process,
                        returnout=print_out,
                    )

            except InvocationError as err:
                status = "parallel child exit code {}".format(err.exit_code)
            finally:
                semaphore.release()
                finished.set()
                tox_env.status = status
                done.add(env_name)
                outcome = spinner.succeed
                if config.option.notest:
                    outcome = spinner.skip
                elif status is not None:
                    outcome = spinner.fail
                outcome(env_name)
                if print_out and output is not None:
                    reporter.verbosity0(output)

        threads = deque()
        processes = {}
        todo_keys = set(venv_dict.keys())
        todo = OrderedDict((n, todo_keys & set(v.envconfig.depends))
                           for n, v in venv_dict.items())
        done = set()
        try:
            while todo:
                for name, depends in list(todo.items()):
                    if depends - done:
                        # skip if has unfinished dependencies
                        continue
                    del todo[name]
                    venv = venv_dict[name]
                    semaphore.acquire(blocking=True)
                    spinner.add(name)
                    thread = Thread(
                        target=run_in_thread,
                        args=(venv, os.environ.copy(), processes),
                    )
                    thread.daemon = True
                    thread.start()
                    threads.append(thread)
                if todo:
                    # wait until someone finishes and retry queuing jobs
                    finished.wait()
                    finished.clear()
            while threads:
                threads = [
                    thread for thread in threads
                    if not thread.join(0.1) and thread.is_alive()
                ]
        except KeyboardInterrupt:
            reporter.verbosity0(
                "[{}] KeyboardInterrupt parallel - stopping children".format(
                    os.getpid()), )
            while True:
                # do not allow to interrupt until children interrupt
                try:
                    # putting it inside a thread so it's not interrupted
                    stopper = Thread(target=_stop_child_processes,
                                     args=(processes, threads))
                    stopper.start()
                    stopper.join()
                except KeyboardInterrupt:
                    continue
                raise KeyboardInterrupt
Ejemplo n.º 7
0
def tox_runtest_post(venv):
    verbosity0("cinderella is {}".format(venv.envconfig.cinderella))
Ejemplo n.º 8
0
def tox_configure(config):
    """Access your option during configuration"""
    verbosity0("flag magic is: {}".format(config.option.magic))