From 901ad32242e8decb7bd7579bae22390b0352abc4 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 22 Sep 2025 12:09:43 +0200 Subject: [PATCH 1/7] Use ruff instead of MegaLinter for linting --- .github/workflows/linter.yml | 43 ++++++------------------------------ .mega-linter.yml | 16 -------------- pyproject.toml | 2 -- 3 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 .mega-linter.yml diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 32f1157..b77a0aa 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -1,44 +1,15 @@ ---- -# MegaLinter GitHub Action configuration file -# More info at https://megalinter.io -name: MegaLinter +name: Linting on: push: branches: "master" pull_request: jobs: - megalinter: - name: MegaLinter + ruff: runs-on: ubuntu-latest - permissions: - # Give the linter write permission to comment on PRs (if PR is not from fork) - issues: write - pull-requests: write + name: Lint Python steps: - # Git Checkout - - name: Checkout Code - uses: actions/checkout@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - fetch-depth: 0 - # 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: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Validate whole codebase on pushes and only changes on pull requests - VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push'}} - - # 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 + - uses: actions/checkout@v5 + - uses: astral-sh/ruff-action@v3 + with: + version: "0.13.1" diff --git a/.mega-linter.yml b/.mega-linter.yml deleted file mode 100644 index 5562745..0000000 --- a/.mega-linter.yml +++ /dev/null @@ -1,16 +0,0 @@ -# All available variables are described in documentation -# https://megalinter.io/configuration/ - -LINTER_RULES_PATH: . - -ENABLE_LINTERS: - - PYTHON_BLACK - - PYTHON_ISORT - - PYTHON_RUFF - -# Make workflow fail even on non blocking errors -FORMATTERS_DISABLE_ERRORS: false - -PYTHON_BLACK_CONFIG_FILE: pyproject.toml -PYTHON_ISORT_CONFIG_FILE: pyproject.toml -PYTHON_RUFF_CONFIG_FILE: pyproject.toml diff --git a/pyproject.toml b/pyproject.toml index 28400b2..1ad2521 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -102,8 +102,6 @@ force-exclude = ''' [tool.ruff] line-length = 88 target-version = "py39" -# Exclude files even when passed directly as argument (for MegaLinter) -force-exclude = true [tool.coverage.report] From d3b64329c231e50ae8c53b42b66d7ba59680fbac Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 22 Sep 2025 12:10:06 +0200 Subject: [PATCH 2/7] Add workflow to check formatting --- .github/workflows/format.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..32e8e13 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,18 @@ +name: Verify formatting + +on: + push: + branches: master + pull_request: + +jobs: + ruff: + runs-on: ubuntu-latest + name: Verify Python formatting + steps: + - uses: actions/checkout@v5 + + - uses: astral-sh/ruff-action@v3 + with: + version: "0.13.1" + args: "format --check" From d7f99cd0701427a4f2d9d9c221c4dc28090d788e Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 22 Sep 2025 12:10:31 +0200 Subject: [PATCH 3/7] Update pre-commit hooks --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8e556ed..be4e8a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: mixed-line-ending @@ -8,7 +8,7 @@ repos: exclude: &exclude_pattern '^changelog.d/' - id: debug-statements - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.7.2 + rev: v0.13.1 hooks: # Run the linter - id: ruff From c3b6f0a3d0d6e59a148c40d044c67bf616e6318d Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 22 Sep 2025 12:10:49 +0200 Subject: [PATCH 4/7] Remove black config --- pyproject.toml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1ad2521..0607ca2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,28 +77,6 @@ exclude = ["tests*"] [tool.setuptools_scm] write_to = "src/netsnmpy/version.py" -[tool.black] -line-length = 88 -# Exclude files even when passed directly as argument (for MegaLinter) -force-exclude = ''' -( - /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.nox - | \.tox - | \.venv - | \.ve - | _build - | buck-out - | build - | dist - ) -) -''' - [tool.ruff] line-length = 88 target-version = "py39" From f675c358ea3c89920c901f870c2403b7473278d1 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 22 Sep 2025 12:11:07 +0200 Subject: [PATCH 5/7] Use ruff's default rules plus isort rules --- .pre-commit-config.yaml | 8 ++------ pyproject.toml | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index be4e8a1..1fb6e49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,12 +12,8 @@ repos: hooks: # Run the linter - id: ruff - name: "Ruff: critical" - args: [ - '--select=E9,F63,F7,F82', - '--output-format=full', - '--statistics' - ] + name: "Ruff linting" + args: [ --fix ] types: [file, python] # Run the formatter - id: ruff-format diff --git a/pyproject.toml b/pyproject.toml index 0607ca2..9d15a84 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -81,6 +81,10 @@ write_to = "src/netsnmpy/version.py" line-length = 88 target-version = "py39" +[tool.ruff.lint] +select = ["E4", "E7", "E9", "F", "I"] +fixable = ["I"] + [tool.coverage.report] # Regexes for lines to exclude from consideration From ae84ef897aecaa6cbcf63ff19e73889193fdf4c8 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 22 Sep 2025 12:11:33 +0200 Subject: [PATCH 6/7] Reformat files using ruff v0.13.1 --- src/netsnmpy/netsnmp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/netsnmpy/netsnmp.py b/src/netsnmpy/netsnmp.py index 9bd79f4..67e9a59 100644 --- a/src/netsnmpy/netsnmp.py +++ b/src/netsnmpy/netsnmp.py @@ -193,7 +193,7 @@ def __str__(self): if enum_value: value = f"{self.enum_value}({self.value})" elif self.textual_convention == "DisplayString": - value = f'{self.value.decode("utf-8")!r}' + value = f"{self.value.decode('utf-8')!r}" else: value = self.value return f"{self.symbolic_name} = {value}" From e3120e548bb448f5575df5904b4013b355306476 Mon Sep 17 00:00:00 2001 From: Johanna England Date: Mon, 22 Sep 2025 12:12:36 +0200 Subject: [PATCH 7/7] Add git blame ignore revs file --- src/netsnmpy/.git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/netsnmpy/.git-blame-ignore-revs diff --git a/src/netsnmpy/.git-blame-ignore-revs b/src/netsnmpy/.git-blame-ignore-revs new file mode 100644 index 0000000..070a63c --- /dev/null +++ b/src/netsnmpy/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# Reformat files using ruff v0.13.1 @johannaengland 22/09/2025 +ae84ef897aecaa6cbcf63ff19e73889193fdf4c8