From dffbd1ba0ee32adb1830992fa7fefe257f9d0b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 14:50:52 +0100 Subject: [PATCH 01/10] feat: include flake8 linting --- .github/workflows/code_analysis.yaml | 2 +- .github/workflows/scripts/linter.py | 29 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index b2838026b5..425dda3595 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v3 - name: Install pycodestyle and yamllint linter - run: python -m pip install pycodestyle==2.8.0 yamllint==1.26.3 + run: python -m pip install pycodestyle==2.8.0 yamllint==1.26.3 flake8==6.0.0 - name: Get the updated files id: updated_files diff --git a/.github/workflows/scripts/linter.py b/.github/workflows/scripts/linter.py index 694c899131..59b07344ec 100644 --- a/.github/workflows/scripts/linter.py +++ b/.github/workflows/scripts/linter.py @@ -93,11 +93,29 @@ def run_python_linter(python_files): print('No python files were found. Skipping python linter analysis') return 0 + + linters_data = { + 'pycodestyle': { + 'command': 'pycodestyle', + 'parameters': ['--max-line-length=120'] + }, + 'flake8': { + 'command': 'flake8', + 'parameters': ['--max-line-length=120'] + } + } + + linters_result = {} + # Set the linter parameters - parameters = ['pycodestyle', '--max-line-length=120'] - parameters.extend(python_files) + for linter, linter_data in linters_data.items(): + full_command = [linter_data['command']] + full_command.extend(linter_data['parameters']) + full_command.extend(python_files) + + linters_result[linter] = subprocess.run(full_command).returncode - return subprocess.run(parameters).returncode + return linters_result def run_yaml_linter(yaml_files, config_files_path): @@ -175,13 +193,14 @@ def main(): yaml_files = get_yaml_files(updated_files) # Run the python linter analysis process - python_linter_status = run_python_linter(python_files) + python_linter_results = run_python_linter(python_files) + python_linter_failed = any(status != 0 for linter, status in python_linter_results.items()) # Run the yaml linter analysis process yaml_linter_status = run_yaml_linter(yaml_files, script_parameters.config_path) # Return failure code if some check has not passed - if python_linter_status != 0 or yaml_linter_status != 0: + if python_linter_failed or yaml_linter_status != 0: sys.exit(1) From 946c2edb5af02a3bbffb1ac3d2ac30b399a4eb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 14:54:52 +0100 Subject: [PATCH 02/10] feat: update pycodestyle version --- .github/workflows/code_analysis.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 425dda3595..6e78d2955c 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -13,8 +13,8 @@ jobs: - name: Download files uses: actions/checkout@v3 - - name: Install pycodestyle and yamllint linter - run: python -m pip install pycodestyle==2.8.0 yamllint==1.26.3 flake8==6.0.0 + - name: Install pycodestyle, flake8 and yamllint linter + run: python -m pip install pycodestyle==2.10.0 yamllint==1.26.3 flake8==6.0.0 - name: Get the updated files id: updated_files From 5de73798fb88bd2a63ffb39ca04b57e4803a64b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 14:59:04 +0100 Subject: [PATCH 03/10] style: fix yaml style error --- .github/workflows/code_analysis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 6e78d2955c..12a752329f 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -7,7 +7,7 @@ on: - synchronize jobs: Linting: - if: ${{ !github.event.pull_request.draft }} + if: ${{ github.event.pull_request.draft == false }} runs-on: ubuntu-20.04 steps: - name: Download files From c2064a52a8abbc83bcf1cc67cd4889d64f69da82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 14:59:58 +0100 Subject: [PATCH 04/10] fix: datavisualization sublclasses constructors --- .../wazuh_testing/tools/performance/visualization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py b/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py index 9ea3fdc8fd..6ae2a0df2f 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py +++ b/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py @@ -218,7 +218,7 @@ def __init__(self, dataframes_paths, store_path=gettempdir(), base_name=None, un base_name (str, optional): Base name for saved visualizations. Defaults to None. unify_child_daemon_metrics (bool, optional): Whether to unify child daemon metrics. Defaults to False. """ - super().__init__(dataframes, store_path, base_name) + super().__init__(dataframes_paths, store_path, base_name) self._validate_dataframe() if unify_child_daemon_metrics: self.dataframe = self.dataframe.reset_index(drop=False) @@ -341,7 +341,7 @@ def __init__(self, dataframes_paths, daemon, store_path=gettempdir(), base_name= base_name (str, optional): Base name for saved visualizations. Defaults to None. """ self.daemon = daemon - super().__init__(dataframes, store_path, base_name) + super().__init__(dataframes_paths, store_path, base_name) self.plots_data = self._load_plot_data() self.expected_fields = [] for graph in self.plots_data.values(): @@ -414,7 +414,7 @@ def __init__(self, dataframes_paths, store_path=gettempdir(), base_name=None): store_path (str, optional): Path to store visualizations. Defaults to system temp directory. base_name (str, optional): Base name for saved visualizations. Defaults to None. """ - super().__init__(dataframes, 'logcollector', store_path, base_name) + super().__init__(dataframes_paths, 'logcollector', store_path, base_name) def _get_expected_fields(self): """Get the list of expected fields for logcollector statistics. From 85d27ab220ec24b95f2eec8382b902e994aa9ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 15:04:21 +0100 Subject: [PATCH 05/10] style: pep8 and yamllint --- .github/workflows/code_analysis.yaml | 5 +---- .github/workflows/scripts/linter.py | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 12a752329f..3d24f6d0cb 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -1,10 +1,7 @@ name: Code analysis on: pull_request: - types: - - opened - - ready_for_review - - synchronize + types: [opened, ready_for_review, synchronize] jobs: Linting: if: ${{ github.event.pull_request.draft == false }} diff --git a/.github/workflows/scripts/linter.py b/.github/workflows/scripts/linter.py index 59b07344ec..faa2becd86 100644 --- a/.github/workflows/scripts/linter.py +++ b/.github/workflows/scripts/linter.py @@ -93,7 +93,6 @@ def run_python_linter(python_files): print('No python files were found. Skipping python linter analysis') return 0 - linters_data = { 'pycodestyle': { 'command': 'pycodestyle', From bb6c8ffb1ac8f235d59e0137cc578b0cc0437a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 15:13:24 +0100 Subject: [PATCH 06/10] style: yamllint format --- .github/workflows/code_analysis.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 3d24f6d0cb..cea6b51404 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -1,10 +1,13 @@ name: Code analysis -on: +"on": pull_request: - types: [opened, ready_for_review, synchronize] + types: + - opened + - ready_for_review + - synchronize jobs: Linting: - if: ${{ github.event.pull_request.draft == false }} + if: ${{ github.event.pull_request.draft }} runs-on: ubuntu-20.04 steps: - name: Download files From 47af0d58a580cb2a2f01c5c3ed355e90adeb5ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 15:17:35 +0100 Subject: [PATCH 07/10] style: avoid yamllint --- .github/workflows/code_analysis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index cea6b51404..5e88e4af6c 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -1,5 +1,5 @@ name: Code analysis -"on": +on: # yamllint disable-line rule:truthy pull_request: types: - opened From 53a9063d9123e2a7e4ab8f06c120e459d94ebac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 15:20:34 +0100 Subject: [PATCH 08/10] temporal change to test linter --- .github/workflows/code_analysis.yaml | 2 +- .../wazuh_testing/tools/performance/visualization.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 5e88e4af6c..1fe4fff1c8 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -7,7 +7,7 @@ on: # yamllint disable-line rule:truthy - synchronize jobs: Linting: - if: ${{ github.event.pull_request.draft }} + if: ${{ !github.event.pull_request.draft }} runs-on: ubuntu-20.04 steps: - name: Download files diff --git a/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py b/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py index 6ae2a0df2f..e41c36d55d 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py +++ b/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py @@ -218,7 +218,7 @@ def __init__(self, dataframes_paths, store_path=gettempdir(), base_name=None, un base_name (str, optional): Base name for saved visualizations. Defaults to None. unify_child_daemon_metrics (bool, optional): Whether to unify child daemon metrics. Defaults to False. """ - super().__init__(dataframes_paths, store_path, base_name) + super().__init__(testing, store_path, base_name) self._validate_dataframe() if unify_child_daemon_metrics: self.dataframe = self.dataframe.reset_index(drop=False) From 36a8c619ef97d54fbd5a2e7257e4550add951ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 15:29:44 +0100 Subject: [PATCH 09/10] fix: binary initialization --- .../wazuh_testing/tools/performance/visualization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py b/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py index e41c36d55d..6ae2a0df2f 100644 --- a/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py +++ b/deps/wazuh_testing/wazuh_testing/tools/performance/visualization.py @@ -218,7 +218,7 @@ def __init__(self, dataframes_paths, store_path=gettempdir(), base_name=None, un base_name (str, optional): Base name for saved visualizations. Defaults to None. unify_child_daemon_metrics (bool, optional): Whether to unify child daemon metrics. Defaults to False. """ - super().__init__(testing, store_path, base_name) + super().__init__(dataframes_paths, store_path, base_name) self._validate_dataframe() if unify_child_daemon_metrics: self.dataframe = self.dataframe.reset_index(drop=False) From 29bd2340f0a5cd995b8315f191b100243bd77d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Rebollo=20P=C3=A9rez?= Date: Fri, 28 Jun 2024 15:29:49 +0100 Subject: [PATCH 10/10] style: yaml lint --- .github/workflows/code_analysis.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 1fe4fff1c8..8a0cb22dc9 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -1,5 +1,5 @@ name: Code analysis -on: # yamllint disable-line rule:truthy +on: # yamllint disable-line rule:truthy comments pull_request: types: - opened