Skip to content

Commit aee8364

Browse files
authored
Allow TaskExtensions to control TaskContext creation (#725)
This non-breaking API change to the TaskExtension plugin allows tasks to control the creation of TaskContext instances, which are then used to create Job instances for execution. In particular this allows tasks to schedule any number of jobs, where they currently always schedule one.
1 parent b5c82cc commit aee8364

3 files changed

Lines changed: 45 additions & 17 deletions

File tree

colcon_core/task/__init__.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2016-2018 Dirk Thomas
22
# Licensed under the Apache License, Version 2.0
33

4+
from collections import OrderedDict
45
import os
56
import shutil
67
import sys
@@ -60,7 +61,33 @@ class TaskExtensionPoint:
6061
"""
6162

6263
"""The version of the task extension interface."""
63-
EXTENSION_POINT_VERSION = '1.0'
64+
EXTENSION_POINT_VERSION = '1.1'
65+
66+
@classmethod
67+
def create_contexts(cls, *, pkg, args, dependencies):
68+
"""
69+
Construct TaskContext instances for a package.
70+
71+
A :py:class:`~colcon_core.executor.Job` will be created for each
72+
:py:class:`~colcon_core.task.TaskContext` that is returned from this
73+
method, with :py:attr:`~colcon_core.executor.Job.identifier`
74+
corresponding to the key. Implementations may return any number of
75+
jobs, but care should be taken to ensure that only one of the jobs is
76+
executed at any given time, presumably by ensuring that dependencies
77+
exist between them.
78+
79+
:param pkg: The package descriptor
80+
:param args: The parsed command line arguments
81+
:param dependencies: The ordered dictionary mapping dependency names to
82+
their paths
83+
:returns: Mapping of job identifier to task context
84+
:rtype: collections.OrderedDict
85+
"""
86+
return OrderedDict((
87+
(pkg.name, TaskContext(
88+
pkg=pkg, args=args,
89+
dependencies=dependencies)),
90+
))
6491

6592
def add_arguments(self, *, parser):
6693
"""

colcon_core/verb/build.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from colcon_core.shell import get_shell_extensions
2626
from colcon_core.task import add_task_arguments
2727
from colcon_core.task import get_task_extension
28-
from colcon_core.task import TaskContext
2928
from colcon_core.verb import check_and_mark_build_tool
3029
from colcon_core.verb import check_and_mark_install_layout
3130
from colcon_core.verb import logger
@@ -201,16 +200,17 @@ def _get_jobs(self, args, decorators, install_base):
201200
logger.debug(
202201
f"Building package '{pkg.name}' with the following arguments: "
203202
f'{{{ordered_package_args}}}')
204-
task_context = TaskContext(
203+
task_contexts = extension.create_contexts(
205204
pkg=pkg, args=package_args,
206205
dependencies=recursive_dependencies)
207206

208-
job = Job(
209-
identifier=pkg.name,
210-
dependencies=set(recursive_dependencies.keys()),
211-
task=extension, task_context=task_context)
207+
for identifier, task_context in task_contexts.items():
208+
job = Job(
209+
identifier=identifier,
210+
dependencies=set(task_context.dependencies.keys()),
211+
task=extension, task_context=task_context)
212212

213-
jobs[pkg.name] = job
213+
jobs[identifier] = job
214214
return jobs, unselected_packages
215215

216216
def _create_prefix_scripts(self, install_base, merge_install):

colcon_core/verb/test.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from colcon_core.plugin_system import satisfies_version
2525
from colcon_core.task import add_task_arguments
2626
from colcon_core.task import get_task_extension
27-
from colcon_core.task import TaskContext
2827
from colcon_core.verb import check_and_mark_build_tool
2928
from colcon_core.verb import check_and_mark_install_layout
3029
from colcon_core.verb import update_object
@@ -211,16 +210,18 @@ def _get_jobs(self, args, decorators, install_base):
211210
logger.debug(
212211
f"Testing package '{pkg.name}' with the following arguments: "
213212
f'{{{ordered_package_args}}}')
214-
task_context = TaskContext(
213+
task_contexts = extension.create_contexts(
215214
pkg=pkg, args=package_args,
216215
dependencies=recursive_dependencies)
217216

218-
job = Job(
219-
identifier=pkg.name,
220-
dependencies=set(
221-
() if drop_test_deps else recursive_dependencies.keys()
222-
),
223-
task=extension, task_context=task_context)
217+
for identifier, task_context in task_contexts.items():
218+
job = Job(
219+
identifier=identifier,
220+
dependencies=set(
221+
() if drop_test_deps
222+
else task_context.dependencies.keys()
223+
),
224+
task=extension, task_context=task_context)
224225

225-
jobs[pkg.name] = job
226+
jobs[identifier] = job
226227
return jobs

0 commit comments

Comments
 (0)