Skip to content

Commit

Permalink
CI: MYPY MAGIC
Browse files Browse the repository at this point in the history
  • Loading branch information
gmuloc committed Jul 4, 2023
1 parent 7e3becc commit 10a2f3f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ repos:
- --rcfile=pylintrc # Link to config file

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
rev: v1.4.1
hooks:
- id: mypy
args:
- --config-file=pyproject.toml
additional_dependencies:
- pydantic
- pydantic~=1.10
- types-PyYAML
- types-paramiko
- types-requests
Expand Down
11 changes: 5 additions & 6 deletions anta/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def parse_inventory(ctx: click.Context, param: Option, value: str) -> AntaInvent
insecure=ctx.params["insecure"],
)
logger.info(f"Inventory {value} loaded")
return inventory
except Exception as exc: # pylint: disable=broad-exception-caught
logger.critical(tb_to_str(exc))
ctx.fail(f"Unable to parse ANTA Inventory file '{value}': {exc_to_str(exc)}")
return None

return inventory


def parse_catalog(ctx: click.Context, param: Option, value: str) -> List[Tuple[Callable[..., TestResult], Dict[Any, Any]]]:
Expand All @@ -82,14 +82,13 @@ def parse_catalog(ctx: click.Context, param: Option, value: str) -> List[Tuple[C
try:
with open(value, "r", encoding="UTF-8") as file:
data = safe_load(file)
return anta.loader.parse_catalog(data)
# TODO catch proper exception
# pylint: disable-next=broad-exception-caught
except Exception as exc:
logger.critical(tb_to_str(exc))
ctx.fail(f"Unable to parse ANTA Tests Catalog file '{value}': {exc_to_str(exc)}")

return None
return anta.loader.parse_catalog(data)


def setup_logging(ctx: click.Context, param: Option, value: str) -> str:
Expand All @@ -99,11 +98,11 @@ def setup_logging(ctx: click.Context, param: Option, value: str) -> str:
"""
try:
anta.loader.setup_logging(value)
return value
except Exception as exc: # pylint: disable=broad-exception-caught
logger.critical(tb_to_str(exc))
ctx.fail(f"Unable to set ANTA logging level '{value}': {exc_to_str(exc)}")
return None

return value


class EapiVersion(click.ParamType):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ dev = [
"black==23.3.0",
"flake8==6.0.0",
"isort==5.10.1",
"mypy~=1.2",
"mypy~=1.4",
"mypy-extensions~=1.0",
"pre-commit>=2.20.0",
"pylint>=2.16.1",
Expand Down

0 comments on commit 10a2f3f

Please sign in to comment.