decorator ¤
Module containing the decorator provided to users.
Functions:
-
create_duty
–Register a duty in the collection.
-
duty
–Decorate a callable to transform it and register it as a duty.
create_duty ¤
create_duty(
func: Callable,
*,
name: str | None = None,
aliases: Iterable[str] | None = None,
pre: DutyListType | None = None,
post: DutyListType | None = None,
skip_if: bool = False,
skip_reason: str | None = None,
**opts: Any
) -> Duty
Register a duty in the collection.
Parameters:
-
func
(Callable
) –The callable to register as a duty.
-
name
(str | None
, default:None
) –The duty name.
-
aliases
(Iterable[str] | None
, default:None
) –A set of aliases for this duty.
-
pre
(DutyListType | None
, default:None
) –Pre-duties.
-
post
(DutyListType | None
, default:None
) –Post-duties.
-
skip_if
(bool
, default:False
) –Skip running the duty if the given condition is met.
-
skip_reason
(str | None
, default:None
) –Custom message when skipping.
-
opts
(Any
, default:{}
) –Options passed to the context.
Returns:
-
Duty
–The registered duty.
Source code in src/duty/decorator.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
duty ¤
Decorate a callable to transform it and register it as a duty.
Parameters:
Raises:
-
ValueError
–When the decorator is misused.
Examples:
Decorate a function:
@duty
def clean(ctx):
ctx.run("rm -rf build", silent=True)
Pass options to the context:
@duty(silent=True)
def clean(ctx):
ctx.run("rm -rf build") # silent=True is implied
Returns:
Source code in src/duty/decorator.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|