MCPcopy Index your code
hub / github.com/pyinvoke/invoke / add_task

Method add_task

invoke/collection.py:238–283  ·  view source on GitHub ↗

Add `.Task` ``task`` to this collection. :param task: The `.Task` object to add to this collection. :param name: Optional string name to bind to (overrides the task's own self-defined ``name`` attribute and/or any Python identifier (i.e.

(
        self,
        task: "Task",
        name: Optional[str] = None,
        aliases: Optional[Tuple[str, ...]] = None,
        default: Optional[bool] = None,
    )

Source from the content-addressed store, hash-verified

236 return collection
237
238 def add_task(
239 self,
240 task: "Task",
241 name: Optional[str] = None,
242 aliases: Optional[Tuple[str, ...]] = None,
243 default: Optional[bool] = None,
244 ) -> None:
245 """
246 Add `.Task` ``task`` to this collection.
247
248 :param task: The `.Task` object to add to this collection.
249
250 :param name:
251 Optional string name to bind to (overrides the task's own
252 self-defined ``name`` attribute and/or any Python identifier (i.e.
253 ``.func_name``.)
254
255 :param aliases:
256 Optional iterable of additional names to bind the task as, on top
257 of the primary name. These will be used in addition to any aliases
258 the task itself declares internally.
259
260 :param default: Whether this task should be the collection default.
261
262 .. versionadded:: 1.0
263 """
264 if name is None:
265 if task.name:
266 name = task.name
267 # XXX https://github.com/python/mypy/issues/1424
268 elif hasattr(task.body, "func_name"):
269 name = task.body.func_name # type: ignore
270 elif hasattr(task.body, "__name__"):
271 name = task.__name__
272 else:
273 raise ValueError("Could not obtain a name for this task!")
274 name = self.transform(name)
275 if name in self.collections:
276 err = "Name conflict: this collection has a sub-collection named {!r} already" # noqa
277 raise ValueError(err.format(name))
278 self.tasks[name] = task
279 for alias in list(task.aliases) + list(aliases or []):
280 self.tasks.alias(self.transform(alias), to=name)
281 if default is True or (default is None and task.is_default):
282 self._check_default_collision(name)
283 self.default = name
284
285 def add_collection(
286 self,

Calls 2

transformMethod · 0.95

Tested by

no test coverage detected