From 87d2683ef974ef6d6d8b38313f73e9ef0acad06c Mon Sep 17 00:00:00 2001 From: PyHedgehog Date: Thu, 1 Dec 2022 01:27:40 +0300 Subject: [PATCH] Add stubs for dockerfile-parse (#9305) Co-authored-by: AlexWaygood --- pyrightconfig.stricter.json | 1 + .../@tests/stubtest_allowlist.txt | 6 ++ stubs/dockerfile-parse/METADATA.toml | 5 ++ .../dockerfile_parse/__init__.pyi | 3 + .../dockerfile_parse/constants.pyi | 5 ++ .../dockerfile_parse/parser.pyi | 67 +++++++++++++++++++ .../dockerfile_parse/util.pyi | 47 +++++++++++++ 7 files changed, 134 insertions(+) create mode 100644 stubs/dockerfile-parse/@tests/stubtest_allowlist.txt create mode 100644 stubs/dockerfile-parse/METADATA.toml create mode 100644 stubs/dockerfile-parse/dockerfile_parse/__init__.pyi create mode 100644 stubs/dockerfile-parse/dockerfile_parse/constants.pyi create mode 100644 stubs/dockerfile-parse/dockerfile_parse/parser.pyi create mode 100644 stubs/dockerfile-parse/dockerfile_parse/util.pyi diff --git a/pyrightconfig.stricter.json b/pyrightconfig.stricter.json index 06d11f1a33b9..29ea28e9150b 100644 --- a/pyrightconfig.stricter.json +++ b/pyrightconfig.stricter.json @@ -30,6 +30,7 @@ "stubs/commonmark", "stubs/cryptography", "stubs/dateparser", + "stubs/dockerfile-parse", "stubs/docutils", "stubs/Flask-Migrate", "stubs/Flask-SQLAlchemy", diff --git a/stubs/dockerfile-parse/@tests/stubtest_allowlist.txt b/stubs/dockerfile-parse/@tests/stubtest_allowlist.txt new file mode 100644 index 000000000000..0d91baed6589 --- /dev/null +++ b/stubs/dockerfile-parse/@tests/stubtest_allowlist.txt @@ -0,0 +1,6 @@ +# These are re-exports which we consider an implementation detail +dockerfile_parse.constants.version_info +dockerfile_parse.parser.string_types +dockerfile_parse.parser.DOCKERFILE_FILENAME +dockerfile_parse.parser.COMMENT_INSTRUCTION +dockerfile_parse.util.PY2 diff --git a/stubs/dockerfile-parse/METADATA.toml b/stubs/dockerfile-parse/METADATA.toml new file mode 100644 index 000000000000..beccf3359d97 --- /dev/null +++ b/stubs/dockerfile-parse/METADATA.toml @@ -0,0 +1,5 @@ +version = "1.2.*" +requires = ["types-six"] + +[tool.stubtest] +ignore_missing_stub = false diff --git a/stubs/dockerfile-parse/dockerfile_parse/__init__.pyi b/stubs/dockerfile-parse/dockerfile_parse/__init__.pyi new file mode 100644 index 000000000000..eeb43a016a3a --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/__init__.pyi @@ -0,0 +1,3 @@ +from .parser import DockerfileParser as DockerfileParser + +__version__: str diff --git a/stubs/dockerfile-parse/dockerfile_parse/constants.pyi b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi new file mode 100644 index 000000000000..31d0e73bc015 --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/constants.pyi @@ -0,0 +1,5 @@ +from typing_extensions import Literal + +PY2: Literal[False] +DOCKERFILE_FILENAME: str +COMMENT_INSTRUCTION: str diff --git a/stubs/dockerfile-parse/dockerfile_parse/parser.pyi b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi new file mode 100644 index 000000000000..73073c521411 --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/parser.pyi @@ -0,0 +1,67 @@ +from collections.abc import Mapping, Sequence +from typing import IO, ClassVar +from typing_extensions import TypedDict + +from .util import Context + +class KeyValues(dict[str, str]): + parser_attr: ClassVar[str | None] + parser: DockerfileParser + def __init__(self, key_values: Mapping[str, str], parser: DockerfileParser) -> None: ... + def __delitem__(self, key: str) -> None: ... + def __setitem__(self, key: str, value: str) -> None: ... + def __eq__(self, other: object) -> bool: ... + def __hash__(self) -> int: ... # type: ignore[override] + +class Labels(KeyValues): ... +class Envs(KeyValues): ... +class Args(KeyValues): ... + +class _InstructionDict(TypedDict): + instruction: str + startline: int + endline: int + content: str + value: str + +class DockerfileParser: + fileobj: IO[str] + dockerfile_path: str + cache_content: bool + cached_content: str + env_replace: bool + parent_env: dict[str, str] + build_args: dict[str, str] + def __init__( + self, + path: str | None = ..., + cache_content: bool = ..., + env_replace: bool = ..., + parent_env: dict[str, str] | None = ..., + fileobj: IO[str] | None = ..., + build_args: dict[str, str] | None = ..., + ) -> None: ... + lines: list[str] + content: str + @property + def structure(self) -> list[_InstructionDict]: ... + @property + def json(self) -> str: ... + parent_images: Sequence[str] + @property + def is_multistage(self) -> bool: ... + baseimage: str + cmd: str + labels: Mapping[str, str] + envs: Mapping[str, str] + args: Mapping[str, str] + def add_lines( + self, *lines: str, all_stages: bool | None = ..., at_start: bool | None = ..., skip_scratch: bool | None = ... + ) -> None: ... + def add_lines_at( + self, anchor: str | int | dict[str, int], *lines: str, replace: bool | None = ..., after: bool | None = ... + ) -> None: ... + @property + def context_structure(self) -> list[Context]: ... + +def image_from(from_value: str) -> tuple[str | None, str | None]: ... diff --git a/stubs/dockerfile-parse/dockerfile_parse/util.pyi b/stubs/dockerfile-parse/dockerfile_parse/util.pyi new file mode 100644 index 000000000000..a2304e96ae7b --- /dev/null +++ b/stubs/dockerfile-parse/dockerfile_parse/util.pyi @@ -0,0 +1,47 @@ +from collections.abc import Generator, Mapping, MutableMapping +from io import StringIO +from typing import ClassVar +from typing_extensions import Literal, TypeAlias + +def b2u(string: bytes | str) -> str: ... +def u2b(string: str | bytes) -> bytes: ... + +_Quotes: TypeAlias = Literal["'", '"'] +_ContextType: TypeAlias = Literal["ARG", "ENV", "LABEL"] + +class WordSplitter: + SQUOTE: ClassVar[_Quotes] + DQUOTE: ClassVar[_Quotes] + stream: StringIO + args: Mapping[str, str] | None + envs: Mapping[str, str] | None + quotes: _Quotes | None + escaped: bool + def __init__(self, s: str, args: Mapping[str, str] | None = ..., envs: Mapping[str, str] | None = ...) -> None: ... + def dequote(self) -> str: ... + def split(self, maxsplit: int | None = ..., dequote: bool = ...) -> Generator[str | None, None, None]: ... + +def extract_key_values(env_replace: bool, args: Mapping[str, str], envs: Mapping[str, str], instruction_value: str): ... +def get_key_val_dictionary( + instruction_value, env_replace: bool = ..., args: Mapping[str, str] | None = ..., envs: Mapping[str, str] | None = ... +): ... + +class Context: + args: MutableMapping[str, str] + envs: MutableMapping[str, str] + labels: MutableMapping[str, str] + line_args: Mapping[str, str] + line_envs: Mapping[str, str] + line_labels: Mapping[str, str] + def __init__( + self, + args: MutableMapping[str, str] | None = ..., + envs: MutableMapping[str, str] | None = ..., + labels: MutableMapping[str, str] | None = ..., + line_args: Mapping[str, str] | None = ..., + line_envs: Mapping[str, str] | None = ..., + line_labels: Mapping[str, str] | None = ..., + ) -> None: ... + def set_line_value(self, context_type: _ContextType, value: Mapping[str, str]) -> None: ... + def get_line_value(self, context_type: _ContextType) -> Mapping[str, str]: ... + def get_values(self, context_type: _ContextType) -> Mapping[str, str]: ...