File: transform.py

package info (click to toggle)
thunderbird 1%3A127.0~b5-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 4,421,808 kB
  • sloc: cpp: 7,379,480; javascript: 5,568,142; ansic: 3,852,317; python: 1,221,238; xml: 620,984; asm: 456,308; java: 179,035; sh: 118,742; makefile: 21,918; perl: 14,823; objc: 12,399; yacc: 4,583; pascal: 2,973; lex: 1,720; ruby: 1,190; exp: 762; sql: 666; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (58 lines) | stat: -rw-r--r-- 2,147 bytes parent folder | download | duplicates (22)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


import logging

from taskgraph.util.templates import merge
from taskgraph.util.yaml import load_yaml

logger = logging.getLogger(__name__)


def loader(kind, path, config, params, loaded_tasks):
    """
    Get the input elements that will be transformed into tasks in a generic
    way.  The elements themselves are free-form, and become the input to the
    first transform.

    By default, this reads tasks from the `tasks` key, or from yaml files
    named by `tasks-from`. The entities are read from mappings, and the
    keys to those mappings are added in the `name` key of each entity.

    If there is a `task-defaults` config, then every task is merged with it.
    This provides a simple way to set default values for all tasks of a kind.
    The `task-defaults` key can also be specified in a yaml file pointed to by
    `tasks-from`. In this case it will only apply to tasks defined in the same
    file.

    Other kind implementations can use a different loader function to
    produce inputs and hand them to `transform_inputs`.
    """

    def generate_tasks():
        defaults = config.get("task-defaults")
        for name, task in config.get("tasks", {}).items():
            if defaults:
                task = merge(defaults, task)
            task["task-from"] = "kind.yml"
            yield name, task

        for filename in config.get("tasks-from", []):
            tasks = load_yaml(path, filename)

            file_defaults = tasks.pop("task-defaults", None)
            if defaults:
                file_defaults = merge(defaults, file_defaults or {})

            for name, task in tasks.items():
                if file_defaults:
                    task = merge(file_defaults, task)
                task["task-from"] = filename
                yield name, task

    for name, task in generate_tasks():
        task["name"] = name
        logger.debug(f"Generating tasks for {kind} {name}")
        yield task