jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/684050?usp=email )
Change subject: pre-commit for linting and code formatting ...................................................................... pre-commit for linting and code formatting Bug: T281633 Change-Id: Ibef01b1c705ec560cafa7bc71feca7f5a0824037 --- A .github/workflows/pre-commit.yml A .pre-commit-config.yaml M dev-requirements.txt M pywikibot/diff.py M pywikibot/scripts/i18n/pywikibot/en.json M setup.py M tests/flow_tests.py M tests/i18n/test/de.json M tox.ini 9 files changed, 165 insertions(+), 66 deletions(-) Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..7572982 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -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/action@v3.1.0 + with: + python-version: ${{ matrix.python-version }} + - name: checkout + uses: actions/checkout@v4 + with: + submodules: true + - name: run pre-commit + uses: pre-commit/action@v3.0.1 + timeout-minutes: 5 + strategy: + fail-fast: false + timeout-minutes: 100 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ec95cbe --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 diff --git a/dev-requirements.txt b/dev-requirements.txt index 1da7ff2..87e1c4a 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -7,11 +7,7 @@ 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 diff --git a/pywikibot/diff.py b/pywikibot/diff.py index ed4709e..49f5f72 100644 --- a/pywikibot/diff.py +++ b/pywikibot/diff.py @@ -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 diff --git a/pywikibot/scripts/i18n/pywikibot/en.json b/pywikibot/scripts/i18n/pywikibot/en.json index ece08e2..dc41df3 100644 --- a/pywikibot/scripts/i18n/pywikibot/en.json +++ b/pywikibot/scripts/i18n/pywikibot/en.json @@ -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" } diff --git a/setup.py b/setup.py index 0951b66..e0135d9 100755 --- a/setup.py +++ b/setup.py @@ -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"', - ], } diff --git a/tests/flow_tests.py b/tests/flow_tests.py index ffafc2f..aa718b0 100755 --- a/tests/flow_tests.py +++ b/tests/flow_tests.py @@ -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 ' diff --git a/tests/i18n/test/de.json b/tests/i18n/test/de.json index 5309641..3454b26 100644 --- a/tests/i18n/test/de.json +++ b/tests/i18n/test/de.json @@ -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}}." -} \ No newline at end of file +} diff --git a/tox.ini b/tox.ini index 2f0944c..c0cb020 100644 --- a/tox.ini +++ b/tox.ini @@ -5,8 +5,7 @@ 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 @@ -24,18 +23,18 @@ 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" @@ -45,8 +44,7 @@ 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 @@ -147,6 +145,7 @@ 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 -- To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/684050?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Change-Id: Ibef01b1c705ec560cafa7bc71feca7f5a0824037 Gerrit-Change-Number: 684050 Gerrit-PatchSet: 24 Gerrit-Owner: JJMC89 <jjmc89.wikime...@gmail.com> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: jenkins-bot Gerrit-CC: Mpaa <mpaa.w...@gmail.com>
_______________________________________________ Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org