From 2bf745809149a30f2654333d536e44f8dab1bc32 Mon Sep 17 00:00:00 2001 From: kasium <15907922+kasium@users.noreply.github.com> Date: Sat, 22 Jan 2022 05:44:26 +0100 Subject: [PATCH] Add stubs for invoke (#6938) --- pyrightconfig.stricter.json | 1 + stubs/invoke/METADATA.toml | 1 + stubs/invoke/invoke/__init__.pyi | 37 ++++++++ stubs/invoke/invoke/collection.pyi | 24 ++++++ stubs/invoke/invoke/completion/__init__.pyi | 0 stubs/invoke/invoke/completion/complete.pyi | 8 ++ stubs/invoke/invoke/config.pyi | 60 +++++++++++++ stubs/invoke/invoke/context.pyi | 22 +++++ stubs/invoke/invoke/env.pyi | 6 ++ stubs/invoke/invoke/exceptions.pyi | 47 +++++++++++ stubs/invoke/invoke/executor.pyi | 16 ++++ stubs/invoke/invoke/loader.pyi | 15 ++++ stubs/invoke/invoke/main.pyi | 3 + stubs/invoke/invoke/parser/__init__.pyi | 3 + stubs/invoke/invoke/parser/argument.pyi | 37 ++++++++ stubs/invoke/invoke/parser/context.pyi | 24 ++++++ stubs/invoke/invoke/parser/parser.pyi | 42 +++++++++ stubs/invoke/invoke/program.pyi | 71 ++++++++++++++++ stubs/invoke/invoke/runners.pyi | 94 +++++++++++++++++++++ stubs/invoke/invoke/tasks.pyi | 71 ++++++++++++++++ stubs/invoke/invoke/terminals.pyi | 12 +++ stubs/invoke/invoke/util.pyi | 39 +++++++++ stubs/invoke/invoke/watchers.pyi | 20 +++++ 23 files changed, 653 insertions(+) create mode 100644 stubs/invoke/METADATA.toml create mode 100644 stubs/invoke/invoke/__init__.pyi create mode 100644 stubs/invoke/invoke/collection.pyi create mode 100644 stubs/invoke/invoke/completion/__init__.pyi create mode 100644 stubs/invoke/invoke/completion/complete.pyi create mode 100644 stubs/invoke/invoke/config.pyi create mode 100644 stubs/invoke/invoke/context.pyi create mode 100644 stubs/invoke/invoke/env.pyi create mode 100644 stubs/invoke/invoke/exceptions.pyi create mode 100644 stubs/invoke/invoke/executor.pyi create mode 100644 stubs/invoke/invoke/loader.pyi create mode 100644 stubs/invoke/invoke/main.pyi create mode 100644 stubs/invoke/invoke/parser/__init__.pyi create mode 100644 stubs/invoke/invoke/parser/argument.pyi create mode 100644 stubs/invoke/invoke/parser/context.pyi create mode 100644 stubs/invoke/invoke/parser/parser.pyi create mode 100644 stubs/invoke/invoke/program.pyi create mode 100644 stubs/invoke/invoke/runners.pyi create mode 100644 stubs/invoke/invoke/tasks.pyi create mode 100644 stubs/invoke/invoke/terminals.pyi create mode 100644 stubs/invoke/invoke/util.pyi create mode 100644 stubs/invoke/invoke/watchers.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index eb179359a..b8049395d 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -36,6 +36,7 @@ "stubs/html5lib", "stubs/httplib2", "stubs/humanfriendly", + "stubs/invoke", "stubs/jmespath", "stubs/jsonschema", "stubs/ldap3", diff --git a/stubs/invoke/METADATA.toml b/stubs/invoke/METADATA.toml new file mode 100644 index 000000000..6cf9fae44 --- /dev/null +++ b/stubs/invoke/METADATA.toml @@ -0,0 +1 @@ +version = "1.6.*" diff --git a/stubs/invoke/invoke/__init__.pyi b/stubs/invoke/invoke/__init__.pyi new file mode 100644 index 000000000..6bf0e8a10 --- /dev/null +++ b/stubs/invoke/invoke/__init__.pyi @@ -0,0 +1,37 @@ +from typing import Any + +from .collection import Collection as Collection +from .config import Config as Config +from .context import Context as Context, MockContext as MockContext +from .exceptions import ( + AmbiguousEnvVar as AmbiguousEnvVar, + AuthFailure as AuthFailure, + CollectionNotFound as CollectionNotFound, + CommandTimedOut as CommandTimedOut, + Exit as Exit, + Failure as Failure, + ParseError as ParseError, + PlatformError as PlatformError, + ResponseNotAccepted as ResponseNotAccepted, + SubprocessPipeError as SubprocessPipeError, + ThreadException as ThreadException, + UncastableEnvVar as UncastableEnvVar, + UnexpectedExit as UnexpectedExit, + UnknownFileType as UnknownFileType, + UnpicklableConfigMember as UnpicklableConfigMember, + WatcherError as WatcherError, +) +from .executor import Executor as Executor +from .loader import FilesystemLoader as FilesystemLoader +from .parser import Argument as Argument, Parser as Parser, ParserContext as ParserContext, ParseResult as ParseResult +from .program import Program as Program +from .runners import Local as Local, Promise as Promise, Result as Result, Runner as Runner +from .tasks import Call as Call, Task as Task, call as call, task as task +from .terminals import pty_size as pty_size +from .watchers import FailingResponder as FailingResponder, Responder as Responder, StreamWatcher as StreamWatcher + +__version_info__: tuple[int, int, int] +__version__: str + +def run(command: str, **kwargs: Any) -> Result: ... +def sudo(command: str, **kwargs: Any) -> Result: ... diff --git a/stubs/invoke/invoke/collection.pyi b/stubs/invoke/invoke/collection.pyi new file mode 100644 index 000000000..c1f0744fa --- /dev/null +++ b/stubs/invoke/invoke/collection.pyi @@ -0,0 +1,24 @@ +from typing import Any + +class Collection: + tasks: Any + collections: Any + default: str | None + name: str | None + loaded_from: Any + auto_dash_names: bool + def __init__(self, *args, **kwargs) -> None: ... + @classmethod + def from_module(cls, module, name=..., config=..., loaded_from=..., auto_dash_names=...): ... + def add_task(self, task, name=..., aliases=..., default=...) -> None: ... + def add_collection(self, coll, name=..., default=...) -> None: ... + def subcollection_from_path(self, path): ... + def task_with_config(self, name): ... + def to_contexts(self): ... + def subtask_name(self, collection_name, task_name): ... + def transform(self, name): ... + @property + def task_names(self): ... + def configuration(self, taskpath=...): ... + def configure(self, options) -> None: ... + def serialized(self): ... diff --git a/stubs/invoke/invoke/completion/__init__.pyi b/stubs/invoke/invoke/completion/__init__.pyi new file mode 100644 index 000000000..e69de29bb diff --git a/stubs/invoke/invoke/completion/complete.pyi b/stubs/invoke/invoke/completion/complete.pyi new file mode 100644 index 000000000..a59c2c44e --- /dev/null +++ b/stubs/invoke/invoke/completion/complete.pyi @@ -0,0 +1,8 @@ +from typing import Iterable, NoReturn, Sequence + +from ..collection import Collection +from ..parser import ParserContext, ParseResult + +def complete(names: Iterable[str], core: ParseResult, initial_context: ParserContext, collection: Collection) -> NoReturn: ... +def print_task_names(collection: Collection) -> None: ... +def print_completion_script(shell: str, names: Sequence[str]) -> None: ... diff --git a/stubs/invoke/invoke/config.pyi b/stubs/invoke/invoke/config.pyi new file mode 100644 index 000000000..c64180eb2 --- /dev/null +++ b/stubs/invoke/invoke/config.pyi @@ -0,0 +1,60 @@ +from typing import Any + +def load_source(name: str, path: str) -> dict[str, Any]: ... + +class DataProxy: + @classmethod + def from_data(cls, data, root=..., keypath=...): ... + def __getattr__(self, key): ... + def __setattr__(self, key, value) -> None: ... + def __iter__(self): ... + def __eq__(self, other): ... + __hash__: Any + def __len__(self): ... + def __setitem__(self, key, value) -> None: ... + def __getitem__(self, key): ... + def __contains__(self, key): ... + def __delitem__(self, key) -> None: ... + def __delattr__(self, name) -> None: ... + def clear(self) -> None: ... + def pop(self, *args): ... + def popitem(self): ... + def setdefault(self, *args): ... + def update(self, *args, **kwargs) -> None: ... + +class Config(DataProxy): + prefix: str + file_prefix: Any + env_prefix: Any + @staticmethod + def global_defaults(): ... + def __init__( + self, + overrides=..., + defaults=..., + system_prefix=..., + user_prefix=..., + project_location=..., + runtime_path=..., + lazy: bool = ..., + ) -> None: ... + def load_base_conf_files(self) -> None: ... + def load_defaults(self, data, merge: bool = ...) -> None: ... + def load_overrides(self, data, merge: bool = ...) -> None: ... + def load_system(self, merge: bool = ...) -> None: ... + def load_user(self, merge: bool = ...) -> None: ... + def load_project(self, merge: bool = ...) -> None: ... + def set_runtime_path(self, path) -> None: ... + def load_runtime(self, merge: bool = ...) -> None: ... + def load_shell_env(self) -> None: ... + def load_collection(self, data, merge: bool = ...) -> None: ... + def set_project_location(self, path) -> None: ... + def merge(self) -> None: ... + def clone(self, into=...): ... + +class AmbiguousMergeError(ValueError): ... + +def merge_dicts(base, updates): ... +def copy_dict(source): ... +def excise(dict_, keypath) -> None: ... +def obliterate(base, deletions) -> None: ... diff --git a/stubs/invoke/invoke/context.pyi b/stubs/invoke/invoke/context.pyi new file mode 100644 index 000000000..b8013b109 --- /dev/null +++ b/stubs/invoke/invoke/context.pyi @@ -0,0 +1,22 @@ +from contextlib import AbstractContextManager + +from .config import Config, DataProxy + +class Context(DataProxy): + def __init__(self, config: Config | None = ...) -> None: ... + @property + def config(self) -> Config: ... + @config.setter + def config(self, value: Config) -> None: ... + def run(self, command: str, **kwargs): ... + def sudo(self, command: str, *, password: str = ..., user: str = ..., **kwargs): ... + def prefix(self, command: str) -> AbstractContextManager[None]: ... + @property + def cwd(self) -> str: ... + def cd(self, path: str) -> AbstractContextManager[None]: ... + +class MockContext(Context): + def __init__(self, config: Config | None = ..., **kwargs) -> None: ... + def run(self, command: str, *args, **kwargs): ... + def sudo(self, command: str, *args, **kwargs): ... + def set_result_for(self, attname, command, result) -> None: ... diff --git a/stubs/invoke/invoke/env.pyi b/stubs/invoke/invoke/env.pyi new file mode 100644 index 000000000..38ffc6721 --- /dev/null +++ b/stubs/invoke/invoke/env.pyi @@ -0,0 +1,6 @@ +from typing import Any + +class Environment: + data: Any + def __init__(self, config, prefix) -> None: ... + def load(self): ... diff --git a/stubs/invoke/invoke/exceptions.pyi b/stubs/invoke/invoke/exceptions.pyi new file mode 100644 index 000000000..437cbc935 --- /dev/null +++ b/stubs/invoke/invoke/exceptions.pyi @@ -0,0 +1,47 @@ +from typing import Any + +class CollectionNotFound(Exception): + name: Any + start: Any + def __init__(self, name, start) -> None: ... + +class Failure(Exception): + result: Any + reason: Any + def __init__(self, result, reason=...) -> None: ... + def streams_for_display(self): ... + +class UnexpectedExit(Failure): ... + +class CommandTimedOut(Failure): + timeout: Any + def __init__(self, result, timeout) -> None: ... + +class AuthFailure(Failure): + result: Any + prompt: Any + def __init__(self, result, prompt) -> None: ... + +class ParseError(Exception): + context: Any + def __init__(self, msg, context=...) -> None: ... + +class Exit(Exception): + message: Any + def __init__(self, message=..., code=...) -> None: ... + @property + def code(self): ... + +class PlatformError(Exception): ... +class AmbiguousEnvVar(Exception): ... +class UncastableEnvVar(Exception): ... +class UnknownFileType(Exception): ... +class UnpicklableConfigMember(Exception): ... + +class ThreadException(Exception): + exceptions: Any + def __init__(self, exceptions) -> None: ... + +class WatcherError(Exception): ... +class ResponseNotAccepted(WatcherError): ... +class SubprocessPipeError(Exception): ... diff --git a/stubs/invoke/invoke/executor.pyi b/stubs/invoke/invoke/executor.pyi new file mode 100644 index 000000000..7d8852cf2 --- /dev/null +++ b/stubs/invoke/invoke/executor.pyi @@ -0,0 +1,16 @@ +from typing import Any, Iterable + +from .collection import Collection +from .config import Config +from .parser import ParserContext, ParseResult +from .tasks import Call, Task + +class Executor: + collection: Collection + config: Config + core: ParseResult | None + def __init__(self, collection: Collection, config: Config | None = ..., core: ParseResult | None = ...) -> None: ... + def execute(self, *tasks: str | tuple[str, dict[str, Any]] | ParserContext) -> dict[Task, Any]: ... + def normalize(self, tasks: Iterable[str | tuple[str, dict[str, Any]] | ParserContext]): ... + def dedupe(self, calls: Iterable[Call]) -> list[Call]: ... + def expand_calls(self, calls: Iterable[Call | Task]) -> list[Call]: ... diff --git a/stubs/invoke/invoke/loader.pyi b/stubs/invoke/invoke/loader.pyi new file mode 100644 index 000000000..b339d5de3 --- /dev/null +++ b/stubs/invoke/invoke/loader.pyi @@ -0,0 +1,15 @@ +from types import ModuleType +from typing import IO, Any + +from . import Config + +class Loader: + config: Config + def __init__(self, config: Config | None = ...) -> None: ... + def find(self, name: str) -> tuple[str, IO[Any], str, tuple[str, str, int]]: ... + def load(self, name: str | None = ...) -> tuple[ModuleType, str]: ... + +class FilesystemLoader(Loader): + def __init__(self, start: str | None = ..., **kwargs: Any) -> None: ... + @property + def start(self) -> str: ... diff --git a/stubs/invoke/invoke/main.pyi b/stubs/invoke/invoke/main.pyi new file mode 100644 index 000000000..d05ea6428 --- /dev/null +++ b/stubs/invoke/invoke/main.pyi @@ -0,0 +1,3 @@ +from . import Program + +program: Program diff --git a/stubs/invoke/invoke/parser/__init__.pyi b/stubs/invoke/invoke/parser/__init__.pyi new file mode 100644 index 000000000..86a533969 --- /dev/null +++ b/stubs/invoke/invoke/parser/__init__.pyi @@ -0,0 +1,3 @@ +from .argument import Argument as Argument +from .context import ParserContext as ParserContext, to_flag as to_flag, translate_underscores as translate_underscores +from .parser import * diff --git a/stubs/invoke/invoke/parser/argument.pyi b/stubs/invoke/invoke/parser/argument.pyi new file mode 100644 index 000000000..1fd21823f --- /dev/null +++ b/stubs/invoke/invoke/parser/argument.pyi @@ -0,0 +1,37 @@ +from typing import Any + +class Argument: + names: Any + kind: Any + raw_value: Any + default: Any + help: Any + positional: Any + optional: Any + incrementable: Any + attr_name: Any + def __init__( + self, + name=..., + names=..., + kind=..., + default=..., + help=..., + positional: bool = ..., + optional: bool = ..., + incrementable: bool = ..., + attr_name=..., + ) -> None: ... + @property + def name(self): ... + @property + def nicknames(self): ... + @property + def takes_value(self): ... + @property + def value(self): ... + @value.setter + def value(self, arg) -> None: ... + def set_value(self, value, cast: bool = ...): ... + @property + def got_value(self): ... diff --git a/stubs/invoke/invoke/parser/context.pyi b/stubs/invoke/invoke/parser/context.pyi new file mode 100644 index 000000000..80cc56a57 --- /dev/null +++ b/stubs/invoke/invoke/parser/context.pyi @@ -0,0 +1,24 @@ +from typing import Any + +def translate_underscores(name: str) -> str: ... +def to_flag(name: str) -> str: ... +def sort_candidate(arg): ... +def flag_key(x): ... + +class ParserContext: + args: Any + positional_args: Any + flags: Any + inverse_flags: Any + name: Any + aliases: Any + def __init__(self, name=..., aliases=..., args=...) -> None: ... + def add_arg(self, *args, **kwargs) -> None: ... + @property + def missing_positional_args(self): ... + @property + def as_kwargs(self): ... + def names_for(self, flag): ... + def help_for(self, flag): ... + def help_tuples(self): ... + def flag_names(self): ... diff --git a/stubs/invoke/invoke/parser/parser.pyi b/stubs/invoke/invoke/parser/parser.pyi new file mode 100644 index 000000000..2f836db1a --- /dev/null +++ b/stubs/invoke/invoke/parser/parser.pyi @@ -0,0 +1,42 @@ +from typing import Any + +from .context import ParserContext + +def is_flag(value: str) -> bool: ... +def is_long_flag(value: str) -> bool: ... + +class Parser: + initial: Any + contexts: Any + ignore_unknown: Any + def __init__(self, contexts=..., initial=..., ignore_unknown: bool = ...) -> None: ... + def parse_argv(self, argv): ... + +class ParseMachine: + initial_state: str + def changing_state(self, from_, to) -> None: ... + ignore_unknown: Any + initial: Any + flag: Any + flag_got_value: bool + result: Any + contexts: Any + def __init__(self, initial, contexts, ignore_unknown) -> None: ... + @property + def waiting_for_flag_value(self): ... + def handle(self, token) -> None: ... + def store_only(self, token) -> None: ... + def complete_context(self) -> None: ... + context: Any + def switch_to_context(self, name) -> None: ... + def complete_flag(self) -> None: ... + def check_ambiguity(self, value): ... + def switch_to_flag(self, flag, inverse: bool = ...) -> None: ... + def see_value(self, value) -> None: ... + def see_positional_arg(self, value) -> None: ... + def error(self, msg) -> None: ... + +class ParseResult(list[ParserContext]): + remainder: str + unparsed: Any + def __init__(self, *args, **kwargs) -> None: ... diff --git a/stubs/invoke/invoke/program.pyi b/stubs/invoke/invoke/program.pyi new file mode 100644 index 000000000..280458237 --- /dev/null +++ b/stubs/invoke/invoke/program.pyi @@ -0,0 +1,71 @@ +from typing import Any + +class Program: + def core_args(self): ... + def task_args(self): ... + leading_indent_width: int + leading_indent: str + indent_width: int + indent: str + col_padding: int + version: Any + namespace: Any + argv: Any + loader_class: Any + executor_class: Any + config_class: Any + def __init__( + self, + version=..., + namespace=..., + name=..., + binary=..., + loader_class=..., + executor_class=..., + config_class=..., + binary_names=..., + ) -> None: ... + config: Any + def create_config(self) -> None: ... + def update_config(self, merge: bool = ...) -> None: ... + def run(self, argv=..., exit: bool = ...) -> None: ... + def parse_core(self, argv) -> None: ... + collection: Any + list_root: Any + list_depth: Any + list_format: str + scoped_collection: Any + def parse_collection(self) -> None: ... + def parse_cleanup(self) -> None: ... + def no_tasks_given(self) -> None: ... + def execute(self) -> None: ... + def normalize_argv(self, argv) -> None: ... + @property + def name(self): ... + @property + def called_as(self): ... + @property + def binary(self): ... + @property + def binary_names(self): ... + @property + def args(self): ... + @property + def initial_context(self): ... + def print_version(self) -> None: ... + def print_help(self) -> None: ... + core: Any + def parse_core_args(self) -> None: ... + def load_collection(self) -> None: ... + parser: Any + core_via_tasks: Any + tasks: Any + def parse_tasks(self) -> None: ... + def print_task_help(self, name) -> None: ... + def list_tasks(self) -> None: ... + def list_flat(self) -> None: ... + def list_nested(self) -> None: ... + def list_json(self) -> None: ... + def task_list_opener(self, extra: str = ...): ... + def display_with_columns(self, pairs, extra: str = ...) -> None: ... + def print_columns(self, tuples) -> None: ... diff --git a/stubs/invoke/invoke/runners.pyi b/stubs/invoke/invoke/runners.pyi new file mode 100644 index 000000000..fd198395e --- /dev/null +++ b/stubs/invoke/invoke/runners.pyi @@ -0,0 +1,94 @@ +from typing import Any +from typing_extensions import Literal + +class Runner: + read_chunk_size: int + input_sleep: float + context: Any + program_finished: Any + warned_about_pty_fallback: bool + watchers: Any + def __init__(self, context) -> None: ... + def run(self, command, **kwargs): ... + def echo(self, command) -> None: ... + def make_promise(self): ... + def create_io_threads(self): ... + def generate_result(self, **kwargs): ... + def read_proc_output(self, reader) -> None: ... + def write_our_output(self, stream, string) -> None: ... + def handle_stdout(self, buffer_, hide, output) -> None: ... + def handle_stderr(self, buffer_, hide, output) -> None: ... + def read_our_stdin(self, input_): ... + def handle_stdin(self, input_, output, echo) -> None: ... + def should_echo_stdin(self, input_, output): ... + def respond(self, buffer_) -> None: ... + def generate_env(self, env, replace_env): ... + def should_use_pty(self, pty, fallback): ... + @property + def has_dead_threads(self): ... + def wait(self) -> None: ... + def write_proc_stdin(self, data) -> None: ... + def decode(self, data): ... + @property + def process_is_finished(self) -> None: ... + def start(self, command, shell, env) -> None: ... + def start_timer(self, timeout) -> None: ... + def read_proc_stdout(self, num_bytes) -> None: ... + def read_proc_stderr(self, num_bytes) -> None: ... + def close_proc_stdin(self) -> None: ... + def default_encoding(self): ... + def send_interrupt(self, interrupt) -> None: ... + def returncode(self) -> None: ... + def stop(self) -> None: ... + def stop_timer(self) -> None: ... + def kill(self) -> None: ... + @property + def timed_out(self): ... + +class Local(Runner): + status: Any + def __init__(self, context) -> None: ... + def should_use_pty(self, pty: bool = ..., fallback: bool = ...): ... + process: Any + +class Result: + stdout: str + stderr: str + encoding: str + command: str + shell: Any + env: dict[str, Any] + exited: int + pty: bool + hide: tuple[Literal["stdout", "stderr"], ...] + def __init__( + self, + stdout: str = ..., + stderr: str = ..., + encoding: str | None = ..., + command: str = ..., + shell: str = ..., + env=..., + exited: int = ..., + pty: bool = ..., + hide: tuple[Literal["stdout", "stderr"], ...] = ..., + ) -> None: ... + @property + def return_code(self) -> int: ... + def __nonzero__(self) -> bool: ... + def __bool__(self) -> bool: ... + @property + def ok(self) -> bool: ... + @property + def failed(self) -> bool: ... + def tail(self, stream: Literal["stderr", "stdout"], count: int = ...) -> str: ... + +class Promise(Result): + runner: Any + def __init__(self, runner) -> None: ... + def join(self): ... + def __enter__(self): ... + def __exit__(self, exc_type, exc_value, traceback) -> None: ... + +def normalize_hide(val, out_stream=..., err_stream=...): ... +def default_encoding() -> str: ... diff --git a/stubs/invoke/invoke/tasks.pyi b/stubs/invoke/invoke/tasks.pyi new file mode 100644 index 000000000..bcb46d7ff --- /dev/null +++ b/stubs/invoke/invoke/tasks.pyi @@ -0,0 +1,71 @@ +from typing import Any + +from .config import Config +from .context import Context + +NO_DEFAULT: object + +class Task: + body: Any + __doc__: str + __name__: str + __module__: Any + aliases: Any + is_default: bool + positional: Any + optional: Any + iterable: Any + incrementable: Any + auto_shortflags: Any + help: Any + pre: Any + post: Any + times_called: int + autoprint: Any + def __init__( + self, + body, + name=..., + aliases=..., + positional=..., + optional=..., + default: bool = ..., + auto_shortflags: bool = ..., + help=..., + pre=..., + post=..., + autoprint: bool = ..., + iterable=..., + incrementable=..., + ) -> None: ... + @property + def name(self): ... + def __eq__(self, other): ... + def __hash__(self): ... + def __call__(self, *args, **kwargs): ... + @property + def called(self): ... + def argspec(self, body): ... + def fill_implicit_positionals(self, positional): ... + def arg_opts(self, name, default, taken_names): ... + def get_arguments(self): ... + +def task(*args, **kwargs) -> Task: ... + +class Call: + task: Task + called_as: str | None + args: tuple[Any, ...] + kwargs: dict[str, Any] + def __init__( + self, task: Task, called_as: str | None = ..., args: tuple[Any, ...] | None = ..., kwargs: dict[str, Any] | None = ... + ) -> None: ... + def __getattr__(self, name: str) -> Any: ... + def __deepcopy__(self, memo: Any) -> Task: ... + def __eq__(self, other: Any) -> bool: ... + def make_context(self, config: Config) -> Context: ... + def clone_data(self): ... + # TODO use overload + def clone(self, into: type[Call] | None = ..., with_: dict[str, Any] | None = ...) -> Call: ... + +def call(task: Task, *args: Any, **kwargs: Any) -> Call: ... diff --git a/stubs/invoke/invoke/terminals.pyi b/stubs/invoke/invoke/terminals.pyi new file mode 100644 index 000000000..611954043 --- /dev/null +++ b/stubs/invoke/invoke/terminals.pyi @@ -0,0 +1,12 @@ +from contextlib import AbstractContextManager +from io import TextIOWrapper +from typing import Any + +WINDOWS: bool + +def pty_size() -> tuple[int, int]: ... +def stdin_is_foregrounded_tty(stream: Any) -> bool: ... +def cbreak_already_set(stream: TextIOWrapper) -> bool: ... +def character_buffered(stream: TextIOWrapper) -> AbstractContextManager[None]: ... +def ready_for_reading(input_: TextIOWrapper) -> bool: ... +def bytes_to_read(input_: TextIOWrapper) -> int: ... diff --git a/stubs/invoke/invoke/util.pyi b/stubs/invoke/invoke/util.pyi new file mode 100644 index 000000000..f99b77930 --- /dev/null +++ b/stubs/invoke/invoke/util.pyi @@ -0,0 +1,39 @@ +import threading +from contextlib import AbstractContextManager +from logging import Logger +from types import TracebackType +from typing import Any, Callable, Iterable, Mapping, NamedTuple + +LOG_FORMAT: str + +def enable_logging() -> None: ... + +log: Logger + +def task_name_sort_key(name: str) -> tuple[list[str], str]: ... +def cd(where: str) -> AbstractContextManager[None]: ... +def has_fileno(stream) -> bool: ... +def isatty(stream) -> bool: ... +def encode_output(string: str, encoding: str) -> str: ... +def helpline(obj: Callable[..., Any]) -> str | None: ... + +class ExceptionHandlingThread(threading.Thread): + def __init__( + self, + *, + group: None = ..., + target: Callable[..., Any] | None = ..., + name: str | None = ..., + args: Iterable[Any] = ..., + kwargs: Mapping[str, Any] | None = ..., + daemon: bool | None = ..., + ) -> None: ... + def exception(self) -> ExceptionWrapper | None: ... + @property + def is_dead(self) -> bool: ... + +class ExceptionWrapper(NamedTuple): + kwargs: Any + type: type[BaseException] + value: BaseException + traceback: TracebackType diff --git a/stubs/invoke/invoke/watchers.pyi b/stubs/invoke/invoke/watchers.pyi new file mode 100644 index 000000000..d1da58a97 --- /dev/null +++ b/stubs/invoke/invoke/watchers.pyi @@ -0,0 +1,20 @@ +import threading +from typing import Iterable + +class StreamWatcher(threading.local): + def submit(self, stream) -> Iterable[str]: ... + +class Responder(StreamWatcher): + pattern: str + response: str + index: int + def __init__(self, pattern: str, response: str) -> None: ... + def pattern_matches(self, stream: str, pattern: str, index_attr: str) -> Iterable[str]: ... + def submit(self, stream: str) -> Iterable[str]: ... + +class FailingResponder(Responder): + sentinel: str + failure_index: int + tried: bool + def __init__(self, pattern: str, response: str, sentinel: str) -> None: ... + def submit(self, stream: str) -> Iterable[str]: ...