diff --git a/.config/pydoclint-baseline.txt b/.config/pydoclint-baseline.txt index 7af602d2c..2e9e243ec 100644 --- a/.config/pydoclint-baseline.txt +++ b/.config/pydoclint-baseline.txt @@ -1,15 +1,3 @@ -src/molecule/dependency/ansible_galaxy/base.py - DOC601: Class `AnsibleGalaxyBase`: Class docstring contains fewer class attributes than actual class attributes. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.) - DOC603: Class `AnsibleGalaxyBase`: Class docstring attributes are different from actual class attributes. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Attributes in the class definition but not in the docstring: [__metaclass__: ]. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.) - DOC101: Method `AnsibleGalaxyBase.__init__`: Docstring contains fewer arguments than in function signature. - DOC106: Method `AnsibleGalaxyBase.__init__`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature - DOC107: Method `AnsibleGalaxyBase.__init__`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints - DOC103: Method `AnsibleGalaxyBase.__init__`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [config: ]. - DOC101: Method `AnsibleGalaxyBase.filter_options`: Docstring contains fewer arguments than in function signature. - DOC106: Method `AnsibleGalaxyBase.filter_options`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature - DOC107: Method `AnsibleGalaxyBase.filter_options`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints - DOC103: Method `AnsibleGalaxyBase.filter_options`: Docstring arguments are different from function arguments. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Arguments in the function signature but not in the docstring: [keys: , opts: ]. --------------------- src/molecule/dependency/ansible_galaxy/collections.py DOC601: Class `Collections`: Class docstring contains fewer class attributes than actual class attributes. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.) DOC603: Class `Collections`: Class docstring attributes are different from actual class attributes. (Or could be other formatting issues: https://jsh9.github.io/pydoclint/violation_codes.html#notes-on-doc103 ). Attributes in the class definition but not in the docstring: [COMMANDS: , FILTER_OPTS: ]. (Please read https://jsh9.github.io/pydoclint/checking_class_attributes.html on how to correctly document class attributes.) diff --git a/src/molecule/dependency/ansible_galaxy/__init__.py b/src/molecule/dependency/ansible_galaxy/__init__.py index b39d31ad9..b70f016b5 100644 --- a/src/molecule/dependency/ansible_galaxy/__init__.py +++ b/src/molecule/dependency/ansible_galaxy/__init__.py @@ -131,7 +131,7 @@ def default_env(self) -> dict[str, str]: return env @property - def default_options(self) -> dict[str, str]: + def default_options(self) -> dict[str, str | bool]: """Default options across all invokers. Returns: diff --git a/src/molecule/dependency/ansible_galaxy/base.py b/src/molecule/dependency/ansible_galaxy/base.py index 02247f0d7..9cb4fcb62 100644 --- a/src/molecule/dependency/ansible_galaxy/base.py +++ b/src/molecule/dependency/ansible_galaxy/base.py @@ -25,10 +25,16 @@ import logging import os +from typing import TYPE_CHECKING + from molecule import util from molecule.dependency import base +if TYPE_CHECKING: + from molecule.config import Config + + LOG = logging.getLogger(__name__) @@ -39,12 +45,14 @@ class AnsibleGalaxyBase(base.Base): FILTER_OPTS: Keys to remove from the dictionary returned by options(). """ - __metaclass__ = abc.ABCMeta - FILTER_OPTS = () - def __init__(self, config) -> None: # type: ignore[no-untyped-def] # noqa: ANN001 - """Construct AnsibleGalaxy.""" + def __init__(self, config: Config) -> None: + """Construct AnsibleGalaxy. + + Args: + config: Molecule Config instance. + """ super().__init__(config) self._sh_command = None @@ -52,12 +60,21 @@ def __init__(self, config) -> None: # type: ignore[no-untyped-def] # noqa: ANN @property @abc.abstractmethod - def requirements_file(self): # type: ignore[no-untyped-def] # cover # noqa: ANN201, D102 - pass + def requirements_file(self) -> str: # cover + """Path to requirements file. + + Returns: + Path to the requirements file for this dependency. + """ @property - def default_options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 - d = { + def default_options(self) -> dict[str, str | bool]: + """Default options for this dependency. + + Returns: + Default options for this dependency. + """ + d: dict[str, str | bool] = { "force": False, } if self._config.debug: @@ -65,13 +82,21 @@ def default_options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 return d - def filter_options(self, opts, keys): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201 + def filter_options( + self, + opts: dict[str, str | bool], + keys: tuple[str, ...], + ) -> dict[str, str | bool]: """Filter certain keys from a dictionary. Removes all the values of ``keys`` from the dictionary ``opts``, if they are present. Returns the resulting dictionary. Does not modify the existing one. + Args: + opts: Options dictionary. + keys: Key names to exclude from opts. + Returns: A copy of ``opts`` without the value of keys """ @@ -84,7 +109,12 @@ def filter_options(self, opts, keys): # type: ignore[no-untyped-def] # noqa: A # NOTE(retr0h): Override the base classes' options() to handle # ``ansible-galaxy`` one-off. @property - def options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 + def options(self) -> dict[str, str | bool]: + """Computed options for this dependency. + + Returns: + Merged and filtered options for this dependency. + """ o = self._config.config["dependency"]["options"] # NOTE(retr0h): Remove verbose options added by the user while in # debug. @@ -92,13 +122,19 @@ def options(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 o = util.filter_verbose_permutation(o) o = util.merge_dicts(self.default_options, o) - return self.filter_options(o, self.FILTER_OPTS) # type: ignore[no-untyped-call] + return self.filter_options(o, self.FILTER_OPTS) @property - def default_env(self): # type: ignore[no-untyped-def] # noqa: ANN201, D102 - return util.merge_dicts(os.environ, self._config.env) + def default_env(self) -> dict[str, str]: + """Default environment variables for this dependency. - def bake(self): # type: ignore[no-untyped-def] # noqa: ANN201 + Returns: + Default environment variables for this dependency. + """ + env = dict(os.environ) + return util.merge_dicts(env, self._config.env) # type: ignore[type-var] + + def bake(self) -> None: """Bake an ``ansible-galaxy`` command so it's ready to execute and returns None.""" options = self.options verbose_flag = util.verbose_flag(options) @@ -110,26 +146,31 @@ def bake(self): # type: ignore[no-untyped-def] # noqa: ANN201 *verbose_flag, ] - def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002, D102 + def execute(self, action_args: list[str] | None = None) -> None: # noqa: ARG002 + """Execute dependency. + + Args: + action_args: Arguments for this dependency. Unused. + """ if not self.enabled: msg = "Skipping, dependency is disabled." LOG.warning(msg) return - super().execute() # type: ignore[no-untyped-call] + super().execute() - if not self._has_requirements_file(): # type: ignore[no-untyped-call] + if not self._has_requirements_file(): msg = "Skipping, missing the requirements file." LOG.warning(msg) return if self._sh_command is None: - self.bake() # type: ignore[no-untyped-call] + self.bake() - self._setup() # type: ignore[no-untyped-call] - self.execute_with_retries() # type: ignore[no-untyped-call] + self._setup() + self.execute_with_retries() - def _setup(self): # type: ignore[no-untyped-def] # noqa: ANN202 + def _setup(self) -> None: """Prepare the system for using ``ansible-galaxy`` and returns None.""" - def _has_requirements_file(self): # type: ignore[no-untyped-def] # noqa: ANN202 + def _has_requirements_file(self) -> bool: return os.path.isfile(self.requirements_file) # noqa: PTH113 diff --git a/src/molecule/dependency/base.py b/src/molecule/dependency/base.py index 99027969b..e8f7069be 100644 --- a/src/molecule/dependency/base.py +++ b/src/molecule/dependency/base.py @@ -58,7 +58,7 @@ def __init__(self, config: Config) -> None: config: An instance of a Molecule config. """ self._config = config - self._sh_command: str | None = None + self._sh_command: str | list[str] | None = None def execute_with_retries(self) -> None: """Run dependency downloads with retry and timed back-off.""" @@ -107,7 +107,7 @@ def execute( @property @abc.abstractmethod - def default_options(self) -> dict[str, str]: # pragma: no cover + def default_options(self) -> dict[str, str | bool]: # pragma: no cover """Get default CLI arguments provided to ``cmd``. Returns: @@ -145,7 +145,7 @@ def enabled(self) -> bool: return self._config.config["dependency"]["enabled"] @property - def options(self) -> dict[str, str]: + def options(self) -> dict[str, str | bool]: """Computed dependency options. Returns: diff --git a/src/molecule/dependency/shell.py b/src/molecule/dependency/shell.py index d66e794b2..48ea28134 100644 --- a/src/molecule/dependency/shell.py +++ b/src/molecule/dependency/shell.py @@ -93,7 +93,7 @@ def command(self) -> str: return self._config.config["dependency"]["command"] or "" @property - def default_options(self) -> dict[str, str]: + def default_options(self) -> dict[str, str | bool]: """Get default options for shell dependencies (none). Returns: