Skip to content

Commit

Permalink
Add stubs for "click-web" package
Browse files Browse the repository at this point in the history
  • Loading branch information
pyhedgehog committed Dec 8, 2024
1 parent 98f070a commit b5fa39d
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 0 deletions.
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"stubs/caldav",
"stubs/cffi",
"stubs/click-default-group",
"stubs/click-web",
"stubs/commonmark",
"stubs/corus",
"stubs/dateparser",
Expand Down
3 changes: 3 additions & 0 deletions stubs/click-web/METADATA.toml
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 17 additions & 0 deletions stubs/click-web/click_web/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import logging
import types
import typing as t

import click
import flask

# import jinja2

jinja_env: t.Any # jinja2.Environment
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: ...
2 changes: 2 additions & 0 deletions stubs/click-web/click_web/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ClickWebException(Exception): ...
class CommandNotFound(ClickWebException): ...
79 changes: 79 additions & 0 deletions stubs/click-web/click_web/resources/cmd_exec.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
6 changes: 6 additions & 0 deletions stubs/click-web/click_web/resources/cmd_form.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
6 changes: 6 additions & 0 deletions stubs/click-web/click_web/resources/index.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
49 changes: 49 additions & 0 deletions stubs/click-web/click_web/resources/input_fields.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
18 changes: 18 additions & 0 deletions stubs/click-web/click_web/web_click_types.pyi
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b5fa39d

Please sign in to comment.