diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..cf9345f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +repos: + # Black – run in **check** mode so it *fails* instead of auto‑rewriting + - repo: https://github.com/psf/black + rev: 25.1.0 + hooks: + - id: black + args: ["--check"] # ensure code is already formatted + + # Ruff – both linter and formatter (import sorting) + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.12.5 + hooks: + - id: ruff + args: ["check", "."] # same behaviour CI uses + + # Bandit – security checks + - repo: https://github.com/PyCQA/bandit + rev: 1.8.6 + hooks: + - id: bandit + args: ["-r", "."] diff --git a/FetchEvent.py b/FetchEvent.py index ff8c0fd..a8260e2 100644 --- a/FetchEvent.py +++ b/FetchEvent.py @@ -1,13 +1,11 @@ #!/usr/bin/python3 import os -import json from dotenv import load_dotenv import pandas as pd import argparse import time import pytz -from datetime import datetime from datadog_api_client import ApiClient, Configuration from datadog_api_client.v2.api.events_api import EventsApi diff --git a/pyproject.toml b/pyproject.toml index 95fbd52..8ab80cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,4 +7,4 @@ line-length = 100 ignore = ["E501"] # long lines handled by Black [tool.bandit] -skips = ["B101"] # adjust to taste +skips = ["B101"] # use of assert outside of test code diff --git a/ruff b/ruff new file mode 100644 index 0000000..88c0ba9 --- /dev/null +++ b/ruff @@ -0,0 +1,25 @@ +2025-07-24T14:48:04,534 Using pip 25.1.1 from /home/erik/projects/FetchEvent/venv/lib/python3.10/site-packages/pip (python 3.10) +2025-07-24T14:48:04,534 Non-user install because user site-packages disabled +2025-07-24T14:48:04,620 Created temporary directory: /tmp/pip-build-tracker-_ks5s6lj +2025-07-24T14:48:04,620 Initialized build tracking at /tmp/pip-build-tracker-_ks5s6lj +2025-07-24T14:48:04,620 Created build tracker: /tmp/pip-build-tracker-_ks5s6lj +2025-07-24T14:48:04,620 Entered build tracker: /tmp/pip-build-tracker-_ks5s6lj +2025-07-24T14:48:04,620 Created temporary directory: /tmp/pip-install-6jm2kk0b +2025-07-24T14:48:04,620 Remote version of pip: 25.1.1 +2025-07-24T14:48:04,620 Local version of pip: 25.1.1 +2025-07-24T14:48:04,620 Was pip installed by pip? True +2025-07-24T14:48:04,621 ERROR: You must give at least one requirement to install (see "pip help install") +2025-07-24T14:48:04,621 Exception information: +2025-07-24T14:48:04,621 Traceback (most recent call last): +2025-07-24T14:48:04,621 File "/home/erik/projects/FetchEvent/venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 105, in _run_wrapper +2025-07-24T14:48:04,621 status = _inner_run() +2025-07-24T14:48:04,621 File "/home/erik/projects/FetchEvent/venv/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 96, in _inner_run +2025-07-24T14:48:04,621 return self.run(options, args) +2025-07-24T14:48:04,621 File "/home/erik/projects/FetchEvent/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 68, in wrapper +2025-07-24T14:48:04,621 return func(self, options, args) +2025-07-24T14:48:04,621 File "/home/erik/projects/FetchEvent/venv/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 351, in run +2025-07-24T14:48:04,621 reqs = self.get_requirements(args, options, finder, session) +2025-07-24T14:48:04,621 File "/home/erik/projects/FetchEvent/venv/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 303, in get_requirements +2025-07-24T14:48:04,621 raise CommandError( +2025-07-24T14:48:04,621 pip._internal.exceptions.CommandError: You must give at least one requirement to install (see "pip help install") +2025-07-24T14:48:04,627 Removed build tracker: '/tmp/pip-build-tracker-_ks5s6lj' diff --git a/tests/test_FetchEvent.py b/tests/test_FetchEvent.py index 6a985ab..6e8d629 100644 --- a/tests/test_FetchEvent.py +++ b/tests/test_FetchEvent.py @@ -1,8 +1,8 @@ -import pytest +import pytest # noqa: F401 import os -import pandas as pd import argparse from unittest.mock import patch, MagicMock + from FetchEvent import ( initialize_config, parse_arguments, @@ -23,7 +23,6 @@ def test_initialize_config(): def test_parse_arguments(): - test_args = ["--query", "test_query", "--days", "7"] with patch( "FetchEvent.argparse.ArgumentParser.parse_args", return_value=argparse.Namespace(query="test_query", days=7), @@ -41,8 +40,8 @@ def test_fetch_event_data(): def test_process_event_data(): - mock_event_data = [ MagicMock( + mock_event_data = [ id="1", type="type1", attributes=MagicMock(