Ejemplo n.º 1
0
def run(client, no_output, command_line):
    """Tracking work on a specific problem."""
    working_dir = client.git.working_dir
    candidates = [
        os.path.join(working_dir, path)
        for path in [x[0] for x in client.git.index.entries] +
        client.git.untracked_files
    ]
    mapped_std = _mapped_std_streams(candidates)
    factory = CommandLineToolFactory(command_line=command_line,
                                     directory=working_dir,
                                     **{
                                         name:
                                         os.path.relpath(path, working_dir)
                                         for name, path in mapped_std.items()
                                     })

    with client.with_workflow_storage() as wf:
        with factory.watch(client, no_output=no_output) as tool:
            call(
                factory.command_line,
                cwd=os.getcwd(),
                **{key: getattr(sys, key)
                   for key in mapped_std.keys()},
            )

            sys.stdout.flush()
            sys.stderr.flush()

            wf.add_step(run=tool)
Ejemplo n.º 2
0
def run(client, no_output, success_codes, command_line):
    """Tracking work on a specific problem."""
    working_dir = client.git.working_dir
    paths = [x[0] for x in client.git.index.entries]
    paths += client.git.untracked_files
    candidates = [os.path.join(working_dir, path) for path in paths]
    mapped_std = _mapped_std_streams(candidates)
    factory = CommandLineToolFactory(command_line=command_line,
                                     directory=os.getcwd(),
                                     working_dir=working_dir,
                                     successCodes=success_codes,
                                     **{
                                         name:
                                         os.path.relpath(path, working_dir)
                                         for name, path in mapped_std.items()
                                     })

    with client.with_workflow_storage() as wf:
        with factory.watch(client, no_output=no_output) as tool:
            returncode = call(
                factory.command_line,
                cwd=os.getcwd(),
                **{key: getattr(sys, key)
                   for key in mapped_std.keys()},
            )

            if returncode not in (success_codes or {0}):
                raise errors.InvalidSuccessCode(returncode,
                                                success_codes=success_codes)

            sys.stdout.flush()
            sys.stderr.flush()

            wf.add_step(run=tool)
Ejemplo n.º 3
0
def test_exitings_output_directory(client):
    """Test creation of InitialWorkDirRequirement for output directory."""
    instance_path = client.path
    output = client.path / 'output'

    argv = ['script', 'output']
    factory = CommandLineToolFactory(
        argv,
        directory=instance_path,
        working_dir=instance_path,
    )

    with factory.watch(repo=client, no_output=True) as tool:
        # Script creates the directory.
        output.mkdir(parents=True)

    initial_work_dir_requirement = [
        r for r in tool.requirements
        if r.__class__.__name__ == 'InitialWorkDirRequirement'
    ]
    assert 0 == len(initial_work_dir_requirement)

    output.mkdir(parents=True, exist_ok=True)
    with factory.watch(repo=client) as tool:
        # The directory already exists.
        (output / 'result.txt').touch()

    initial_work_dir_requirement = [
        r for r in tool.requirements
        if r.__class__.__name__ == 'InitialWorkDirRequirement'
    ]
    assert 1 == len(initial_work_dir_requirement)
    assert initial_work_dir_requirement[0].listing[0].entryname == output.name

    assert 1 == len(tool.inputs)
    assert 1 == len(tool.outputs)
Ejemplo n.º 4
0
def run(client, outputs, no_output, success_codes, isolation, command_line):
    """Tracking work on a specific problem."""
    working_dir = client.repo.working_dir
    mapped_std = _mapped_std_streams(client.candidate_paths)
    factory = CommandLineToolFactory(
        command_line=command_line,
        directory=os.getcwd(),
        working_dir=working_dir,
        successCodes=success_codes,
        **{
            name: os.path.relpath(path, working_dir)
            for name, path in mapped_std.items()
        }
    )

    with client.with_workflow_storage() as wf:
        with factory.watch(
            client, no_output=no_output, outputs=outputs
        ) as tool:
            # Don't compute paths if storage is disabled.
            if client.has_external_storage:
                # Make sure all inputs are pulled from a storage.
                paths_ = (
                    path
                    for _, path in tool.iter_input_files(client.workflow_path)
                )
                client.pull_paths_from_storage(*paths_)

            returncode = call(
                factory.command_line,
                cwd=os.getcwd(),
                **{key: getattr(sys, key)
                   for key in mapped_std.keys()},
            )

            if returncode not in (success_codes or {0}):
                raise errors.InvalidSuccessCode(
                    returncode, success_codes=success_codes
                )

            sys.stdout.flush()
            sys.stderr.flush()

            wf.add_step(run=tool)
Ejemplo n.º 5
0
def run(client, no_output, command_line):
    """Tracking work on a specific problem."""
    candidates = [x[0] for x in client.git.index.entries] + \
        client.git.untracked_files
    mapped_std = _mapped_std_streams(candidates)
    factory = CommandLineToolFactory(command_line=command_line, **mapped_std)

    with client.with_workflow_storage() as wf:
        with factory.watch(client, no_output=no_output) as tool:
            call(
                factory.command_line,
                cwd=os.getcwd(),
                **{key: getattr(sys, key)
                   for key in mapped_std.keys()},
            )

            sys.stdout.flush()
            sys.stderr.flush()

            wf.add_step(run=tool)