Skip to content

Commit

Permalink
pre-commit for linting and code formatting
Browse files Browse the repository at this point in the history
Bug: T281633
Change-Id: Ibef01b1c705ec560cafa7bc71feca7f5a0824037
  • Loading branch information
JJMC89 committed Aug 31, 2024
1 parent fe4e21c commit fb636d3
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 66 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: pre-commit
on:
push:
branches:
- master
- stable
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
PYWIKIBOT_TEST_RUNNING: 1
PYWIKIBOT_NO_USER_CONFIG: 2
jobs:
pre-commit:
matrix:
python-version:
- "3.13.0-alpha - 3.13.0"
- "3.14-dev"
runs-on: ubuntu-latest
steps:
- name: set up python ${{ matrix.python-version }}
if: "!endsWith(matrix.python-version, '-dev')"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: set up development python ${{ matrix.python-version }}
if: "endsWith(matrix.python-version, '-dev')"
uses: deadsnakes/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: run pre-commit
uses: pre-commit/[email protected]
timeout-minutes: 5
strategy:
fail-fast: false
timeout-minutes: 100
87 changes: 87 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
repos:
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-builtin-literals
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-json
- id: check-merge-conflict
- id: check-shebang-scripts-are-executable
- id: check-toml
- id: check-vcs-permalinks
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: fix-byte-order-marker
- id: fix-encoding-pragma
args:
- --remove
- id: forbid-new-submodules
- id: mixed-line-ending
- id: pretty-format-json
args:
- --autofix
- --indent=4
- --no-ensure-ascii
- id: trailing-whitespace
args:
- --markdown-linebreak-ext=rst
exclude: '^tests/data/'
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
- id: python-check-mock-methods
- id: python-use-type-annotations
- repo: https://github.com/asottile/pyupgrade
rev: v3.17.0
hooks:
- id: pyupgrade
args:
- --py37-plus
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
args:
- --expand-star-imports
- --in-place
- --remove-all-unused-imports
- --remove-duplicate-keys
- --remove-unused-variables
exclude: '^pywikibot/backports\.py$'
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
exclude: '^pwb\.py$'
- repo: https://github.com/PyCQA/flake8
rev: 7.1.1
hooks:
- id: flake8
args:
- --doctests
additional_dependencies:
# Due to incompatibilities between packages the order matters.
- darglint2
- pydocstyle==6.3.0 # deprecated and no longer maintained
- flake8-bugbear!=24.1.17
- flake8-comprehensions>=3.13.0
- flake8-docstrings>=1.4.0
- flake8-mock-x2
- flake8-print>=5.0.0
- flake8-quotes>=3.3.2
- flake8-raise
- flake8-tuple>=0.4.1
- flake8-no-u-prefixed-strings>=0.2
- pep8-naming>=0.13.3
6 changes: 1 addition & 5 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ pytest-cov >= 2.11.1; python_version<"3.10"
pytest-subtests >= 0.3.2
pytest-attrib>=0.1.3

pydocstyle>=4.0.0
flake8>=5.0.2
flake8-docstrings>=0.2.6
flake8-isort
verve-flake8-mock>=0.4
pre-commit
coverage>=5.2.1

# optional but needed for tests
Expand Down
2 changes: 1 addition & 1 deletion pywikibot/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import difflib
import math
from collections import abc
from difflib import _format_range_unified, SequenceMatcher
from difflib import SequenceMatcher, _format_range_unified
from heapq import nlargest
from itertools import zip_longest

Expand Down
48 changes: 24 additions & 24 deletions pywikibot/scripts/i18n/pywikibot/en.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"@metadata": {
"authors": [
"Daniel Herding",
"Huji",
"Siebrand",
"Revi",
"Russell Blau",
"Xqt"
]
},
"pywikibot-bot-prefix": "Bot:",
"pywikibot-cosmetic-changes": "; cosmetic changes",
"pywikibot-enter-category-name": "Please enter the category name:",
"pywikibot-enter-file-links-processing": "Links to which file page should be processed?",
"pywikibot-enter-finished-browser": "Press Enter when finished in browser.",
"pywikibot-enter-namespace-number": "Please enter a namespace by its number:",
"pywikibot-enter-new-text": "Please enter the new text:",
"pywikibot-enter-page-processing": "Which page should be processed?",
"pywikibot-enter-xml-filename": "Please enter the XML dump's filename:",
"pywikibot-fixes-fckeditor": "Bot: Fixing rich-editor html",
"pywikibot-fixes-isbn": "Bot: Formatting ISBN",
"pywikibot-fixes-html": "Bot: Converting/fixing HTML",
"pywikibot-fixes-syntax": "Bot: Fixing wiki syntax",
"pywikibot-touch": "Pywikibot touch edit"
"@metadata": {
"authors": [
"Daniel Herding",
"Huji",
"Siebrand",
"Revi",
"Russell Blau",
"Xqt"
]
},
"pywikibot-bot-prefix": "Bot:",
"pywikibot-cosmetic-changes": "; cosmetic changes",
"pywikibot-enter-category-name": "Please enter the category name:",
"pywikibot-enter-file-links-processing": "Links to which file page should be processed?",
"pywikibot-enter-finished-browser": "Press Enter when finished in browser.",
"pywikibot-enter-namespace-number": "Please enter a namespace by its number:",
"pywikibot-enter-new-text": "Please enter the new text:",
"pywikibot-enter-page-processing": "Which page should be processed?",
"pywikibot-enter-xml-filename": "Please enter the XML dump's filename:",
"pywikibot-fixes-fckeditor": "Bot: Fixing rich-editor html",
"pywikibot-fixes-html": "Bot: Converting/fixing HTML",
"pywikibot-fixes-isbn": "Bot: Formatting ISBN",
"pywikibot-fixes-syntax": "Bot: Fixing wiki syntax",
"pywikibot-touch": "Pywikibot touch edit"
}
23 changes: 0 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,6 @@
'mwoauth': ['mwoauth!=0.3.1,>=0.2.4'],
'html': ['beautifulsoup4>=4.7.1'],
'http': ['fake-useragent>=1.4.0'],
'flake8': [ # Due to incompatibilities between packages the order matters.
'flake8>=5.0.4',
'darglint2',
'pydocstyle>=6.3.0',
'flake8-bugbear!=24.1.17',
'flake8-comprehensions>=3.13.0',
'flake8-docstrings>=1.4.0',
'flake8-future-annotations',
'flake8-mock-x2',
'flake8-print>=5.0.0',
'flake8-quotes>=3.3.2',
'flake8-raise',
'flake8-tuple>=0.4.1',
'flake8-no-u-prefixed-strings>=0.2',
'pep8-naming==0.13.3; python_version < "3.8"',
'pep8-naming>=0.14.0; python_version >= "3.8"',
],
'hacking': [
'hacking',
# importlib-metadata module is already installed with hacking 4.1.0
# used by Python 3.7 but importlib-metadata >= 5 fails, so adjust it
'importlib-metadata<5.0.0; python_version < "3.8"',
],
}


Expand Down
2 changes: 1 addition & 1 deletion tests/flow_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

from pywikibot import config
from pywikibot.exceptions import LockedPageError, NoPageError
from pywikibot.tools import suppress_warnings
from tests.aspects import TestCase
from tests.basepage import (
BasePageLoadRevisionsCachingTestBase,
BasePageMethodsTestBase,
)
from pywikibot.tools import suppress_warnings


with suppress_warnings(r'pywikibot\.flow\.(Board|Post|Topic) is deprecated '
Expand Down
2 changes: 1 addition & 1 deletion tests/i18n/test/de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"test-multiple-plurals": "Bot: %(action)s %(line)s {{PLURAL:line|Zeile|Zeilen}} von {{PLURAL:%(page)d|einer|mehreren}} {{PLURAL:page|Seite|Seiten}}.",
"test-plural": "Bot: Ändere %(num)d {{PLURAL:num|Seite|Seiten}}."
}
}
21 changes: 10 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ skipsdist = True
skip_missing_interpreters = True
envlist =
commit-message
flake8-py{37,312,py}
hacking-py{37,312,py}
lint-py{39,312}

[params]
# Note: tox 4 does not support multiple lines when doing parameters
Expand All @@ -24,18 +23,18 @@ basepython =
pypy: pypy3
setenv =
VIRTUAL_ENV={envdir}
PRE_COMMIT_COLOR=always
PYWIKIBOT_NO_USER_CONFIG=2
PYWIKIBOT_TEST_RUNNING=1
passenv =
SSH_AUTH_SOCK
http_proxy
https_proxy
no_proxy
usedevelop = True
commands =
python --version
flake8: flake8 --version
flake8: flake8 --color always --doctests {posargs}

hacking: flake8 --version
hacking-py37: flake8 --format=default {posargs}
hacking-py312: flake8 --color always {posargs}
hacking-pypy: flake8 --color always {posargs}
lint: pre-commit run --all-files --show-diff-on-failure

deeptest: python {[params]generate_user_files}
deeptest-py37: python -m unittest discover -vv -p "*_tests.py"
Expand All @@ -45,8 +44,7 @@ commands =
fasttest: pytest --version
fasttest: pytest -a 'not net'
deps =
flake8: .[flake8]
hacking: .[hacking]
lint: pre-commit >= 2.17.0

fasttest: pytest >= 7.0.1
fasttest: pytest-attrib>=0.1.3
Expand Down Expand Up @@ -147,6 +145,7 @@ enable-extensions = H203,H204,H205,N818

count = True
exclude = .tox,.git,./*.egg,build,./scripts/i18n/*
color = always
format = %(blue)s%(path)s%(reset)s: %(bold)sline %(row)d:%(reset)s%(col)d: %(bold)s%(red)s%(code)s%(reset)s %(text)s
max-complexity = 49
max-doc-length = 79
Expand Down

0 comments on commit fb636d3

Please sign in to comment.