Skip to content

Commit

Permalink
Add stubs for dockerfile-parse (#9305)
Browse files Browse the repository at this point in the history
Co-authored-by: AlexWaygood <[email protected]>
  • Loading branch information
pyhedgehog and AlexWaygood authored Nov 30, 2022
1 parent ee69f60 commit 87d2683
Show file tree
Hide file tree
Showing 7 changed files with 134 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 @@ -30,6 +30,7 @@
"stubs/commonmark",
"stubs/cryptography",
"stubs/dateparser",
"stubs/dockerfile-parse",
"stubs/docutils",
"stubs/Flask-Migrate",
"stubs/Flask-SQLAlchemy",
Expand Down
6 changes: 6 additions & 0 deletions stubs/dockerfile-parse/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions stubs/dockerfile-parse/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version = "1.2.*"
requires = ["types-six"]

[tool.stubtest]
ignore_missing_stub = false
3 changes: 3 additions & 0 deletions stubs/dockerfile-parse/dockerfile_parse/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .parser import DockerfileParser as DockerfileParser

__version__: str
5 changes: 5 additions & 0 deletions stubs/dockerfile-parse/dockerfile_parse/constants.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing_extensions import Literal

PY2: Literal[False]
DOCKERFILE_FILENAME: str
COMMENT_INSTRUCTION: str
67 changes: 67 additions & 0 deletions stubs/dockerfile-parse/dockerfile_parse/parser.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...
47 changes: 47 additions & 0 deletions stubs/dockerfile-parse/dockerfile_parse/util.pyi
Original file line number Diff line number Diff line change
@@ -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]: ...

0 comments on commit 87d2683

Please sign in to comment.