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:
Andrew Halberstadt 2024-06-12 19:26:43 +00:00
parent 296700d1af
commit 55ae9658b3
7 changed files with 6 additions and 67 deletions

View File

@ -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::

View File

@ -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__)

View File

@ -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

View File

@ -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):

View File

@ -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()

View File

@ -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()

View File

@ -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]))