Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stubs for dockerfile-parse #9305

Merged
merged 7 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]: ...