示例#1
0
文件: graph.py 项目: lparkes/cylc
def get_config(workflow: str, opts: 'Values') -> WorkflowConfig:
    """Return a WorkflowConfig object for the provided reg / path."""
    workflow, flow_file = parse_reg(workflow, src=True)
    template_vars = get_template_vars(opts)
    return WorkflowConfig(workflow,
                          flow_file,
                          opts,
                          template_vars=template_vars)
示例#2
0
def get_config(workflow_id: str, opts: 'Values') -> WorkflowConfig:
    """Return a WorkflowConfig object for the provided reg / path."""
    workflow_id, _, flow_file = parse_id(
        workflow_id,
        src=True,
        constraint='workflows',
    )
    template_vars = get_template_vars(opts)
    return WorkflowConfig(workflow_id,
                          flow_file,
                          opts,
                          template_vars=template_vars)
示例#3
0
def test_get_template_vars_src_flow_fails(monkeypatch, provide_opts,
                                          monkeypatch_load_template_vars):
    """It fails if there is a plugin error.
    """
    def fake_iter_entry_points(_):
        class fake_ep:
            name = 'Zaphod'

            def resolve():
                def _inner(srcdir, opts):
                    raise TypeError('Utter Drivel.')

                return _inner

        return [fake_ep]

    monkeypatch.setattr('cylc.flow.templatevars.iter_entry_points',
                        fake_iter_entry_points)

    with pytest.raises(PluginError) as exc:
        get_template_vars(provide_opts, '')
    assert exc.match(
        'Error in plugin cylc.pre_configure.Zaphod\nUtter Drivel.')
示例#4
0
def main(
    parser: COP,
    options: 'Values',
    *ids,
) -> None:

    if options.print_platform_names and options.print_platforms:
        options.print_platform_names = False

    if options.print_platform_names or options.print_platforms:
        # Get platform information:
        if ids:
            raise UserInputError(
                "Workflow IDs are incompatible with --platform options.")
        glbl_cfg().platform_dump(options.print_platform_names,
                                 options.print_platforms)
        return

    if not ids:
        if options.print_hierarchy:
            print("\n".join(get_config_file_hierarchy()))
            return

        glbl_cfg().idump(options.item,
                         not options.defaults,
                         oneline=options.oneline,
                         none_str=options.none_str)
        return

    workflow_id, _, flow_file = parse_id(
        *ids,
        src=True,
        constraint='workflows',
    )

    if options.print_hierarchy:
        print("\n".join(get_config_file_hierarchy(workflow_id)))
        return

    config = WorkflowConfig(workflow_id, flow_file, options,
                            get_template_vars(options))

    config.pcfg.idump(options.item,
                      not options.defaults,
                      oneline=options.oneline,
                      none_str=options.none_str)
示例#5
0
文件: config.py 项目: kinow/cylc-flow
def main(parser: COP, options: 'Values', reg: Optional[str] = None) -> None:
    if options.print_hierarchy:
        print("\n".join(get_config_file_hierarchy(reg)))
        return

    if reg is None:
        glbl_cfg().idump(options.item,
                         not options.defaults,
                         oneline=options.oneline,
                         none_str=options.none_str)
        return

    workflow, flow_file = parse_reg(reg, src=True)

    config = WorkflowConfig(workflow, flow_file, options,
                            get_template_vars(options, flow_file))

    config.pcfg.idump(options.item,
                      not options.defaults,
                      oneline=options.oneline,
                      none_str=options.none_str)
示例#6
0
def test_get_template_vars_src_flow(monkeypatch, provide_opts,
                                    monkeypatch_load_template_vars):
    """It works on a flow which hasn't been installed.
    """
    def fake_iter_entry_points(_):
        class fake_ep:
            name = 'Zaphod'

            def resolve():
                def _inner(srcdir, opts):
                    return {
                        'template_variables': {
                            'MYVAR': 'foo'
                        },
                        'templating_detected': 'lazyman'
                    }

                return _inner

        return [fake_ep]

    monkeypatch.setattr('cylc.flow.templatevars.iter_entry_points',
                        fake_iter_entry_points)
    assert get_template_vars(provide_opts, '') == {'MYVAR': 'foo'}
示例#7
0
def main(parser: COP, options: 'Values', reg: str) -> None:
    """cylc validate CLI."""
    profiler = Profiler(None, options.profile_mode)
    profiler.start()

    if cylc.flow.flags.verbosity < 2:
        # for readability omit timestamps from logging unless in debug mode
        for handler in LOG.handlers:
            if isinstance(handler.formatter, CylcLogFormatter):
                handler.formatter.configure(timestamp=False)

    workflow, flow_file = parse_reg(reg, src=True)
    cfg = WorkflowConfig(workflow,
                         flow_file,
                         options,
                         get_template_vars(options, flow_file),
                         output_fname=options.output,
                         mem_log_func=profiler.log_memory)

    # Check bounds of sequences
    out_of_bounds = [
        str(seq) for seq in cfg.sequences
        if seq.get_first_point(cfg.start_point) is None
    ]
    if out_of_bounds:
        if len(out_of_bounds) > 1:
            # avoid spamming users with multiple warnings
            out_of_bounds_str = '\n'.join(
                textwrap.wrap(', '.join(out_of_bounds), 70))
            msg = ("multiple sequences out of bounds for initial cycle point "
                   f"{cfg.start_point}:\n{out_of_bounds_str}")
        else:
            msg = (f"{out_of_bounds[0]}: sequence out of bounds for "
                   f"initial cycle point {cfg.start_point}")
        LOG.warning(msg)

    # Instantiate tasks and force evaluation of trigger expressions.
    # (Taken from config.py to avoid circular import problems.)
    # TODO - This is not exhaustive, it only uses the initial cycle point.
    if cylc.flow.flags.verbosity > 0:
        print('Instantiating tasks to check trigger expressions')
    flow_label = FlowLabelMgr().get_new_label()
    for name, taskdef in cfg.taskdefs.items():
        try:
            itask = TaskProxy(taskdef, cfg.start_point, flow_label)
        except TaskProxySequenceBoundsError:
            # Should already failed above
            mesg = 'Task out of bounds for %s: %s\n' % (cfg.start_point, name)
            if cylc.flow.flags.verbosity > 0:
                sys.stderr.write(' + %s\n' % mesg)
            continue
        except Exception as exc:
            raise WorkflowConfigError('failed to instantiate task %s: %s' %
                                      (name, exc))

        # force trigger evaluation now
        try:
            itask.state.prerequisites_eval_all()
        except TriggerExpressionError as exc:
            err = str(exc)
            if '@' in err:
                print(
                    f"ERROR, {name}: xtriggers can't be in conditional"
                    f" expressions: {err}",
                    file=sys.stderr)
            else:
                print('ERROR, %s: bad trigger: %s' % (name, err),
                      file=sys.stderr)
            raise WorkflowConfigError("ERROR: bad trigger")
        except Exception as exc:
            print(str(exc), file=sys.stderr)
            raise WorkflowConfigError('%s: failed to evaluate triggers.' %
                                      name)
        if cylc.flow.flags.verbosity > 0:
            print('  + %s ok' % itask.identity)

    print(cparse('<green>Valid for cylc-%s</green>' % CYLC_VERSION))
    profiler.stop()
示例#8
0
文件: list.py 项目: lparkes/cylc
def main(parser: COP, options: 'Values', reg: str) -> None:
    workflow, flow_file = parse_reg(reg, src=True)
    template_vars = get_template_vars(options)

    if options.all_tasks and options.all_namespaces:
        parser.error("Choose either -a or -n")
    if options.all_tasks:
        which = "all tasks"
    elif options.all_namespaces:
        which = "all namespaces"
    elif options.prange:
        which = "prange"
        if options.prange == ",":
            tr_start = None
            tr_stop = None
        elif options.prange.endswith(","):
            tr_start = options.prange[:-1]
            tr_stop = None
        elif options.prange.startswith(","):
            tr_start = None
            tr_stop = options.prange[1:]
        else:
            tr_start, tr_stop = options.prange.split(',')
    else:
        which = "graphed tasks"

    if options.tree and os.environ['LANG'] == 'C' and options.box:
        print("WARNING, ignoring -t/--tree: $LANG=C", file=sys.stderr)
        options.tree = False

    if options.titles and options.mro:
        parser.error("Please choose --mro or --title, not both")

    if options.tree and any(
            [options.all_tasks, options.all_namespaces, options.mro]):
        print("WARNING: -t chosen, ignoring non-tree options.",
              file=sys.stderr)
    config = WorkflowConfig(
        workflow,
        flow_file,
        options,
        template_vars
    )
    if options.tree:
        config.print_first_parent_tree(
            pretty=options.box, titles=options.titles)
    elif options.prange:
        for node in sorted(config.get_node_labels(tr_start, tr_stop)):
            print(node)
    else:
        result = config.get_namespace_list(which)
        namespaces = list(result)
        namespaces.sort()

        if (options.mro or options.titles):
            # compute padding
            maxlen = 0
            for ns in namespaces:
                if len(ns) > maxlen:
                    maxlen = len(ns)
            padding = maxlen * ' '

        for ns in namespaces:
            if options.mro:
                print(ns, padding[0:len(padding) - len(ns)], end=' ')
                print(' '.join(config.get_mro(ns)))
            elif options.titles:
                print(ns, padding[0:len(padding) - len(ns)], end=' ')
                print(result[ns])
            else:
                print(ns)
示例#9
0
def main(parser: COP, options: 'Values', workflow_id: str) -> None:
    """cylc validate CLI."""
    profiler = Profiler(None, options.profile_mode)
    profiler.start()

    if cylc.flow.flags.verbosity < 2:
        disable_timestamps(LOG)

    workflow_id, _, flow_file = parse_id(
        workflow_id,
        src=True,
        constraint='workflows',
    )
    cfg = WorkflowConfig(workflow_id,
                         flow_file,
                         options,
                         get_template_vars(options),
                         output_fname=options.output,
                         mem_log_func=profiler.log_memory)

    # Instantiate tasks and force evaluation of trigger expressions.
    # (Taken from config.py to avoid circular import problems.)
    # TODO - This is not exhaustive, it only uses the initial cycle point.
    if cylc.flow.flags.verbosity > 0:
        print('Instantiating tasks to check trigger expressions')
    for name, taskdef in cfg.taskdefs.items():
        try:
            itask = TaskProxy(taskdef, cfg.start_point)
        except TaskProxySequenceBoundsError:
            # Should already failed above
            mesg = 'Task out of bounds for %s: %s\n' % (cfg.start_point, name)
            if cylc.flow.flags.verbosity > 0:
                sys.stderr.write(' + %s\n' % mesg)
            continue
        except Exception as exc:
            raise WorkflowConfigError('failed to instantiate task %s: %s' %
                                      (name, exc))

        # force trigger evaluation now
        try:
            itask.state.prerequisites_eval_all()
        except TriggerExpressionError as exc:
            err = str(exc)
            if '@' in err:
                print(
                    f"ERROR, {name}: xtriggers can't be in conditional"
                    f" expressions: {err}",
                    file=sys.stderr)
            else:
                print('ERROR, %s: bad trigger: %s' % (name, err),
                      file=sys.stderr)
            raise WorkflowConfigError("ERROR: bad trigger")
        except Exception as exc:
            print(str(exc), file=sys.stderr)
            raise WorkflowConfigError('%s: failed to evaluate triggers.' %
                                      name)
        if cylc.flow.flags.verbosity > 0:
            print('  + %s ok' % itask.identity)

    print(cparse('<green>Valid for cylc-%s</green>' % CYLC_VERSION))
    profiler.stop()