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

Class Loader

invoke/loader.py:14–96  ·  view source on GitHub ↗

Abstract class defining how to find/import a session's base `.Collection`. .. versionadded:: 1.0

Source from the content-addressed store, hash-verified

12
13
14class Loader:
15 """
16 Abstract class defining how to find/import a session's base `.Collection`.
17
18 .. versionadded:: 1.0
19 """
20
21 def __init__(self, config: Optional["Config"] = None) -> None:
22 """
23 Set up a new loader with some `.Config`.
24
25 :param config:
26 An explicit `.Config` to use; it is referenced for loading-related
27 config options. Defaults to an anonymous ``Config()`` if none is
28 given.
29 """
30 if config is None:
31 config = Config()
32 self.config = config
33
34 def find(self, name: str) -> Optional[ModuleSpec]:
35 """
36 Implementation-specific finder method seeking collection ``name``.
37
38 Must return a ModuleSpec valid for use by `importlib`, which is
39 typically a name string followed by the contents of the 3-tuple
40 returned by `importlib.util.module_from_spec` (``name``, ``loader``,
41 ``origin``.)
42
43 For a sample implementation, see `.FilesystemLoader`.
44
45 .. versionadded:: 1.0
46 """
47 raise NotImplementedError
48
49 def load(self, name: Optional[str] = None) -> Tuple[ModuleType, str]:
50 """
51 Load and return collection module identified by ``name``.
52
53 This method requires a working implementation of `.find` in order to
54 function.
55
56 In addition to importing the named module, it will add the module's
57 parent directory to the front of `sys.path` to provide normal Python
58 import behavior (i.e. so the loaded module may load local-to-it modules
59 or packages.)
60
61 :returns:
62 Two-tuple of ``(module, directory)`` where ``module`` is the
63 collection-containing Python module object, and ``directory`` is
64 the string path to the directory the module was found in.
65
66 .. versionadded:: 1.0
67 """
68 if name is None:
69 name = self.config.tasks.collection_name
70 spec = self.find(name)
71 if spec and spec.loader and spec.origin:

Callers 1

setup_methodMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…