diff --git a/src/molecule/dependency/ansible_galaxy/collections.py b/src/molecule/dependency/ansible_galaxy/collections.py index a0ac19b4f..7c99206da 100644 --- a/src/molecule/dependency/ansible_galaxy/collections.py +++ b/src/molecule/dependency/ansible_galaxy/collections.py @@ -5,21 +5,32 @@ import logging import os +from typing import TYPE_CHECKING + from molecule import util from molecule.dependency.ansible_galaxy.base import AnsibleGalaxyBase +if TYPE_CHECKING: + from molecule.types import DependencyOptions + + LOG = logging.getLogger(__name__) class Collections(AnsibleGalaxyBase): """Collection-specific Ansible Galaxy dependency handling.""" - FILTER_OPTS = ("role-file",) # type: ignore # noqa: PGH003 + FILTER_OPTS = ("role-file",) COMMANDS = ("collection", "install") @property - def default_options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 + def default_options(self) -> DependencyOptions: + """Default options for this dependency. + + Returns: + Default options for this dependency. + """ general = super().default_options specific = util.merge_dicts( general, @@ -34,9 +45,10 @@ def default_options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 return specific # noqa: RET504 @property - def default_env(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 - return super().default_env + def requirements_file(self) -> str: + """Path to requirements file. - @property - def requirements_file(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 + Returns: + Path to the requirements file for this dependency. + """ return self.options["requirements-file"] diff --git a/src/molecule/dependency/ansible_galaxy/roles.py b/src/molecule/dependency/ansible_galaxy/roles.py index 6a633213d..f7a6bed4e 100644 --- a/src/molecule/dependency/ansible_galaxy/roles.py +++ b/src/molecule/dependency/ansible_galaxy/roles.py @@ -5,21 +5,32 @@ import logging import os +from typing import TYPE_CHECKING + from molecule import util from molecule.dependency.ansible_galaxy.base import AnsibleGalaxyBase +if TYPE_CHECKING: + from molecule.types import DependencyOptions + + LOG = logging.getLogger(__name__) class Roles(AnsibleGalaxyBase): """Role-specific Ansible Galaxy dependency handling.""" - FILTER_OPTS = ("requirements-file",) # type: ignore # noqa: PGH003 + FILTER_OPTS = ("requirements-file",) COMMANDS = ("install",) @property - def default_options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 + def default_options(self) -> DependencyOptions: + """Default options for this dependency. + + Returns: + Default options for this dependency. + """ general = super().default_options specific = util.merge_dicts( general, @@ -33,5 +44,10 @@ def default_options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 return specific # noqa: RET504 @property - def requirements_file(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 + def requirements_file(self) -> str: + """Path to requirements file. + + Returns: + Path to the requirements file for this dependency. + """ return self.options["role-file"] diff --git a/src/molecule/types.py b/src/molecule/types.py index 0cf902809..cc7293da9 100644 --- a/src/molecule/types.py +++ b/src/molecule/types.py @@ -9,6 +9,13 @@ from typing import Any +DependencyOptions = TypedDict( + "DependencyOptions", + {"force": bool, "requirements-file": str, "role-file": str, "vvv": bool}, + total=False, +) + + class DependencyData(TypedDict, total=False): """Molecule dependency configuration. @@ -23,8 +30,8 @@ class DependencyData(TypedDict, total=False): name: str command: str | None enabled: bool - options: dict[str, Any] - env: dict[str, Any] + options: DependencyOptions + env: dict[str, str] class DriverOptions(TypedDict, total=False):