Skip to content

Commit

Permalink
Add docstrings and type hints to ansiblegalaxy suptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Nov 22, 2024
1 parent 9a94964 commit 07ea9a8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
24 changes: 18 additions & 6 deletions src/molecule/dependency/ansible_galaxy/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]
22 changes: 19 additions & 3 deletions src/molecule/dependency/ansible_galaxy/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]
11 changes: 9 additions & 2 deletions src/molecule/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
Expand Down

0 comments on commit 07ea9a8

Please sign in to comment.