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 @@ -166,7 +166,8 @@ def parameters():

@pytest.fixture
def maketgg(monkeypatch, parameters):
def inner(target_tasks=None, kinds=[("_fake", [])], params=None):
def inner(target_tasks=None, kinds=None, params=None, enable_verifications=True):
kinds = kinds or [("_fake", [])]
params = params or {}
FakeKind.loaded_kinds = []
target_tasks = target_tasks or []
Expand All @@ -186,7 +187,9 @@ def target_tasks_method(full_task_graph, parameters, graph_config):

monkeypatch.setattr(generator, "load_graph_config", fake_load_graph_config)

return WithFakeKind("/root", parameters)
return WithFakeKind(
"/root", parameters, enable_verifications=enable_verifications
)

return inner

Expand Down
1 change: 1 addition & 0 deletions src/taskgraph/decision.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def taskgraph_decision(options, parameters=None):
parameters=parameters,
decision_task_id=decision_task_id,
write_artifacts=True,
enable_verifications=options.get("verify", True),
)

# write out the parameters used to generate this graph
Expand Down
14 changes: 9 additions & 5 deletions src/taskgraph/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def __init__(
parameters: Union[Parameters, Callable[[GraphConfig], Parameters]],
decision_task_id: str = "DECISION-TASK",
write_artifacts: bool = False,
enable_verifications: bool = True,
):
"""
@param root_dir: root directory containing the Taskgraph config.yml file
Expand All @@ -136,6 +137,7 @@ def __init__(
self._parameters = parameters
self._decision_task_id = decision_task_id
self._write_artifacts = write_artifacts
self._enable_verifications = enable_verifications

# start the generator
self._run = self._run() # type: ignore
Expand Down Expand Up @@ -258,7 +260,7 @@ def _run(self):
graph_config.register()

# Initial verifications that don't depend on any generation state.
verifications("initial")
self.verify("initial")

if callable(self._parameters):
parameters = self._parameters(graph_config)
Expand Down Expand Up @@ -289,7 +291,7 @@ def _run(self):
kinds = {
kind.name: kind for kind in self._load_kinds(graph_config, target_kinds)
}
verifications("kinds", kinds)
self.verify("kinds", kinds)

edges = set()
for kind in kinds.values():
Expand Down Expand Up @@ -437,9 +439,11 @@ def _run_until(self, name):
self._run_results[k] = v
return self._run_results[name]

def verify(self, name, obj, *args, **kwargs):
verifications(name, obj, *args, **kwargs)
return name, obj
def verify(self, name, *args, **kwargs):
if self._enable_verifications:
verifications(name, *args, **kwargs)
if args:
return name, args[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does it return anything?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hysterical raisins? I'm not sure, it's always been like that. We do yield self.verify(...), I guess we could refactor it a bit, but I don't really want to change that as part of this PR.



def load_tasks_for_kind(parameters, kind, root_dir=None):
Expand Down
7 changes: 7 additions & 0 deletions src/taskgraph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,13 @@ def load_task(args):
"--tasks-for", required=True, help="the tasks_for value used to generate this task"
)
@argument("--try-task-config-file", help="path to try task configuration file")
@argument(
"--no-verify",
dest="verify",
default=True,
action="store_false",
help="Skip graph verifications",
)
@argument(
"--verbose", "-v", action="store_true", help="include debug-level logging output"
)
Expand Down
12 changes: 12 additions & 0 deletions test/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ def test_optimized_task_graph(maketgg):
)


def test_verifications(mocker, maketgg):
m = mocker.patch.object(generator, "verifications")
tgg = maketgg(["_fake-t-2"], enable_verifications=True)
tgg.morphed_task_graph
assert m.call_count == 9

m = mocker.patch.object(generator, "verifications")
tgg = maketgg(["_fake-t-2"], enable_verifications=False)
tgg.morphed_task_graph
m.assert_not_called()


def test_load_tasks_for_kind(monkeypatch):
"""
`load_tasks_for_kinds` will load the tasks for the provided kind
Expand Down
Loading