Skip to content

Commit 87d2683

Browse files
Add stubs for dockerfile-parse (#9305)
Co-authored-by: AlexWaygood <[email protected]>
1 parent ee69f60 commit 87d2683

File tree

7 files changed

+134
-0
lines changed

7 files changed

+134
-0
lines changed

pyrightconfig.stricter.json

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"stubs/commonmark",
3131
"stubs/cryptography",
3232
"stubs/dateparser",
33+
"stubs/dockerfile-parse",
3334
"stubs/docutils",
3435
"stubs/Flask-Migrate",
3536
"stubs/Flask-SQLAlchemy",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# These are re-exports which we consider an implementation detail
2+
dockerfile_parse.constants.version_info
3+
dockerfile_parse.parser.string_types
4+
dockerfile_parse.parser.DOCKERFILE_FILENAME
5+
dockerfile_parse.parser.COMMENT_INSTRUCTION
6+
dockerfile_parse.util.PY2

stubs/dockerfile-parse/METADATA.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version = "1.2.*"
2+
requires = ["types-six"]
3+
4+
[tool.stubtest]
5+
ignore_missing_stub = false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .parser import DockerfileParser as DockerfileParser
2+
3+
__version__: str
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from typing_extensions import Literal
2+
3+
PY2: Literal[False]
4+
DOCKERFILE_FILENAME: str
5+
COMMENT_INSTRUCTION: str
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from collections.abc import Mapping, Sequence
2+
from typing import IO, ClassVar
3+
from typing_extensions import TypedDict
4+
5+
from .util import Context
6+
7+
class KeyValues(dict[str, str]):
8+
parser_attr: ClassVar[str | None]
9+
parser: DockerfileParser
10+
def __init__(self, key_values: Mapping[str, str], parser: DockerfileParser) -> None: ...
11+
def __delitem__(self, key: str) -> None: ...
12+
def __setitem__(self, key: str, value: str) -> None: ...
13+
def __eq__(self, other: object) -> bool: ...
14+
def __hash__(self) -> int: ... # type: ignore[override]
15+
16+
class Labels(KeyValues): ...
17+
class Envs(KeyValues): ...
18+
class Args(KeyValues): ...
19+
20+
class _InstructionDict(TypedDict):
21+
instruction: str
22+
startline: int
23+
endline: int
24+
content: str
25+
value: str
26+
27+
class DockerfileParser:
28+
fileobj: IO[str]
29+
dockerfile_path: str
30+
cache_content: bool
31+
cached_content: str
32+
env_replace: bool
33+
parent_env: dict[str, str]
34+
build_args: dict[str, str]
35+
def __init__(
36+
self,
37+
path: str | None = ...,
38+
cache_content: bool = ...,
39+
env_replace: bool = ...,
40+
parent_env: dict[str, str] | None = ...,
41+
fileobj: IO[str] | None = ...,
42+
build_args: dict[str, str] | None = ...,
43+
) -> None: ...
44+
lines: list[str]
45+
content: str
46+
@property
47+
def structure(self) -> list[_InstructionDict]: ...
48+
@property
49+
def json(self) -> str: ...
50+
parent_images: Sequence[str]
51+
@property
52+
def is_multistage(self) -> bool: ...
53+
baseimage: str
54+
cmd: str
55+
labels: Mapping[str, str]
56+
envs: Mapping[str, str]
57+
args: Mapping[str, str]
58+
def add_lines(
59+
self, *lines: str, all_stages: bool | None = ..., at_start: bool | None = ..., skip_scratch: bool | None = ...
60+
) -> None: ...
61+
def add_lines_at(
62+
self, anchor: str | int | dict[str, int], *lines: str, replace: bool | None = ..., after: bool | None = ...
63+
) -> None: ...
64+
@property
65+
def context_structure(self) -> list[Context]: ...
66+
67+
def image_from(from_value: str) -> tuple[str | None, str | None]: ...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from collections.abc import Generator, Mapping, MutableMapping
2+
from io import StringIO
3+
from typing import ClassVar
4+
from typing_extensions import Literal, TypeAlias
5+
6+
def b2u(string: bytes | str) -> str: ...
7+
def u2b(string: str | bytes) -> bytes: ...
8+
9+
_Quotes: TypeAlias = Literal["'", '"']
10+
_ContextType: TypeAlias = Literal["ARG", "ENV", "LABEL"]
11+
12+
class WordSplitter:
13+
SQUOTE: ClassVar[_Quotes]
14+
DQUOTE: ClassVar[_Quotes]
15+
stream: StringIO
16+
args: Mapping[str, str] | None
17+
envs: Mapping[str, str] | None
18+
quotes: _Quotes | None
19+
escaped: bool
20+
def __init__(self, s: str, args: Mapping[str, str] | None = ..., envs: Mapping[str, str] | None = ...) -> None: ...
21+
def dequote(self) -> str: ...
22+
def split(self, maxsplit: int | None = ..., dequote: bool = ...) -> Generator[str | None, None, None]: ...
23+
24+
def extract_key_values(env_replace: bool, args: Mapping[str, str], envs: Mapping[str, str], instruction_value: str): ...
25+
def get_key_val_dictionary(
26+
instruction_value, env_replace: bool = ..., args: Mapping[str, str] | None = ..., envs: Mapping[str, str] | None = ...
27+
): ...
28+
29+
class Context:
30+
args: MutableMapping[str, str]
31+
envs: MutableMapping[str, str]
32+
labels: MutableMapping[str, str]
33+
line_args: Mapping[str, str]
34+
line_envs: Mapping[str, str]
35+
line_labels: Mapping[str, str]
36+
def __init__(
37+
self,
38+
args: MutableMapping[str, str] | None = ...,
39+
envs: MutableMapping[str, str] | None = ...,
40+
labels: MutableMapping[str, str] | None = ...,
41+
line_args: Mapping[str, str] | None = ...,
42+
line_envs: Mapping[str, str] | None = ...,
43+
line_labels: Mapping[str, str] | None = ...,
44+
) -> None: ...
45+
def set_line_value(self, context_type: _ContextType, value: Mapping[str, str]) -> None: ...
46+
def get_line_value(self, context_type: _ContextType) -> Mapping[str, str]: ...
47+
def get_values(self, context_type: _ContextType) -> Mapping[str, str]: ...

0 commit comments

Comments
 (0)