Skip to content
Snippets Groups Projects
Commit d65569d7 authored by Andrew Halberstadt's avatar Andrew Halberstadt
Browse files

Bug 1901281 - Replace 'gecko_taskgraph.util.templates' with 'taskgraph.util.templates', a=RyanVM

parent 35c82e5c
No related branches found
No related tags found
No related merge requests found
......@@ -58,7 +58,7 @@ Each variant must conform to the
to be applied. The ``task`` definition is passed in as context.
* **replace** - A dictionary that will overwrite keys in the task definition.
* **merge** - A dictionary that will be merged into the task definition using
the :py:func:`~gecko_taskgraph.util.templates.merge` function.
the :py:func:`~taskgraph.util.templates.merge` function.
.. note::
......
......@@ -5,10 +5,9 @@
import logging
from taskgraph.util.templates import merge
from taskgraph.util.yaml import load_yaml
from ..util.templates import merge
logger = logging.getLogger(__name__)
......
......@@ -13,10 +13,10 @@ from taskgraph.generator import Kind, TaskGraphGenerator
from taskgraph.optimize import base as optimize_mod
from taskgraph.optimize.base import OptimizationStrategy
from taskgraph.parameters import Parameters
from taskgraph.util.templates import merge
from gecko_taskgraph import GECKO
from gecko_taskgraph.actions import render_actions_json
from gecko_taskgraph.util.templates import merge
@pytest.fixture
......
......@@ -6,8 +6,7 @@
import unittest
import mozunit
from gecko_taskgraph.util.templates import merge, merge_to
from taskgraph.util.templates import merge, merge_to
class MergeTest(unittest.TestCase):
......
......@@ -18,12 +18,12 @@ from taskgraph.util.taskcluster import (
get_artifact_url,
get_index_url,
)
from taskgraph.util.templates import merge
from voluptuous import Any, Optional, Required
from gecko_taskgraph.transforms.test.variant import TEST_VARIANTS
from gecko_taskgraph.util.perftest import is_external_browser
from gecko_taskgraph.util.platforms import platform_family
from gecko_taskgraph.util.templates import merge
transforms = TransformSequence()
......
......@@ -7,11 +7,11 @@ import jsone
from taskgraph.transforms.base import TransformSequence
from taskgraph.util.copy import deepcopy
from taskgraph.util.schema import Schema, validate_schema
from taskgraph.util.templates import merge
from taskgraph.util.treeherder import join_symbol, split_symbol
from voluptuous import Any, Optional, Required
from gecko_taskgraph.util.chunking import TEST_VARIANTS
from gecko_taskgraph.util.templates import merge
transforms = TransformSequence()
......
# 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/.
from taskgraph.util.copy import deepcopy
def merge_to(source, dest):
"""
Merge dict and arrays (override scalar values)
Keys from source override keys from dest, and elements from lists in source
are appended to lists in dest.
:param dict source: to copy from
:param dict dest: to copy to (modified in place)
"""
for key, value in source.items():
if (
isinstance(value, dict)
and len(value) == 1
and list(value)[0].startswith("by-")
):
# Do not merge by-* values as this is likely to confuse someone
dest[key] = value
continue
# Override mismatching or empty types
if type(value) != type(dest.get(key)): # noqa
dest[key] = value
continue
# Merge dict
if isinstance(value, dict):
merge_to(value, dest[key])
continue
if isinstance(value, list):
dest[key] = dest[key] + value
continue
dest[key] = value
return dest
def merge(*objects):
"""
Merge the given objects, using the semantics described for merge_to, with
objects later in the list taking precedence. From an inheritance
perspective, "parents" should be listed before "children".
Returns the result without modifying any arguments.
"""
if len(objects) == 1:
return deepcopy(objects[0])
return merge_to(objects[-1], merge(*objects[:-1]))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment