diff --git a/stubs/whatthepatch/METADATA.toml b/stubs/whatthepatch/METADATA.toml new file mode 100644 index 000000000000..f3e83f9c456b --- /dev/null +++ b/stubs/whatthepatch/METADATA.toml @@ -0,0 +1 @@ +version = "1.0.*" diff --git a/stubs/whatthepatch/whatthepatch/__init__.pyi b/stubs/whatthepatch/whatthepatch/__init__.pyi new file mode 100644 index 000000000000..600e4526291c --- /dev/null +++ b/stubs/whatthepatch/whatthepatch/__init__.pyi @@ -0,0 +1,2 @@ +from .apply import apply_diff as apply_diff +from .patch import parse_patch as parse_patch diff --git a/stubs/whatthepatch/whatthepatch/apply.pyi b/stubs/whatthepatch/whatthepatch/apply.pyi new file mode 100644 index 000000000000..c927a4cef0f4 --- /dev/null +++ b/stubs/whatthepatch/whatthepatch/apply.pyi @@ -0,0 +1,8 @@ +from collections.abc import Iterable + +from . import patch as patch +from .exceptions import HunkApplyException as HunkApplyException, SubprocessException as SubprocessException +from .snippets import remove as remove, which as which + +def apply_patch(diffs: patch.diffobj | Iterable[patch.diffobj]) -> None: ... +def apply_diff(diff: patch.diffobj, text: str | Iterable[str], reverse: bool = ..., use_patch: bool = ...) -> list[str]: ... diff --git a/stubs/whatthepatch/whatthepatch/exceptions.pyi b/stubs/whatthepatch/whatthepatch/exceptions.pyi new file mode 100644 index 000000000000..918275ea28ef --- /dev/null +++ b/stubs/whatthepatch/whatthepatch/exceptions.pyi @@ -0,0 +1,14 @@ +class WhatThePatchException(Exception): ... + +class HunkException(WhatThePatchException): + hunk: int | None + def __init__(self, msg: str, hunk: int | None = ...) -> None: ... + +class ApplyException(WhatThePatchException): ... + +class SubprocessException(ApplyException): + code: int + def __init__(self, msg: str, code: int) -> None: ... + +class HunkApplyException(HunkException, ApplyException, ValueError): ... +class ParseException(HunkException, ValueError): ... diff --git a/stubs/whatthepatch/whatthepatch/patch.pyi b/stubs/whatthepatch/whatthepatch/patch.pyi new file mode 100644 index 000000000000..dcabfa37d359 --- /dev/null +++ b/stubs/whatthepatch/whatthepatch/patch.pyi @@ -0,0 +1,77 @@ +from collections.abc import Iterable, Iterator +from typing import NamedTuple, Pattern + +from . import exceptions as exceptions +from .snippets import findall_regex as findall_regex, split_by_regex as split_by_regex + +class header(NamedTuple): + index_path: str | None + old_path: str + old_version: str | None + new_path: str + new_version: str | None + +class diffobj(NamedTuple): + header: header | None + changes: list[Change] | None + text: str + +class Change(NamedTuple): + old: int | None + new: int | None + line: int | None + hunk: int + +file_timestamp_str: str +diffcmd_header: Pattern[str] +unified_header_index: Pattern[str] +unified_header_old_line: Pattern[str] +unified_header_new_line: Pattern[str] +unified_hunk_start: Pattern[str] +unified_change: Pattern[str] +context_header_old_line: Pattern[str] +context_header_new_line: Pattern[str] +context_hunk_start: Pattern[str] +context_hunk_old: Pattern[str] +context_hunk_new: Pattern[str] +context_change: Pattern[str] +ed_hunk_start: Pattern[str] +ed_hunk_end: Pattern[str] +rcs_ed_hunk_start: Pattern[str] +default_hunk_start: Pattern[str] +default_hunk_mid: Pattern[str] +default_change: Pattern[str] +git_diffcmd_header: Pattern[str] +git_header_index: Pattern[str] +git_header_old_line: Pattern[str] +git_header_new_line: Pattern[str] +git_header_file_mode: Pattern[str] +git_header_binary_file: Pattern[str] +bzr_header_index: Pattern[str] +bzr_header_old_line: Pattern[str] +bzr_header_new_line: Pattern[str] +svn_header_index: Pattern[str] +svn_header_timestamp_version: Pattern[str] +svn_header_timestamp: Pattern[str] +cvs_header_index: Pattern[str] +cvs_header_rcs: Pattern[str] +cvs_header_timestamp: Pattern[str] +cvs_header_timestamp_colon: Pattern[str] +old_cvs_diffcmd_header: Pattern[str] + +def parse_patch(text: str | Iterable[str]) -> Iterator[diffobj]: ... +def parse_header(text: str | Iterable[str]) -> header | None: ... +def parse_scm_header(text: str | Iterable[str]) -> header | None: ... +def parse_diff_header(text: str | Iterable[str]) -> header | None: ... +def parse_diff(text: str | Iterable[str]) -> list[Change] | None: ... +def parse_git_header(text: str | Iterable[str]) -> header | None: ... +def parse_svn_header(text: str | Iterable[str]) -> header | None: ... +def parse_cvs_header(text: str | Iterable[str]) -> header | None: ... +def parse_diffcmd_header(text: str | Iterable[str]) -> header | None: ... +def parse_unified_header(text: str | Iterable[str]) -> header | None: ... +def parse_context_header(text: str | Iterable[str]) -> header | None: ... +def parse_default_diff(text: str | Iterable[str]) -> list[Change] | None: ... +def parse_unified_diff(text: str | Iterable[str]) -> list[Change] | None: ... +def parse_context_diff(text: str | Iterable[str]) -> list[Change] | None: ... +def parse_ed_diff(text: str | Iterable[str]) -> list[Change] | None: ... +def parse_rcs_ed_diff(text: str | Iterable[str]) -> list[Change] | None: ... diff --git a/stubs/whatthepatch/whatthepatch/snippets.pyi b/stubs/whatthepatch/whatthepatch/snippets.pyi new file mode 100644 index 000000000000..3d867ddb3b9d --- /dev/null +++ b/stubs/whatthepatch/whatthepatch/snippets.pyi @@ -0,0 +1,7 @@ +from collections.abc import Sequence +from typing import Pattern + +def remove(path: str) -> None: ... +def findall_regex(items: Sequence[str], regex: Pattern[str]) -> list[int]: ... +def split_by_regex(items: Sequence[str], regex: Pattern[str]) -> list[Sequence[str]]: ... +def which(program: str) -> str | None: ...