context ¤
Module containing the context definition.
Classes:
-
Context
–A simple context class.
Context ¤
A simple context class.
Context instances are passed to functions decorated with duty
.
Parameters:
-
options
(dict[str, Any]
) –Base options specified in
@duty(**options)
. -
options_override
(dict[str, Any] | None
, default:None
) –Options that override
run
and@duty
options. This argument is used to allow users to override options from the CLI or environment.
Methods:
-
cd
–Change working directory as a context manager.
-
options
–Change options as a context manager.
-
run
–Run a command in a subprocess or a Python callable.
Source code in src/duty/context.py
22 23 24 25 26 27 28 29 30 31 32 |
|
cd ¤
Change working directory as a context manager.
Parameters:
-
directory
(str
) –The directory to go into.
Yields:
-
Iterator
–Nothing.
Source code in src/duty/context.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
options ¤
Change options as a context manager.
Can be nested as will, previous options will pop once out of the with clause.
Parameters:
-
**opts
(Any
, default:{}
) –Options used in
run
.
Yields:
-
Iterator
–Nothing.
Source code in src/duty/context.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
run ¤
Run a command in a subprocess or a Python callable.
Parameters:
-
cmd
(CmdType
) –A command or a Python callable.
-
options
(Any
, default:{}
) –Options passed to
failprint
functions.
Raises:
-
DutyFailure
–When the exit code / function result is greather than 0.
Returns:
-
str
–The output of the command.
Source code in src/duty/context.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|