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

Method __init__

invoke/collection.py:19–114  ·  view source on GitHub ↗

Create a new task collection/namespace. `.Collection` offers a set of methods for building a collection of tasks from scratch, plus a convenient constructor wrapping said API. In either case: * The first positional argument may be a string, which (if given

(self, *args: Any, **kwargs: Any)

Source from the content-addressed store, hash-verified

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
70 to `.add_task`/`.add_collection` as appropriate. Module objects are
71 also valid (as they are for `.add_collection`). For example, the below
72 snippet results in the same two task identifiers as the one above::
73
74 ns = Collection(top_level_task, Collection('docs', doc_task))
75
76 If any ``**kwargs`` are given, the keywords are used as the initial

Callers

nothing calls this directly

Calls 3

transformMethod · 0.95
_add_objectMethod · 0.95
popMethod · 0.45

Tested by

no test coverage detected