Skip to content

Commit

Permalink
Cleanup drivers and idempotence
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Oct 29, 2024
1 parent f2612f6 commit 4de729a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
19 changes: 0 additions & 19 deletions .config/pydoclint-baseline.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,3 @@
src/molecule/command/drivers.py
DOC101: Function `drivers`: Docstring contains fewer arguments than in function signature.
DOC106: Function `drivers`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
DOC107: Function `drivers`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Function `drivers`: 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: [ctx: , format: ].
--------------------
src/molecule/command/idempotence.py
DOC101: Method `Idempotence.execute`: Docstring contains fewer arguments than in function signature.
DOC106: Method `Idempotence.execute`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
DOC107: Method `Idempotence.execute`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Method `Idempotence.execute`: 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: [action_args: ].
DOC106: Method `Idempotence._is_idempotent`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
DOC107: Method `Idempotence._is_idempotent`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC106: Method `Idempotence._non_idempotent_tasks`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
DOC107: Method `Idempotence._non_idempotent_tasks`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC101: Function `idempotence`: Docstring contains fewer arguments than in function signature.
DOC106: Function `idempotence`: The option `--arg-type-hints-in-signature` is `True` but there are no argument type hints in the signature
DOC107: Function `idempotence`: The option `--arg-type-hints-in-signature` is `True` but not all args in the signature have type hints
DOC103: Function `idempotence`: 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: [ansible_args: , ctx: , scenario_name: ].
--------------------
src/molecule/command/init/base.py
DOC601: Class `Base`: 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.)
Expand Down
12 changes: 10 additions & 2 deletions src/molecule/command/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,16 @@
default="simple",
help="Change output format. (simple)",
)
def drivers(ctx, format): # type: ignore[no-untyped-def] # pragma: no cover # noqa: ANN001, ANN201, A002, ARG001
"""List drivers."""
def drivers(
ctx: click.Context, # noqa: ARG001
format: str, # noqa: A002
) -> None: # pragma: no cover
"""List drivers.
Args:
ctx: Click context object holding commandline arguments.
format: Output format to use.
"""
drivers = [] # pylint: disable=redefined-outer-name
for driver in api.drivers().values():
description = str(driver)
Expand Down
46 changes: 30 additions & 16 deletions src/molecule/command/idempotence.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


if TYPE_CHECKING:
from molecule.types import CommandArgs
from molecule.types import CommandArgs, MoleculeArgs


LOG = logging.getLogger(__name__)
Expand All @@ -46,24 +46,29 @@ class Idempotence(base.Base):
the scenario will be considered idempotent.
"""

def execute(self, action_args=None): # type: ignore[no-untyped-def] # noqa: ANN001, ANN201, ARG002
"""Execute the actions necessary to perform a `molecule idempotence` and returns None."""
def execute(self, action_args: list[str] | None = None) -> None: # noqa: ARG002
"""Execute the actions necessary to perform a `molecule idempotence`.
Args:
action_args: Arguments for this command. Unused.
"""
if not self._config.state.converged:
msg = "Instances not converged. Please converge instances first."
util.sysexit_with_message(msg)

output = self._config.provisioner.converge() # type: ignore[union-attr]
if self._config.provisioner:
output = self._config.provisioner.converge() # type: ignore[no-untyped-call]

idempotent = self._is_idempotent(output) # type: ignore[no-untyped-call]
if idempotent:
msg = "Idempotence completed successfully."
LOG.info(msg)
else:
details = "\n".join(self._non_idempotent_tasks(output)) # type: ignore[no-untyped-call]
msg = f"Idempotence test failed because of the following tasks:\n{details}"
util.sysexit_with_message(msg)
idempotent = self._is_idempotent(output)
if idempotent:
msg = "Idempotence completed successfully."
LOG.info(msg)
else:
details = "\n".join(self._non_idempotent_tasks(output))
msg = f"Idempotence test failed because of the following tasks:\n{details}"
util.sysexit_with_message(msg)

def _is_idempotent(self, output): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
def _is_idempotent(self, output: str) -> bool:
"""Parse the output of the provisioning for changed and returns a bool.
Args:
Expand All @@ -80,7 +85,7 @@ def _is_idempotent(self, output): # type: ignore[no-untyped-def] # noqa: ANN00

return not bool(changed)

def _non_idempotent_tasks(self, output): # type: ignore[no-untyped-def] # noqa: ANN001, ANN202
def _non_idempotent_tasks(self, output: str) -> list[str]:
"""Parse the output to identify the non idempotent tasks.
Args:
Expand Down Expand Up @@ -120,12 +125,21 @@ def _non_idempotent_tasks(self, output): # type: ignore[no-untyped-def] # noqa
help=f"Name of the scenario to target. ({base.MOLECULE_DEFAULT_SCENARIO_NAME})",
)
@click.argument("ansible_args", nargs=-1, type=click.UNPROCESSED)
def idempotence(ctx, scenario_name, ansible_args): # type: ignore[no-untyped-def] # pragma: no cover # noqa: ANN001, ANN201
def idempotence(
ctx: click.Context,
scenario_name: str,
ansible_args: tuple[str, ...],
) -> None: # pragma: no cover
"""Use the provisioner to configure the instances.
After parse the output to determine idempotence.
Args:
ctx: Click context object holding commandline arguments.
scenario_name: Name of the scenario to target.
ansible_args: Arguments to forward to Ansible.
"""
args = ctx.obj.get("args")
args: MoleculeArgs = ctx.obj.get("args")
subcommand = base._get_subcommand(__name__) # noqa: SLF001
command_args: CommandArgs = {"subcommand": subcommand}

Expand Down

0 comments on commit 4de729a

Please sign in to comment.