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

Method from_module

invoke/collection.py:146–236  ·  view source on GitHub ↗

Return a new `.Collection` created from ``module``. Inspects ``module`` for any `.Task` instances and adds them to a new `.Collection`, returning it. If any explicit namespace collections exist (named ``ns`` or ``namespace``) a copy of that collection object

(
        cls,
        module: ModuleType,
        name: Optional[str] = None,
        config: Optional[Dict[str, Any]] = None,
        loaded_from: Optional[str] = None,
        auto_dash_names: Optional[bool] = None,
    )

Source from the content-addressed store, hash-verified

144
145 @classmethod
146 def from_module(
147 cls,
148 module: ModuleType,
149 name: Optional[str] = None,
150 config: Optional[Dict[str, Any]] = None,
151 loaded_from: Optional[str] = None,
152 auto_dash_names: Optional[bool] = None,
153 ) -> "Collection":
154 """
155 Return a new `.Collection` created from ``module``.
156
157 Inspects ``module`` for any `.Task` instances and adds them to a new
158 `.Collection`, returning it. If any explicit namespace collections
159 exist (named ``ns`` or ``namespace``) a copy of that collection object
160 is preferentially loaded instead.
161
162 When the implicit/default collection is generated, it will be named
163 after the module's ``__name__`` attribute, or its last dotted section
164 if it's a submodule. (I.e. it should usually map to the actual ``.py``
165 filename.)
166
167 Explicitly given collections will only be given that module-derived
168 name if they don't already have a valid ``.name`` attribute.
169
170 If the module has a docstring (``__doc__``) it is copied onto the
171 resulting `.Collection` (and used for display in help, list etc
172 output.)
173
174 :param str name:
175 A string, which if given will override any automatically derived
176 collection name (or name set on the module's root namespace, if it
177 has one.)
178
179 :param dict config:
180 Used to set config options on the newly created `.Collection`
181 before returning it (saving you a call to `.configure`.)
182
183 If the imported module had a root namespace object, ``config`` is
184 merged on top of it (i.e. overriding any conflicts.)
185
186 :param str loaded_from:
187 Identical to the same-named kwarg from the regular class
188 constructor - should be the path where the module was
189 found.
190
191 :param bool auto_dash_names:
192 Identical to the same-named kwarg from the regular class
193 constructor - determines whether emitted names are auto-dashed.
194
195 .. versionadded:: 1.0
196 """
197 module_name = module.__name__.split(".")[-1]
198
199 def instantiate(obj_name: Optional[str] = None) -> "Collection":
200 # Explicitly given name wins over root ns name (if applicable),
201 # which wins over actual module name.
202 args = [name or obj_name or module_name]
203 kwargs = dict(

Calls 6

copy_dictFunction · 0.85
merge_dictsFunction · 0.85
_transform_lexiconMethod · 0.80
transformMethod · 0.80
add_taskMethod · 0.80
configureMethod · 0.80

Tested by

no test coverage detected