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

Class Context

invoke/context.py:22–411  ·  view source on GitHub ↗

Context-aware API wrapper & state-passing object. `.Context` objects are created during command-line parsing (or, if desired, by hand) and used to share parser and configuration state with executed tasks (see :ref:`why-context`). Specifically, the class offers wrappers for cor

Source from the content-addressed store, hash-verified

20
21
22class Context(DataProxy):
23 """
24 Context-aware API wrapper & state-passing object.
25
26 `.Context` objects are created during command-line parsing (or, if desired,
27 by hand) and used to share parser and configuration state with executed
28 tasks (see :ref:`why-context`).
29
30 Specifically, the class offers wrappers for core API calls (such as `.run`)
31 which take into account CLI parser flags, configuration files, and/or
32 changes made at runtime. It also acts as a proxy for its `~.Context.config`
33 attribute - see that attribute's documentation for details.
34
35 Instances of `.Context` may be shared between tasks when executing
36 sub-tasks - either the same context the caller was given, or an altered
37 copy thereof (or, theoretically, a brand new one).
38
39 .. versionadded:: 1.0
40 """
41
42 # NOTE: sometime after Sphinx 1.7, autodoc stopped being able to see
43 # doc-comments inside __init__ (or something equivalent, anyway). Moving
44 # the type definitions up here seems to work better and /shouldn't/ mess up
45 # the DataProxy magic going on...
46
47 #: A list of commands to run (via "&&") before the main argument to any
48 #: `run` or `sudo` calls. Note that the primary API for manipulating
49 #: this list is `prefix`; see its docs for details.
50 command_prefixes: List[str]
51 #: A list of directories to 'cd' into before running commands with
52 #: `run` or `sudo`; intended for management via `cd`, please see its
53 #: docs for details.
54 command_cwds: List[str]
55 #: The CLI parser's 'remainder' value (text given after a standalone
56 #: ``--`` in the command line), or the empty string if not given.
57 remainder: str
58
59 def __init__(
60 self,
61 config: Optional[Config] = None,
62 remainder: str = "",
63 ) -> None:
64 """
65 :param config:
66 `.Config` object to use as the base configuration.
67
68 Defaults to an anonymous/default `.Config` instance.
69
70 :param remainder:
71 The invoking program&#x27;s :ref:`parser remainder <remainder>` value,
72 if any was obtained.
73 """
74 config = config if config is not None else Config()
75 self._set(
76 _config=config,
77 command_prefixes=[],
78 command_cwds=[],
79 remainder=remainder,

Callers 15

base_caseMethod · 0.90
_hang_on_full_pipeMethod · 0.90
_expect_attrMethod · 0.90
defaults_to_LocalMethod · 0.90
setup_methodMethod · 0.90
setup_methodMethod · 0.90
should_apply_to_runMethod · 0.90
should_apply_to_sudoMethod · 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…