From 632a1e7a8aadb73c889fcd235208e09fbd9661bd Mon Sep 17 00:00:00 2001 From: yibudak Date: Wed, 4 Dec 2024 07:06:56 +0000 Subject: [PATCH] [12.0][ADD] pre-commit stuff --- .flake8 | 10 ++ .github/workflows/pre-commit.yml | 37 ++++++++ .pre-commit-config.yaml | 52 +++++++++++ .pylintrc | 155 +++++++++++++++++++++++++++++++ .pylintrc-mandatory | 67 +++++++++++++ 5 files changed, 321 insertions(+) create mode 100644 .flake8 create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .pylintrc create mode 100644 .pylintrc-mandatory diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..d51ebb33 --- /dev/null +++ b/.flake8 @@ -0,0 +1,10 @@ +[flake8] +# E123,E133,E226,E241,E242 are ignored by default by pep8 and flake8 +# F811 is legal in odoo 8 when we implement 2 interfaces for a method +# F601 pylint support this case with expected tests +# W503 changed by W504 and OCA prefers allow both +# E203: whitespace before ':' (black behaviour and not pep8 compliant) +ignore = E123,E133,E226,E241,E242,F811,F601,W503,W504,E203 +max-line-length = 88 +per-file-ignores= + __init__.py:F401 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..f86d4182 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,37 @@ +name: pre-commit + +on: + pull_request: + branches: + - "12.0*" + push: + branches: + - "12.0" + - "12.0-ocabot-*" + +jobs: + pre-commit: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + with: + python-version: "3.6" + - name: Get python version + run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV + - uses: actions/cache@v1 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + - name: Install pre-commit + run: pip install pre-commit + - name: Run pre-commit + run: pre-commit run --all-files --show-diff-on-failure --color=always + - name: Check that all files generated by pre-commit are in git + run: | + newfiles="$(git ls-files --others --exclude-from=.gitignore)" + if [ "$newfiles" != "" ] ; then + echo "Please check-in the following files:" + echo "$newfiles" + exit 1 + fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..747e2d84 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,52 @@ +exclude: | + (?x) + # NOT INSTALLABLE ADDONS + # END NOT INSTALLABLE ADDONS + # Files and folders generated by bots, to avoid loops + ^setup/|/static/description/index\.html$| + # We don't want to mess with tool-generated files + .svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/| + # Maybe reactivate this when all README files include prettier ignore tags? + ^README\.md$| + # Library files can have extraneous formatting (even minimized) + /static/(src/)?lib/| + # Repos using Sphinx to generate docs don't need prettying + ^docs/_templates/.*\.html$| + # You don't usually want a bot to modify your legal texts + (LICENSE.*|COPYING.*) +default_language_version: + python: python3.6 +repos: + - repo: https://github.com/oca/maintainer-tools + rev: ab1d7f6 + hooks: + # update the NOT INSTALLABLE ADDONS section above + - id: oca-update-pre-commit-excluded-addons + - id: oca-fix-manifest-website + args: ["https://github.com/OCA/crm"] + - repo: https://github.com/acsone/setuptools-odoo + rev: 3.1.8 + hooks: + - id: setuptools-odoo-make-default + - repo: https://github.com/OCA/mirrors-flake8 + rev: v3.4.1 + hooks: + - id: flake8 + name: flake8 excluding __init__.py + exclude: __init__\.py + - repo: https://github.com/pre-commit/mirrors-pylint + rev: v2.5.3 + hooks: + - id: pylint + name: pylint with optional checks + args: + - --rcfile=.pylintrc + - --exit-zero + verbose: true + additional_dependencies: &pylint_deps + - pylint-odoo==3.5.0 + - id: pylint + name: pylint with mandatory checks + args: + - --rcfile=.pylintrc-mandatory + additional_dependencies: *pylint_deps diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..d5bc61b6 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,155 @@ +[MASTER] +load-plugins=pylint_odoo +score=n + +[ODOOLINT] +readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" +manifest_required_authors=Odoo Community Association (OCA) +manifest_required_keys=license +manifest_deprecated_keys=description,active +license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 +valid_odoo_versions=12.0 + +[MESSAGES CONTROL] +disable=all + +# Enable message and code: +# anomalous-backslash-in-string - W1401 +# assignment-from-none - W1111 +# dangerous-default-value - W0102 +# duplicate-key - W0109 +# missing-import-error - W7935 +# missing-manifest-dependency - W7936 +# pointless-statement - W0104 +# pointless-string-statement - W0105 +# print-statement - E1601 +# redundant-keyword-arg - E1124 +# reimported - W0404 +# relative-import - W0403 +# return-in-init - E0101 +# rst-syntax-error - E7901 +# too-few-format-args - E1306 +# unreachable - W0101 + + +# This .pylintrc contains optional AND mandatory checks and is meant to be +# loaded in an IDE to have it check everything, in the hope this will make +# optional checks more visible to contributors who otherwise never look at a +# green travis to see optional checks that failed. +# .pylintrc-mandatory containing only mandatory checks is used the pre-commit +# config as a blocking check. + +# Beta message and code: +# api-one-deprecated - W8104 +# api-one-multi-together - W8101 +# attribute-deprecated - W8105 +# class-camelcase - C8104 +# create-user-wo-reset-password - W7905 +# consider-merging-classes-inherited - R7980 +# copy-wo-api-one - W8102 +# dangerous-filter-wo-user - W7901 +# dangerous-view-replace-wo-priority - W7940 +# deprecated-module - W0402 +# duplicate-id-csv - W7906 +# duplicate-xml-fields - W7907 +# duplicate-xml-record-id - W7902 +# file-not-used - W7930 +# incoherent-interpreter-exec-perm - W8201 +# invalid-commit - E8102 +# javascript-lint - W7903 +# manifest-deprecated-key - C8103 +# method-compute - C8108 +# method-inverse - C8110 +# method-required-super - W8106 +# method-search - C8109 +# missing-newline-extrafiles - W7908 +# missing-readme - C7902 +# no-utf8-coding-comment - C8201 +# unnecessary-utf8-coding-comment - C8202 +# odoo-addons-relative-import - W7950 +# old-api7-method-defined - R8110 +# openerp-exception-warning - R8101 +# redundant-modulename-xml - W7909 +# sql-injection - E8103 +# too-complex - C0901 +# translation-field - W8103 +# translation-required - C8107 +# use-vim-comment - W8202 +# wrong-tabs-instead-of-spaces - W7910 +# xml-syntax-error - E7902 + + +enable=anomalous-backslash-in-string, + assignment-from-none, + dangerous-default-value, + development-status-allowed, + duplicate-key, + duplicate-po-message-definition, + missing-import-error, + missing-manifest-dependency, + po-msgstr-variables, + po-syntax-error, + pointless-statement, + pointless-string-statement, + print-used, + redundant-keyword-arg, + reimported, + relative-import, + return-in-init, + rst-syntax-error, + too-few-format-args, + unreachable, + eval-used, + eval-referenced, + license-allowed, + manifest-author-string, + manifest-required-author, + manifest-required-key, + manifest-version-format, + api-one-deprecated, + api-one-multi-together, + attribute-deprecated, + class-camelcase, + create-user-wo-reset-password, + consider-merging-classes-inherited, + copy-wo-api-one, + dangerous-filter-wo-user, + dangerous-view-replace-wo-priority, + deprecated-module, + duplicate-id-csv, + duplicate-po-message-definition, + duplicate-xml-fields, + duplicate-xml-record-id, + file-not-used, + incoherent-interpreter-exec-perm, + invalid-commit, + javascript-lint, + manifest-deprecated-key, + method-compute, + method-inverse, + method-required-super, + method-search, + missing-newline-extrafiles, + missing-readme, + po-msgstr-variables, + po-syntax-error, + no-utf8-coding-comment, + unnecessary-utf8-coding-comment, + odoo-addons-relative-import, + old-api7-method-defined, + openerp-exception-warning, + redefined-builtin, + redundant-modulename-xml, + sql-injection, + too-complex, + translation-field, + translation-required, + use-vim-comment, + wrong-tabs-instead-of-spaces, + xml-syntax-error, + + +[REPORTS] +msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} +output-format=colorized +reports=no diff --git a/.pylintrc-mandatory b/.pylintrc-mandatory new file mode 100644 index 00000000..3a1427de --- /dev/null +++ b/.pylintrc-mandatory @@ -0,0 +1,67 @@ +[MASTER] +load-plugins=pylint_odoo +score=n + +[ODOOLINT] +readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" +manifest_required_authors=Odoo Community Association (OCA) +manifest_required_keys=license +manifest_deprecated_keys=description,active +license_allowed=AGPL-3,GPL-2,GPL-2 or any later version,GPL-3,GPL-3 or any later version,LGPL-3 +valid_odoo_versions=12.0 + +[MESSAGES CONTROL] +disable=all + +# Enable message and code: +# anomalous-backslash-in-string - W1401 +# assignment-from-none - W1111 +# dangerous-default-value - W0102 +# duplicate-key - W0109 +# missing-import-error - W7935 +# missing-manifest-dependency - W7936 +# pointless-statement - W0104 +# pointless-string-statement - W0105 +# print-statement - E1601 +# redundant-keyword-arg - E1124 +# reimported - W0404 +# relative-import - W0403 +# return-in-init - E0101 +# rst-syntax-error - E7901 +# too-few-format-args - E1306 +# unreachable - W0101 + + + +enable=anomalous-backslash-in-string, + assignment-from-none, + dangerous-default-value, + development-status-allowed, + duplicate-key, + duplicate-po-message-definition, + missing-import-error, + missing-manifest-dependency, + po-msgstr-variables, + po-syntax-error, + pointless-statement, + pointless-string-statement, + print-used, + redundant-keyword-arg, + reimported, + relative-import, + return-in-init, + rst-syntax-error, + too-few-format-args, + unreachable, + eval-used, + eval-referenced, + license-allowed, + manifest-author-string, + manifest-required-author, + manifest-required-key, + manifest-version-format + +[REPORTS] +msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} +output-format=colorized +reports=no