mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-26 12:20:56 +00:00
Bug 1901281 - Replace 'gecko_taskgraph.util.templates' with 'taskgraph.util.templates', r=taskgraph-reviewers,bhearsum
Differential Revision: https://phabricator.services.mozilla.com/D213428
This commit is contained in:
parent
296700d1af
commit
55ae9658b3
@ -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()
|
||||
|
||||
|
@ -1,59 +0,0 @@
|
||||
# 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]))
|
Loading…
x
Reference in New Issue
Block a user