Core object representing an executable task & its argument specification. For the most part, this object is a clearinghouse for all of the data that may be supplied to the `@task ` decorator, such as ``name``, ``aliases``, ``positional`` etc, which appear as attr
| 35 | |
| 36 | |
| 37 | class Task(Generic[T]): |
| 38 | """ |
| 39 | Core object representing an executable task & its argument specification. |
| 40 | |
| 41 | For the most part, this object is a clearinghouse for all of the data that |
| 42 | may be supplied to the `@task <invoke.tasks.task>` decorator, such as |
| 43 | ``name``, ``aliases``, ``positional`` etc, which appear as attributes. |
| 44 | |
| 45 | In addition, instantiation copies some introspection/documentation friendly |
| 46 | metadata off of the supplied ``body`` object, such as ``__doc__``, |
| 47 | ``__name__`` and ``__module__``, allowing it to "appear as" ``body`` for |
| 48 | most intents and purposes. |
| 49 | |
| 50 | .. versionadded:: 1.0 |
| 51 | """ |
| 52 | |
| 53 | # TODO: store these kwarg defaults central, refer to those values both here |
| 54 | # and in @task. |
| 55 | # TODO: allow central per-session / per-taskmodule control over some of |
| 56 | # them, e.g. (auto_)positional, auto_shortflags. |
| 57 | # NOTE: we shadow __builtins__.help here on purpose - obfuscating to avoid |
| 58 | # it feels bad, given the builtin will never actually be in play anywhere |
| 59 | # except a debug shell whose frame is exactly inside this class. |
| 60 | def __init__( |
| 61 | self, |
| 62 | body: Callable, |
| 63 | name: Optional[str] = None, |
| 64 | aliases: Iterable[str] = (), |
| 65 | positional: Optional[Iterable[str]] = None, |
| 66 | optional: Iterable[str] = (), |
| 67 | default: bool = False, |
| 68 | auto_shortflags: bool = True, |
| 69 | help: Optional[Dict[str, Any]] = None, |
| 70 | pre: Optional[Union[List[str], str]] = None, |
| 71 | post: Optional[Union[List[str], str]] = None, |
| 72 | autoprint: bool = False, |
| 73 | iterable: Optional[Iterable[str]] = None, |
| 74 | incrementable: Optional[Iterable[str]] = None, |
| 75 | ) -> None: |
| 76 | # Real callable |
| 77 | self.body = body |
| 78 | update_wrapper(self, self.body) |
| 79 | # Copy a bunch of special properties from the body for the benefit of |
| 80 | # Sphinx autodoc or other introspectors. |
| 81 | self.__doc__ = getattr(body, "__doc__", "") |
| 82 | self.__name__ = getattr(body, "__name__", "") |
| 83 | self.__module__ = getattr(body, "__module__", "") |
| 84 | # Default name, alternate names, and whether it should act as the |
| 85 | # default for its parent collection |
| 86 | self._name = name |
| 87 | self.aliases = aliases |
| 88 | self.is_default = default |
| 89 | # Arg/flag/parser hints |
| 90 | self.positional = self.fill_implicit_positionals(positional) |
| 91 | self.optional = tuple(optional) |
| 92 | self.iterable = iterable or [] |
| 93 | self.incrementable = incrementable or [] |
| 94 | self.auto_shortflags = auto_shortflags |
no outgoing calls
no test coverage detected
searching dependent graphs…