From e7fadad6eee863bae0ab89ddb203686a187847ce Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Fri, 6 Dec 2024 19:43:21 +0300 Subject: [PATCH] Add stubs for "click-web" package --- pyrightconfig.stricter.json | 1 + stubs/click-web/METADATA.toml | 3 + stubs/click-web/click_web/__init__.pyi | 16 ++++ stubs/click-web/click_web/exceptions.pyi | 2 + .../click_web/resources/cmd_exec.pyi | 79 +++++++++++++++++++ .../click_web/resources/cmd_form.pyi | 6 ++ stubs/click-web/click_web/resources/index.pyi | 6 ++ .../click_web/resources/input_fields.pyi | 49 ++++++++++++ stubs/click-web/click_web/web_click_types.pyi | 18 +++++ 9 files changed, 180 insertions(+) create mode 100644 stubs/click-web/METADATA.toml create mode 100644 stubs/click-web/click_web/__init__.pyi create mode 100644 stubs/click-web/click_web/exceptions.pyi create mode 100644 stubs/click-web/click_web/resources/cmd_exec.pyi create mode 100644 stubs/click-web/click_web/resources/cmd_form.pyi create mode 100644 stubs/click-web/click_web/resources/index.pyi create mode 100644 stubs/click-web/click_web/resources/input_fields.pyi create mode 100644 stubs/click-web/click_web/web_click_types.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index be0163441020..7a2fda7dab78 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -38,6 +38,7 @@ "stubs/caldav", "stubs/cffi", "stubs/click-default-group", + "stubs/click-web", "stubs/commonmark", "stubs/corus", "stubs/dateparser", diff --git a/stubs/click-web/METADATA.toml b/stubs/click-web/METADATA.toml new file mode 100644 index 000000000000..1f42748d42a5 --- /dev/null +++ b/stubs/click-web/METADATA.toml @@ -0,0 +1,3 @@ +version = "0.8.*" +requires = ["click>=8.0.0", "Flask>=2.3.2"] +upstream_repository = "https://github.com/fredrik-corneliusson/click-web" diff --git a/stubs/click-web/click_web/__init__.pyi b/stubs/click-web/click_web/__init__.pyi new file mode 100644 index 000000000000..a6f95dc1dae0 --- /dev/null +++ b/stubs/click-web/click_web/__init__.pyi @@ -0,0 +1,16 @@ +import logging +import types + +import click +import flask +from _typeshed import Incomplete + +# This should be jinja2.Environment, but it does not have stubs and forbidden for requires in METADATA.toml +jinja_env: Incomplete +script_file: str | None +click_root_cmd: str | None +OUTPUT_FOLDER: str +_flask_app: flask.Flask | None +logger: logging.Logger | None + +def create_click_web_app(module: types.ModuleType, command: click.BaseCommand, root: str = "/") -> flask.Flask: ... diff --git a/stubs/click-web/click_web/exceptions.pyi b/stubs/click-web/click_web/exceptions.pyi new file mode 100644 index 000000000000..172a2026a871 --- /dev/null +++ b/stubs/click-web/click_web/exceptions.pyi @@ -0,0 +1,2 @@ +class ClickWebException(Exception): ... +class CommandNotFound(ClickWebException): ... diff --git a/stubs/click-web/click_web/resources/cmd_exec.pyi b/stubs/click-web/click_web/resources/cmd_exec.pyi new file mode 100644 index 000000000000..1c616c6782b6 --- /dev/null +++ b/stubs/click-web/click_web/resources/cmd_exec.pyi @@ -0,0 +1,79 @@ +import logging + +from flask import Response + +from .input_fields import FieldId + +logger: logging.Logger | None + +HTML_HEAD: str +HTML_TAIL: str + +class Executor: + RAW_CMD_PATH: str + + def __init__(self) -> None: ... + def exec(self, command_path: str) -> Response: ... + def _exec_raw(self, command: list[str]) -> Response: ... # undocumented + def _exec_html(self, command_path: str) -> Response: ... # undocumented + def _run_script_and_generate_stream(self) -> None: ... # undocumented + def _create_cmd_header(self, commands: list[CmdPart]) -> str: ... # undocumented + def _create_result_footer(self) -> str: ... # undocumented + +def _get_download_link(field_info: FieldFileInfo) -> str: ... # undocumented + +class CommandLineRaw: + def __init__(self, script_file_path: str, command: str) -> None: ... + def append(self, part: str, secret: bool = False) -> None: ... + def get_commandline(self, obfuscate: bool = False) -> list[str]: ... + def get_download_field_infos(self) -> list[FieldInfo]: ... + def after_script_executed(self) -> None: ... + +class CommandLineForm: + def __init__(self, script_file_path: str, commands: list[str]) -> None: ... + def append(self, part: str, secret: bool = False) -> None: ... + def get_commandline(self, obfuscate: bool = False) -> list[str]: ... + def get_download_field_infos(self) -> list[FieldInfo]: ... + def after_script_executed(self) -> None: ... + +def _get_python_interpreter() -> str: ... + +class CmdPart: + def __init__(self, part: str, secret: bool = False) -> None: ... + +class FormToCommandLineBuilder: + def __init__(self, command_line: CommandLineForm) -> None: ... + def add_command_args(self, command_index: int) -> None: ... + @staticmethod + def _is_option(cmd_option: str) -> bool: ... + def _process_option(self, field_info: FieldInfo) -> None: ... + +class FieldInfo: + @staticmethod + def factory(key: str) -> FieldInfo: ... + def __init__(self, param: FieldId) -> None: ... + def before_script_execute(self) -> None: ... + def after_script_executed(self) -> None: ... + def __lt__(self, other: object) -> bool: ... + def __eq__(self, other: object) -> bool: ... + +class FieldFileInfo(FieldInfo): + def __init__(self, fimeta: FieldId) -> None: ... + def before_script_execute(self) -> None: ... + @classmethod + def temp_dir(cls) -> str: ... + def save(self) -> None: ... + +class FieldOutFileInfo(FieldFileInfo): + def __init__(self, fimeta: FieldId) -> None: ... + def save(self) -> None: ... + +class FieldPathInfo(FieldFileInfo): + def save(self) -> None: ... + def after_script_executed(self) -> None: ... + +class FieldPathOutInfo(FieldOutFileInfo): + def save(self) -> None: ... + def after_script_executed(self) -> None: ... + +def zip_folder(folder_path: str, out_folder: str, out_prefix: str) -> str: ... diff --git a/stubs/click-web/click_web/resources/cmd_form.pyi b/stubs/click-web/click_web/resources/cmd_form.pyi new file mode 100644 index 000000000000..fff80bd290ee --- /dev/null +++ b/stubs/click-web/click_web/resources/cmd_form.pyi @@ -0,0 +1,6 @@ +import click + +def get_form_for(command_path: str) -> str: ... +def _get_commands_by_path(command_path: str) -> list[tuple[click.Context, click.Command]]: ... +def _generate_form_data(ctx_and_commands: list[tuple[click.Context, click.Command]]): ... +def _process_help(help_text: bool) -> str: ... diff --git a/stubs/click-web/click_web/resources/index.pyi b/stubs/click-web/click_web/resources/index.pyi new file mode 100644 index 000000000000..c932a5a7e7b0 --- /dev/null +++ b/stubs/click-web/click_web/resources/index.pyi @@ -0,0 +1,6 @@ +from typing import Any + +import click + +def index() -> str: ... +def _click_to_tree(ctx: click.Context, node: click.Command, ancestors: list[click.Command] | None = None) -> dict[str, Any]: ... diff --git a/stubs/click-web/click_web/resources/input_fields.pyi b/stubs/click-web/click_web/resources/input_fields.pyi new file mode 100644 index 000000000000..65b3018982eb --- /dev/null +++ b/stubs/click-web/click_web/resources/input_fields.pyi @@ -0,0 +1,49 @@ +from typing import Any + +import click + +class FieldId: + SEPARATOR: str + + def __init__( + self, + command_index: int, + param_index: int, + param_type: str, + click_type: str, + nargs: int, + form_type: str, + name: str, + key: str | None = None, + ): ... + @classmethod + def from_string(cls, field_info_as_string: str) -> FieldId: ... + +class NotSupported(ValueError): ... + +class BaseInput: + param_type_cls: type | None + def __init__(self, ctx: click.Context, param: click.Parameter, command_index: int, param_index: int) -> None: ... + def is_supported(self) -> bool: ... + @property + def fields(self) -> dict[str, Any]: ... + @property + def type_attrs(self) -> dict[str, Any]: ... + def _to_cmd_line_name(self, name: str) -> str: ... + def _build_name(self, name: str): ... + +class ChoiceInput(BaseInput): ... +class FlagInput(BaseInput): ... +class IntInput(BaseInput): ... +class FloatInput(BaseInput): ... +class FolderInput(BaseInput): ... +class FileInput(BaseInput): ... +class EmailInput(BaseInput): ... +class PasswordInput(BaseInput): ... +class TextAreaInput(BaseInput): ... +class DefaultInput(BaseInput): ... + +INPUT_TYPES: list[type] +_DEFAULT_INPUT: list[type] + +def get_input_field(ctx: click.Context, param: click.Parameter, command_index, param_index) -> dict[str, Any]: ... diff --git a/stubs/click-web/click_web/web_click_types.pyi b/stubs/click-web/click_web/web_click_types.pyi new file mode 100644 index 000000000000..1546f7e7d7d1 --- /dev/null +++ b/stubs/click-web/click_web/web_click_types.pyi @@ -0,0 +1,18 @@ +import re +import typing as t + +import click + +class EmailParamType(click.ParamType): + EMAIL_REGEX: re.Pattern[str] + def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ... + +class PasswordParamType(click.ParamType): + def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ... + +class TextAreaParamType(click.ParamType): + def convert(self, value: t.Any, param: click.Parameter | None, ctx: click.Context | None) -> t.Any: ... + +EMAIL_TYPE: EmailParamType +PASSWORD_TYPE: PasswordParamType +TEXTAREA_TYPE: TextAreaParamType