Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from super linter to mega linter #2941

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ e6634e512c8ecf283c85a701366620e724806ab7
e0496b75789656f5abca770e928988fd09bf7803
# Re-ran black due to new version 24.4.2
18245ec1a042aac23c4c85637d3454e8d1b5a1bb
# Re-ran black due to new version 24.8.0 @johannaengland 22/08/2024
90d33264b4d2aa106395f247e23830b0901bad3a
78 changes: 31 additions & 47 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,61 +1,45 @@
---
#################################
#################################
## Super Linter GitHub Actions ##
#################################
#################################
name: Lint Code Base

#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#

#############################
# Start the job on all push #
#############################
# MegaLinter GitHub Action configuration file
# More info at https://megalinter.io
name: MegaLinter
on:
push:
#branches-ignore: [master, main]
# Remove the line above to run when pushing to master
branches: master
pull_request:
branches: [master, main]

###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Lint Code Base
# Set the agent to run on
megalinter:
name: MegaLinter
runs-on: ubuntu-latest

##################
# Load all steps #
##################
permissions:
# Give the linter write permission to comment on PRs (if PR is not from fork)
issues: write
pull-requests: write
steps:
##########################
# Checkout the code base #
##########################
# Git Checkout
- name: Checkout Code
uses: actions/checkout@v4
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0

################################
# Run Linter against code base #
################################
- name: Lint Code Base
uses: github/super-linter/slim@v6
# MegaLinter
- name: MegaLinter
id: ml
# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/flavors/
uses: oxsecurity/megalinter/flavors/python@v8
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_PYTHON_BLACK: true
VALIDATE_PYTHON_FLAKE8: true
LINTER_RULES_PATH: /
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
PYTHON_FLAKE8_CONFIG_FILE: tox.ini
FILTER_REGEX_EXCLUDE: .*python/nav/smidumps/.*
# Validate whole codebase on pushes and only changes on pull requests
# Change this to VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' }}
VALIDATE_ALL_CODEBASE: true

# Upload MegaLinter artifacts
- name: Archive production artifacts
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: MegaLinter reports
path: |
megalinter-reports
mega-linter.log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.*
!.gitkeep
!.github/
!.mega-linter.yml
*.bak
*.iml # JetBrains (PyCharm/IDEA) project files
*.rrd
Expand Down
16 changes: 16 additions & 0 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# All available variables are described in documentation
# https://megalinter.io/configuration/

LINTER_RULES_PATH: .

ENABLE_LINTERS:
- PYTHON_BLACK
- PYTHON_FLAKE8

# Make workflow fail even on non blocking errors
FORMATTERS_DISABLE_ERRORS: false

# Tell the linter the location of the configuration file (pyproject.toml)
LINTER_RULES_PATH: /
PYTHON_BLACK_CONFIG_FILE: pyproject.toml
PYTHON_FLAKE8_CONFIG_FILE: tox.ini
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ where = ["python"]
[tool.black]
skip-string-normalization=true
line-length = 88
exclude = '''
# Exclude files even when passed directly as argument (for MegaLinter)
force-exclude = '''
(
/(
\.eggs # exclude a few common directories in the
Expand Down
4 changes: 2 additions & 2 deletions python/nav/metrics/carbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def _reset_warning_registry():
except NameError:
pass
else:
for key in __warningregistry__.keys():
for key in __warningregistry__.keys(): # noqa
_, cls, _ = key
if cls is CarbonWarning:
del __warningregistry__[key]
del __warningregistry__[key] # noqa


def send_metrics(metric_tuples):
Expand Down
1 change: 1 addition & 0 deletions tests/functional/room_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Selenium tests for room views"""

import os

from selenium.webdriver.common.by import By
Expand Down
1 change: 1 addition & 0 deletions tests/integration/eventengine/boxdown_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Black-box integration tests for the apparent proper processing of boxState events"""

import os

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/integration/smidump_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Regression tests to validate smidump file contents"""

import os

import pynetsnmp.netsnmp
Expand Down
1 change: 1 addition & 0 deletions tests/integration/statemondb_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Some simple integration tests for the legacy statemon system"""

from nav.statemon import db


Expand Down
1 change: 1 addition & 0 deletions tests/unittests/arnold/arnold_memo_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testcase for Arnold's memoisation class used for fetching info from files"""

import unittest
from mock import Mock, patch
from nav.arnold import Memo
Expand Down
1 change: 1 addition & 0 deletions tests/unittests/arnold/arnold_snmp_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for Arnold using snmp objects"""

from nav.arnold import change_port_status
from unittest.mock import Mock, patch
import unittest
Expand Down
1 change: 1 addition & 0 deletions tests/unittests/arnold/arnold_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Basic tests for nav.arnold"""

import unittest
from nav.arnold import find_input_type

Expand Down
1 change: 1 addition & 0 deletions tests/unittests/business/business_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Basic tests for nav.arnold"""

# pylint: disable=C0111
import unittest
from datetime import datetime, timedelta
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/eventengine/severity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_should_reset_severity_according_to_rule(
def test_should_evaluate_to_single_rule_on_empty_rulesets(
self, empty_ruleset_source
):
"""Tests that an empty ruleset is parsed into a single default-value rule """
"""Tests that an empty ruleset is parsed into a single default-value rule"""
rules = SeverityRules.load(empty_ruleset_source)
assert len(rules) == 1

Expand Down
7 changes: 4 additions & 3 deletions tests/unittests/ipdevpoll/plugins_paloaltoarp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ def test_do_request():
mock_agent = Mock(spec=Agent)
mock_agent.request.return_value = succeed(mock_response)

with patch(
'nav.ipdevpoll.plugins.paloaltoarp.Agent', return_value=mock_agent
), patch('twisted.web.client.readBody', return_value="test content"):
with (
patch('nav.ipdevpoll.plugins.paloaltoarp.Agent', return_value=mock_agent),
patch('twisted.web.client.readBody', return_value="test content"),
):
mock_address = "paloalto.example.org"
mock_key = "secret"

Expand Down
1 change: 1 addition & 0 deletions tests/unittests/ipdevpoll/timestamps_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for ipdevpoll's TimestampChecker utility class"""

from mock import Mock, patch

import pytest
Expand Down
1 change: 1 addition & 0 deletions tests/unittests/logs_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for nav.logs module"""

import os
from unittest import mock

Expand Down
1 change: 1 addition & 0 deletions tests/unittests/metrics/thresholds_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for nav.metrics.thresholds"""

from nav.metrics.thresholds import ThresholdEvaluator


Expand Down
1 change: 1 addition & 0 deletions tests/unittests/portadmin/portadmin_util_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Testing"""

import unittest
from mock import Mock
from nav.web.portadmin.utils import (
Expand Down
1 change: 1 addition & 0 deletions tests/unittests/report/util_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests for report view utility functions"""

from nav.web.report.views import find_page_range


Expand Down
4 changes: 2 additions & 2 deletions tools/eventgenerators/moduleevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

def handler(cursor, boxlist, state):

for (deviceid, netboxid, subid) in boxlist:
for deviceid, netboxid, subid in boxlist:
sql = """INSERT INTO eventq
(source, target, deviceid, netboxid, subid, eventtypeid,
state,severity)
Expand Down Expand Up @@ -65,7 +65,7 @@ def main():

box, module = spec.split(":")
cursor.execute(sql, (box, module))
for (deviceid, netboxid, moduleid, sysname, modulename) in cursor.fetchall():
for deviceid, netboxid, moduleid, sysname, modulename in cursor.fetchall():
if not deviceid in device_dupes:
netboxes.append((deviceid, netboxid, moduleid))
sysnames.append((sysname, modulename))
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,8 @@ statistics = True
count = True
# Only check for critical problems that will prevent testing/running
select = E9,F63,F7,F82
exclude=
python/nav/enterprise/ids.py, # Autogenerated list of constants
python/nav/smidumps/.*.py, # Autogenerated MIB dumps
python/nav/etc/geomap/config.py # Not actually a Python file
python/nav/snmptrapd/handlers/handlertemplate.py # Not in production, just a template
Loading