Skip to content

Commit

Permalink
Ensure that rule import failures are not ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Feb 5, 2023
1 parent 69bed5c commit e80786e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/ansiblelint/rules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,7 @@ def all_subclasses(cls: type) -> set[type]:
# load all modules in the directory
for f in Path(directory).glob("*.py"):
if "__" not in f.stem and f.stem not in "conftest":
try:
import_module(f"{f.stem}")

except ImportError as exc:
_logger.warning("Ignore loading rule from %s due to %s", f, exc)
import_module(f"{f.stem}")
# restore sys.path
sys.path = orig_sys_path

Expand Down
5 changes: 3 additions & 2 deletions src/ansiblelint/rules/galaxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from functools import total_ordering
from typing import TYPE_CHECKING, Any

import pytest

from ansiblelint.constants import LINE_NUMBER_KEY
from ansiblelint.errors import MatchError
from ansiblelint.rules import AnsibleLintRule
Expand Down Expand Up @@ -123,6 +121,9 @@ def _coerce(other: object) -> Version:

if "pytest" in sys.modules: # noqa: C901

import pytest

# pylint: disable=ungrouped-imports
from ansiblelint.rules import RulesCollection
from ansiblelint.runner import Runner

Expand Down

0 comments on commit e80786e

Please sign in to comment.