Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
here = Path(__file__).parent


def fake_loader(kind, path, config, parameters, loaded_tasks):
def fake_loader(kind, path, config, parameters, loaded_tasks, write_artifacts):
for i in range(3):
dependencies = {}
if i >= 1:
Expand Down
6 changes: 6 additions & 0 deletions src/taskgraph/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import copy
import inspect
import logging
import multiprocessing
import os
Expand Down Expand Up @@ -60,12 +61,17 @@ def load_tasks(self, parameters, kind_dependencies_tasks, write_artifacts):
loader = self._get_loader()
config = copy.deepcopy(self.config)

if "write_artifacts" in inspect.signature(loader).parameters:
extra_args = (write_artifacts,)
else:
extra_args = ()
inputs = loader(
self.name,
self.path,
config,
parameters,
list(kind_dependencies_tasks.values()),
*extra_args,
)

transforms = TransformSequence()
Expand Down
4 changes: 2 additions & 2 deletions src/taskgraph/loader/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
]


def loader(kind, path, config, params, loaded_tasks):
def loader(kind, path, config, params, loaded_tasks, write_artifacts):
"""
This default loader builds on the `transform` loader by providing sensible
default transforms that the majority of simple tasks will need.
Expand All @@ -30,4 +30,4 @@ def loader(kind, path, config, params, loaded_tasks):
f"Transform {t} is already present in the loader's default transforms; it must not be defined in the kind"
)
transform_refs.extend(DEFAULT_TRANSFORMS)
return transform_loader(kind, path, config, params, loaded_tasks)
return transform_loader(kind, path, config, params, loaded_tasks, write_artifacts)
2 changes: 1 addition & 1 deletion src/taskgraph/loader/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger = logging.getLogger(__name__)


def loader(kind, path, config, params, loaded_tasks):
def loader(kind, path, config, params, loaded_tasks, write_artifacts):
"""
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
Expand Down
16 changes: 14 additions & 2 deletions test/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ def test_load_tasks_for_kind(monkeypatch):
)


def test_loader_backwards_compat_interface(graph_config):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this test :)

"""Ensure loaders can be called even if they don't support a
`write_artifacts` argument."""

class OldLoaderKind(Kind):
def _get_loader(self):
return lambda kind, path, config, params, tasks: []

kind = OldLoaderKind("", "", {"transforms": []}, graph_config)
kind.load_tasks({}, {}, False)


@pytest.mark.parametrize(
"config,expected_transforms",
(
Expand Down Expand Up @@ -243,7 +255,7 @@ def test_default_loader(config, expected_transforms):
assert loader is default_loader, (
"Default Kind loader should be taskgraph.loader.default.loader"
)
loader("", "", config, {}, [])
loader("", "", config, {}, [], False)

assert config["transforms"] == expected_transforms

Expand Down Expand Up @@ -273,7 +285,7 @@ def test_default_loader(config, expected_transforms):
def test_default_loader_errors(config):
loader = Kind("", "", config, {})._get_loader()
try:
loader("", "", config, {}, [])
loader("", "", config, {}, [], False)
except KeyError:
return

Expand Down
Loading