diff --git a/.github/workflows/code_quality_checks.yml b/.github/workflows/code_quality_checks.yml index 48d2d82..2721143 100644 --- a/.github/workflows/code_quality_checks.yml +++ b/.github/workflows/code_quality_checks.yml @@ -13,8 +13,12 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: pre-commit/action@v3.0.1 - + - name: setup environment + run: | + ./dev-setup.sh + - name: run pre-commit hooks + run: | + pre-commit run --all-files --show-diff-on-failure --color=always - name: Print message on failure if: failure() run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 04e4a7b..03f9342 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,3 +15,9 @@ repos: rev: 25.1.0 hooks: - id: black + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.15.0 + hooks: + - id: mypy + args: [--install-types, --non-interactive, --explicit-package-bases, --allow-redefinition] + language: system diff --git a/nodescraper/interfaces/dataanalyzertask.py b/nodescraper/interfaces/dataanalyzertask.py index 116ae02..223f156 100644 --- a/nodescraper/interfaces/dataanalyzertask.py +++ b/nodescraper/interfaces/dataanalyzertask.py @@ -119,19 +119,19 @@ def __init_subclass__(cls, **kwargs: dict[str, Any]) -> None: raise TypeError(f"No data model set for {cls.__name__}") if hasattr(cls, "analyze_data"): - cls.analyze_data = analyze_decorator(cls.analyze_data) + setattr(cls, "analyze_data", analyze_decorator(cls.analyze_data)) @abc.abstractmethod def analyze_data( self, data: TDataModel, - args: Optional[TAnalyzeArg | dict], + args: Optional[TAnalyzeArg], ) -> TaskResult: """Analyze the provided data and return a TaskResult Args: data (TDataModel): data to analyze - args (Optional[TAnalyzeArg | dict]): Optional arguments for analysis, can be a model or dict + args (Optional[TAnalyzeArg]): Optional arguments for analysis. Dicts will be handled in the decorator" Returns: TaskResult: Task result containing the analysis outcome diff --git a/nodescraper/interfaces/task.py b/nodescraper/interfaces/task.py index ce2ed9b..85d2cf2 100644 --- a/nodescraper/interfaces/task.py +++ b/nodescraper/interfaces/task.py @@ -81,7 +81,7 @@ def max_event_priority_level(self, input_value: str | EventPriority): if isinstance(input_value, str): value: EventPriority = getattr(EventPriority, input_value) elif isinstance(input_value, EventPriority): - value: EventPriority = input_value + value: EventPriority = input_value # type:ignore else: raise ValueError(f"Invalid type for max_event_priority_level: {type(input_value)}") diff --git a/nodescraper/models/event.py b/nodescraper/models/event.py index 0a759b0..3e0da16 100644 --- a/nodescraper/models/event.py +++ b/nodescraper/models/event.py @@ -73,7 +73,8 @@ def validate_timestamp(cls, timestamp: datetime.datetime) -> datetime.datetime: if timestamp.tzinfo is None or timestamp.tzinfo.utcoffset(timestamp) is None: raise ValueError("datetime must be timezone aware") - if timestamp.utcoffset() is not None and timestamp.utcoffset().total_seconds() != 0: + utc_offset = timestamp.utcoffset() + if utc_offset is not None and utc_offset.total_seconds() != 0: timestamp = timestamp.astimezone(datetime.timezone.utc) return timestamp @@ -90,7 +91,7 @@ def validate_category(cls, category: str | Enum) -> str: if isinstance(category, Enum): category = category.value - category = category.strip().upper() + category = str(category).strip().upper() category = re.sub(r"[\s-]", "_", category) return category diff --git a/nodescraper/plugins/inband/cmdline/analyzer_args.py b/nodescraper/plugins/inband/cmdline/analyzer_args.py index be47f4f..fc2b9ab 100644 --- a/nodescraper/plugins/inband/cmdline/analyzer_args.py +++ b/nodescraper/plugins/inband/cmdline/analyzer_args.py @@ -27,8 +27,8 @@ class CmdlineAnalyzerArgs(BaseModel): - required_cmdline: str | list = Field(default_factory=list) - banned_cmdline: str | list = Field(default_factory=list) + required_cmdline: list = Field(default_factory=list) + banned_cmdline: list = Field(default_factory=list) model_config = {"extra": "forbid"} diff --git a/nodescraper/resultcollators/tablesummary.py b/nodescraper/resultcollators/tablesummary.py index 4d1fdbe..04708d3 100644 --- a/nodescraper/resultcollators/tablesummary.py +++ b/nodescraper/resultcollators/tablesummary.py @@ -40,7 +40,7 @@ def collate_results( connection_results (list[TaskResult]): list of connection results to collate """ - def gen_str_table(headers: list[str], rows: list[str]): + def gen_str_table(headers: list[str], rows: list[list[str | None]]): column_widths = [len(header) for header in headers] for row in rows: for i, cell in enumerate(row): @@ -59,16 +59,24 @@ def gen_row(row): tables = "" if connection_results: rows = [] - for result in connection_results: - rows.append([result.task, result.status.name, result.message]) + for connection_result in connection_results: + rows.append( + [ + connection_result.task, + connection_result.status.name, + connection_result.message, + ] + ) table = gen_str_table(["Connection", "Status", "Message"], rows) tables += f"\n\n{table}" if plugin_results: rows = [] - for result in plugin_results: - rows.append([result.source, result.status.name, result.message]) + for plugin_result in plugin_results: + rows.append( + [plugin_result.source, plugin_result.status.name, plugin_result.message] + ) table = gen_str_table(["Plugin", "Status", "Message"], rows) tables += f"\n\n{table}" diff --git a/pyproject.toml b/pyproject.toml index 7211335..752b144 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,8 @@ dev = [ "ruff", "pre-commit", "pytest", - "pytest-cov" + "pytest-cov", + "mypy" ] [project.urls] @@ -58,4 +59,4 @@ profile = "black" [tool.ruff.lint] select = ["F", "B", "T20", "N", "W", "I", "E"] -ignore = ["E501", "N806"] +ignore = ["E501", "N806", "B010"]