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

Class Collection

invoke/collection.py:12–608  ·  view source on GitHub ↗

A collection of executable tasks. See :doc:`/concepts/namespaces`. .. versionadded:: 1.0

Source from the content-addressed store, hash-verified

10
11
12class Collection:
13 """
14 A collection of executable tasks. See :doc:`/concepts/namespaces`.
15
16 .. versionadded:: 1.0
17 """
18
19 def __init__(self, *args: Any, **kwargs: Any) -> None:
20 """
21 Create a new task collection/namespace.
22
23 `.Collection` offers a set of methods for building a collection of
24 tasks from scratch, plus a convenient constructor wrapping said API.
25
26 In either case:
27
28 * The first positional argument may be a string, which (if given) is
29 used as the collection's default name when performing namespace
30 lookups;
31 * A ``loaded_from`` keyword argument may be given, which sets metadata
32 indicating the filesystem path the collection was loaded from. This
33 is used as a guide when loading per-project :ref:`configuration files
34 <config-hierarchy>`.
35 * An ``auto_dash_names`` kwarg may be given, controlling whether task
36 and collection names have underscores turned to dashes in most cases;
37 it defaults to ``True`` but may be set to ``False`` to disable.
38
39 The CLI machinery will pass in the value of the
40 ``tasks.auto_dash_names`` config value to this kwarg.
41
42 **The method approach**
43
44 May initialize with no arguments and use methods (e.g.
45 `.add_task`/`.add_collection`) to insert objects::
46
47 c = Collection()
48 c.add_task(some_task)
49
50 If an initial string argument is given, it is used as the default name
51 for this collection, should it be inserted into another collection as a
52 sub-namespace::
53
54 docs = Collection('docs')
55 docs.add_task(doc_task)
56 ns = Collection()
57 ns.add_task(top_level_task)
58 ns.add_collection(docs)
59 # Valid identifiers are now 'top_level_task' and 'docs.doc_task'
60 # (assuming the task objects were actually named the same as the
61 # variables we're using :))
62
63 For details, see the API docs for the rest of the class.
64
65 **The constructor approach**
66
67 All ``*args`` given to `.Collection` (besides the abovementioned
68 optional positional 'name' argument and ``loaded_from`` kwarg) are
69 expected to be `.Task` or `.Collection` instances which will be passed

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…