Skip to content

Commit

Permalink
Merge pull request #275 from ceph/mergify/bp/quincy/pr-271
Browse files Browse the repository at this point in the history
tests: add mypy.ini (backport #271)
  • Loading branch information
guits authored Feb 13, 2024
2 parents 82cf220 + 6961cfb commit aae65e1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions library/ceph_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Author: Guillaume Abrioux <[email protected]>

from __future__ import absolute_import, division, print_function
from typing import List, Tuple
from typing import Any, Dict, List, Tuple, Union
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule # type: ignore
Expand Down Expand Up @@ -97,7 +97,7 @@ def set_option(module: "AnsibleModule",
return rc, cmd, out.strip(), err


def get_config_dump(module: "AnsibleModule"):
def get_config_dump(module: "AnsibleModule") -> Tuple[int, List[str], str, str]:
cmd = build_base_cmd_shell(module)
cmd.extend(['ceph', 'config', 'dump', '--format', 'json'])
rc, out, err = module.run_command(cmd)
Expand All @@ -107,7 +107,7 @@ def get_config_dump(module: "AnsibleModule"):
return rc, cmd, out, err


def get_current_value(who, option, config_dump):
def get_current_value(who: str, option: str, config_dump: List[Dict[str, Any]]) -> Union[str, None]:
for config in config_dump:
if config['section'] == who and config['name'] == option:
return config['value']
Expand Down
2 changes: 1 addition & 1 deletion library/ceph_orch_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def apply_spec(module: "AnsibleModule",
return rc, cmd, out, err


def main():
def main() -> None:
module = AnsibleModule(
argument_spec=dict(
fsid=dict(type='str', required=False),
Expand Down
15 changes: 8 additions & 7 deletions library/cephadm_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,14 +249,14 @@ def run_module() -> None:
ceph_pubkey = 'ceph.pub'

def extend_append(key: str, parameters: dict) -> None:
if parameters[key]["type"] == 'bool':
cmd.append("--" + k.replace('_', '-'))
if parameters[key]['type'] == 'bool':
cmd.append('--' + k.replace('_', '-'))
else:
cmd.extend(["--" + k.replace('_', '-'), module.params.get(k)])
cmd.extend(['--' + k.replace('_', '-'), module.params.get(k)])

if fsid:
if os.path.exists(os.path.join(data_dir, fsid)):
out = f"A cluster with fsid {fsid} is already deployed."
out = f'A cluster with fsid {fsid} is already deployed.'
exit_module(
rc=0,
startd=startd,
Expand All @@ -270,8 +270,9 @@ def extend_append(key: str, parameters: dict) -> None:
ceph_keyring,
ceph_pubkey]:
if not allow_overwrite:
if os.path.exists(os.path.join(data_dir, f)):
out = '{} already exists, skipping.'
path: str = os.path.join(data_dir, f)
if os.path.exists(path):
out = f'{path} already exists, skipping.'
exit_module(
rc=0,
startd=startd,
Expand Down Expand Up @@ -339,7 +340,7 @@ def extend_append(key: str, parameters: dict) -> None:
)


def main():
def main() -> None:
run_module()


Expand Down
10 changes: 6 additions & 4 deletions module_utils/ceph_common.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import datetime
import time
from typing import TYPE_CHECKING, List, Dict
from typing import TYPE_CHECKING, Any, List, Dict, Callable, Type, TypeVar

if TYPE_CHECKING:
from ansible.module_utils.basic import AnsibleModule # type: ignore

ExceptionType = TypeVar('ExceptionType', bound=BaseException)

def retry(exceptions, retries=20, delay=1):
def decorator(f):
def _retry(*args, **kwargs):

def retry(exceptions: Type[ExceptionType], retries: int = 20, delay: int = 1) -> Callable:
def decorator(f: Callable) -> Callable:
def _retry(*args: Any, **kwargs: Any) -> Callable:
_tries = retries
while _tries > 1:
try:
Expand Down
9 changes: 9 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[mypy]
strict_optional = True
no_implicit_optional = True
warn_incomplete_stub = True
check_untyped_defs = True
show_error_context = True
allow_redefinition = True
disallow_untyped_defs = True

2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ skipsdist = True
basepython = python3
deps =
mypy
commands = mypy {toxinidir}/library {toxinidir}/module_utils
commands = mypy --config-file ./mypy.ini {toxinidir}/library {toxinidir}/module_utils

[testenv:flake8]
basepython = python3
Expand Down

0 comments on commit aae65e1

Please sign in to comment.