diff --git a/.travis.yml b/.travis.yml index 6f3b974b7..1bb3814df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,14 +31,16 @@ env: - INCLUDE="test_module,second_module" UNIT_TEST="1" - VERSION="7.0" INCLUDE="test_module,second_module" ODOO_REPO="OCA/OCB" # ODOO_REPO usage example - VERSION="6.1" INCLUDE="test_module,second_module" - - LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="17" TRAVIS_PULL_REQUEST="false" # Use main pylint config file - - LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="18" TRAVIS_PULL_REQUEST="true" # Use PR pylint config file + - LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="18" TRAVIS_PULL_REQUEST="false" # Use main pylint config file + - VERSION=master LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="18" TRAVIS_PULL_REQUEST="true" # Use PR pylint config file + - VERSION="7.0" LINT_CHECK="1" TESTS="0" PYLINT_EXPECTED_ERRORS="18" TRAVIS_PULL_REQUEST="true" # To check pylint_conf of PR's with old api install: - cp -r ../maintainer-quality-tools/ $HOME - mv tests/test_repo/* ./ - export PATH=$HOME/maintainer-quality-tools/travis:$PATH - travis_install_nightly 8.0 # only used if VERSION not set in env + - git --git-dir=${TRAVIS_BUILD_DIR}/.git add --all # All modules moved are modules changed to test PR changes script: - coverage run --append ./travis/self_tests diff --git a/tests/test_repo/broken_lint/__init__.py b/tests/test_repo/broken_lint/__init__.py new file mode 100644 index 000000000..dbba1fc56 --- /dev/null +++ b/tests/test_repo/broken_lint/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import case_import diff --git a/tests/test_repo/broken_lint/__openerp__.py b/tests/test_repo/broken_lint/__openerp__.py new file mode 100644 index 000000000..0cfd8f089 --- /dev/null +++ b/tests/test_repo/broken_lint/__openerp__.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +{ + 'name': 'Broken module for lint tests', + 'license': 'AGPL-3', + 'author': 'Odoo Community Association (OCA)', + 'version': '1.0', + 'depends': [], + 'data': [], + 'test': [], + 'installable': False, +} diff --git a/tests/test_repo/broken_lint/case_import.py b/tests/test_repo/broken_lint/case_import.py new file mode 100644 index 000000000..e553aca8d --- /dev/null +++ b/tests/test_repo/broken_lint/case_import.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +import openerp + +from openerp import api +from openerp.api import one + +from openerp.exceptions import Warning as UserError +from openerp.exceptions import Warning as OtherName +from openerp.exceptions import Warning +from openerp.exceptions import AccessError as AE, \ + ValidationError, Warning as UserError2 + + +class UseUnusedImport(object): + def method1(self): + return UserError, OtherName, Warning, AE, ValidationError, UserError2 + + +class ApiOne(object): + @api.one + def copy(): + pass + + +class One(object): + @one + def copy(): + pass + + +class OpenerpApiOne(object): + @openerp.api.one + def copy(): + pass + + +class WOApiOne(object): + # copy without api.one decorator + def copy(): + pass + + +class ApiOneMultiTogether(object): + + @api.multi + @api.one + def copy(): + pass diff --git a/tests/test_repo/broken_module/README.rst b/tests/test_repo/broken_module/README.rst new file mode 100644 index 000000000..caf2e50c7 --- /dev/null +++ b/tests/test_repo/broken_module/README.rst @@ -0,0 +1,4 @@ +Module broken +=============== +`````````` +syntax error diff --git a/tests/test_repo/broken_module/__init__.py b/tests/test_repo/broken_module/__init__.py index f3fc39f79..efcda3c3b 100644 --- a/tests/test_repo/broken_module/__init__.py +++ b/tests/test_repo/broken_module/__init__.py @@ -1,2 +1,5 @@ -# -*- coding: utf-8 -*- +#!/usr/bin/python +# -*- coding: latin-1 -*- from . import model +from . import interpreter_wox +# execution permission and interpreter done diff --git a/tests/test_repo/broken_module/__openerp__.py b/tests/test_repo/broken_module/__openerp__.py index 4930c48d3..663d793cf 100644 --- a/tests/test_repo/broken_module/__openerp__.py +++ b/tests/test_repo/broken_module/__openerp__.py @@ -1,9 +1,14 @@ # -*- coding: utf-8 -*- { 'name': 'Broken module for tests', + # missing license + 'author': 'Many People', # Missing oca author + 'description': 'Should be a README.rst file', 'version': '1.0', 'depends': ['base'], - 'data': [], + 'data': ['model_view.xml'], 'test': ['test.yml'], 'installable': True, + 'name': 'Duplicated value', + 'active': True, # Deprecated active key } diff --git a/tests/test_repo/broken_module/doc/index.rst b/tests/test_repo/broken_module/doc/index.rst new file mode 100644 index 000000000..caf2e50c7 --- /dev/null +++ b/tests/test_repo/broken_module/doc/index.rst @@ -0,0 +1,4 @@ +Module broken +=============== +`````````` +syntax error diff --git a/tests/test_repo/broken_module/interpreter_wox.py b/tests/test_repo/broken_module/interpreter_wox.py new file mode 100755 index 000000000..188711aa1 --- /dev/null +++ b/tests/test_repo/broken_module/interpreter_wox.py @@ -0,0 +1,5 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + + +"Module python with interpreter but without execute permission." diff --git a/tests/test_repo/broken_module/ipdb.py b/tests/test_repo/broken_module/ipdb.py index 919b22fe9..e99e5319d 100644 --- a/tests/test_repo/broken_module/ipdb.py +++ b/tests/test_repo/broken_module/ipdb.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- # W0402(deprecated-module) require module present diff --git a/tests/test_repo/broken_module/model.py b/tests/test_repo/broken_module/model.py old mode 100644 new mode 100755 index dd1fac83b..2118418a3 --- a/tests/test_repo/broken_module/model.py +++ b/tests/test_repo/broken_module/model.py @@ -1,4 +1,4 @@ - +# missing coding from openerp.osv import orm, fields import os @@ -70,3 +70,5 @@ def method_w1111(): class E0101(object): def __init__(self): return 'E0101' + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/tests/test_repo/broken_module/model_view.xml b/tests/test_repo/broken_module/model_view.xml new file mode 100644 index 000000000..1b85c1db0 --- /dev/null +++ b/tests/test_repo/broken_module/model_view.xml @@ -0,0 +1,33 @@ + + + + + + view.model.form + test.model + +
+ + +
+
+ + + view.model.form + test.model + + + + + + + + + + By name + test.model + {'group_by': ['name']} + + +
+
diff --git a/tests/test_repo/broken_module/pdb.py b/tests/test_repo/broken_module/pdb.py index 919b22fe9..e99e5319d 100644 --- a/tests/test_repo/broken_module/pdb.py +++ b/tests/test_repo/broken_module/pdb.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- # W0402(deprecated-module) require module present diff --git a/tests/test_repo/broken_module/pudb.py b/tests/test_repo/broken_module/pudb.py index 919b22fe9..e99e5319d 100644 --- a/tests/test_repo/broken_module/pudb.py +++ b/tests/test_repo/broken_module/pudb.py @@ -1 +1,2 @@ +# -*- coding: utf-8 -*- # W0402(deprecated-module) require module present diff --git a/tests/test_repo/broken_module/tests/__init__.py b/tests/test_repo/broken_module/tests/__init__.py new file mode 100644 index 000000000..e0bb3a28b --- /dev/null +++ b/tests/test_repo/broken_module/tests/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import dummy_test diff --git a/tests/test_repo/broken_module/tests/dummy_test.py b/tests/test_repo/broken_module/tests/dummy_test.py new file mode 100644 index 000000000..273bb8738 --- /dev/null +++ b/tests/test_repo/broken_module/tests/dummy_test.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# missing coding +"""This file is not added to main __init__ +We need to validate that check py errors""" + +try: + from openerp.exceptions import Warning +except ImportError: + pass + + +def using_imported(): + return Warning diff --git a/tests/test_repo/second_module/__openerp__.py b/tests/test_repo/second_module/__openerp__.py index a0652d4f3..4af221b52 100644 --- a/tests/test_repo/second_module/__openerp__.py +++ b/tests/test_repo/second_module/__openerp__.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- { 'name': 'Second empty module for tests', - 'version': '1.0', + 'version': '8.0.1.0.0', + 'author': 'Odoo Community Association (OCA)', + 'license': 'AGPL-3', 'depends': [ 'base', 'test_module', diff --git a/tests/test_repo/test_module/README.rst b/tests/test_repo/test_module/README.rst new file mode 100644 index 000000000..d00cd1be4 --- /dev/null +++ b/tests/test_repo/test_module/README.rst @@ -0,0 +1,9 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Test module +=========== + +This module was written to check the test of rst syntax. +This is a rst file without syntax error. + diff --git a/tests/test_repo/test_module/__openerp__.py b/tests/test_repo/test_module/__openerp__.py index 27124ec04..1656d77fa 100644 --- a/tests/test_repo/test_module/__openerp__.py +++ b/tests/test_repo/test_module/__openerp__.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- { 'name': 'Empty module for tests', + 'license': 'AGPL-3', + 'author': 'Odoo Community Association (OCA)', 'version': '1.0', 'depends': [ 'base', diff --git a/tests/test_repo/test_module/doc/index.rst b/tests/test_repo/test_module/doc/index.rst new file mode 100644 index 000000000..d00cd1be4 --- /dev/null +++ b/tests/test_repo/test_module/doc/index.rst @@ -0,0 +1,9 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 + +Test module +=========== + +This module was written to check the test of rst syntax. +This is a rst file without syntax error. + diff --git a/tests/test_repo/test_module/static/description/icon.png b/tests/test_repo/test_module/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/tests/test_repo/test_module/static/description/icon.png differ diff --git a/travis/cfg/travis_run_pylint.cfg b/travis/cfg/travis_run_pylint.cfg index 1caa9cd0d..a68ec2567 100644 --- a/travis/cfg/travis_run_pylint.cfg +++ b/travis/cfg/travis_run_pylint.cfg @@ -1,6 +1,6 @@ [MASTER] profile=no -ignore=CVS,.git,scenarios,.bzr,__openerp__.py,__odoo__.py,__terp__.py +ignore=CVS,.git,scenarios,.bzr persistent=yes cache-size=500 diff --git a/travis/cfg/travis_run_pylint_61.cfg b/travis/cfg/travis_run_pylint_61.cfg new file mode 100644 index 000000000..6784e2433 --- /dev/null +++ b/travis/cfg/travis_run_pylint_61.cfg @@ -0,0 +1,21 @@ +# This config file not is a real pylint config file. +# This file overwrite params of base template. + +[ODOOLINT] +manifest_deprecated_keys= + +[MESSAGES CONTROL] +# Disable message and code: +# copy-wo-api-one - W8102 +# class-camelcase - C8104 +# missing-readme - C7902 +# openerp-exception-warning - R8101 + +disable=copy-wo-api-one, + class-camelcase, + missing-readme, + openerp-exception-warning, + +[IMPORTS] +deprecated-modules=pdb,pudb,ipdb + diff --git a/travis/cfg/travis_run_pylint_70.cfg b/travis/cfg/travis_run_pylint_70.cfg new file mode 100644 index 000000000..6784e2433 --- /dev/null +++ b/travis/cfg/travis_run_pylint_70.cfg @@ -0,0 +1,21 @@ +# This config file not is a real pylint config file. +# This file overwrite params of base template. + +[ODOOLINT] +manifest_deprecated_keys= + +[MESSAGES CONTROL] +# Disable message and code: +# copy-wo-api-one - W8102 +# class-camelcase - C8104 +# missing-readme - C7902 +# openerp-exception-warning - R8101 + +disable=copy-wo-api-one, + class-camelcase, + missing-readme, + openerp-exception-warning, + +[IMPORTS] +deprecated-modules=pdb,pudb,ipdb + diff --git a/travis/cfg/travis_run_pylint_pr.cfg b/travis/cfg/travis_run_pylint_pr.cfg index 1f32c3a44..187db292c 100644 --- a/travis/cfg/travis_run_pylint_pr.cfg +++ b/travis/cfg/travis_run_pylint_pr.cfg @@ -1,14 +1,48 @@ [MASTER] profile=no -ignore=CVS,.git,scenarios,.bzr,__openerp__.py,__odoo__.py,__terp__.py +ignore=CVS,.git,scenarios,.bzr persistent=yes cache-size=500 +[ODOOLINT] +readme_template_url="https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst" +manifest_required_author="Odoo Community Association (OCA)" +manifest_required_keys=license +manifest_deprecated_keys=description,active + [MESSAGES CONTROL] disable=all -# This change don't add new checks. -# Adding one exits check to test the pr-diff feature -enable=W0403 + +# Enable message and code: +# api-one-multi-together - W8101 +# class-camelcase - C8104 +# copy-wo-api-one - W8102 +# dangerous-filter-wo-user - W7901 +# duplicate-xml-record-id - W7902 +# incoherent-interpreter-exec-perm - W8201 +# manifest-deprecated-key - C8103 +# manifest-required-author - C8101 +# manifest-required-key - C8102 +# missing-readme - C7902 +# no-utf8-coding-comment - C8201 +# openerp-exception-warning - R8101 +# rst-syntax-error - E7901 +# use-vim-comment - W8202 + +enable=api-one-multi-together, + class-camelcase, + copy-wo-api-one, + dangerous-filter-wo-user, + duplicate-xml-record-id, + incoherent-interpreter-exec-perm, + manifest-deprecated-key, + manifest-required-author, + manifest-required-key, + missing-readme, + no-utf8-coding-comment, + openerp-exception-warning, + rst-syntax-error, + use-vim-comment, [REPORTS] msg-template={path}:{line}: [{msg_id}({symbol}), {obj}] {msg} diff --git a/travis/run_pylint.py b/travis/run_pylint.py index b20629eec..d07f94e2d 100755 --- a/travis/run_pylint.py +++ b/travis/run_pylint.py @@ -62,8 +62,8 @@ def run_pylint(paths, cfg, sys_paths=None, extra_params=None): cmd.extend(extra_params) subpaths = get_subpaths(paths) if not subpaths: - raise ValueError("Python modules not found in paths" - " {paths}".format(paths=paths)) + raise UserWarning("Python modules not found in paths" + " {paths}".format(paths=paths)) cmd.extend(subpaths) pylint_res = pylint.lint.Run(cmd, exit=False) return pylint_res.linter.stats @@ -92,7 +92,7 @@ def main(paths, config_file, sys_paths=None, extra_params=None): list(paths), config_file.name, sys_paths=sys_paths, extra_params=extra_params) count_fails = get_count_fails(stats) - except ValueError: + except UserWarning: count_fails = -1 return count_fails diff --git a/travis/self_tests b/travis/self_tests index 1832359cb..ca954f22e 100755 --- a/travis/self_tests +++ b/travis/self_tests @@ -44,7 +44,7 @@ if os.environ.get('LINT_CHECK', 0) == '1': "--extra-params", "-d", "--extra-params", "all", "--extra-params", "-e", "--extra-params", "F0010,duplicate-key", "--path", repo_dir], standalone_mode=False) - assert 1 == count_errors + assert 2 == count_errors empty_path = os.path.join(repo_dir, 'empty_path') if not os.path.exists(empty_path): diff --git a/travis/test_pylint b/travis/test_pylint index 967373b86..aca2ca005 100755 --- a/travis/test_pylint +++ b/travis/test_pylint @@ -6,20 +6,83 @@ Script to process pylint run and exit with result. """ import os +import ConfigParser import run_pylint import travis_helpers from getaddons import get_modules_changed + +def get_extra_params(odoo_version): + '''Get extra pylint params by odoo version + Transform a seudo-pylint-conf to params, + it to overwrite base-pylint-conf values. + Use a seudo-inherit of configuration file. + To avoid have a 2 config files (stable and pr-conf) by each odoo-version + Example: + + pylint_master.conf + pylint_master_pr.conf + pylint_90.conf + pylint_90_pr.conf + pylint_80.conf + pylint_80_pr.conf + pylint_70.conf + pylint_70_pr.conf + pylint_61.conf + pylint_61_pr.conf + ... and new future versions. + + If you need add a new conventions in all versions + you will need change all pr files or stables files. + + + With this method you can use: + + pylint_lastest.conf + pylint_lastest_pr.conf + pylint_disabling_70.conf <- Overwrite params of pylint_lastest*.conf + pylint_disabling_61.conf <- Overwrite params of pylint_lastest*.conf + + If you need add a new conventions in all versions you will need change just + pylint_lastest_pr.conf or pylint_lastest.conf, similar to inherit. + + :param version: String with name of version of odoo + :return: List of extra pylint params + ''' + params = ["--load-plugins=pylint_oca"] + odoo_version = odoo_version.replace('.', '') + custom_cfg = os.path.join( + os.path.dirname(os.path.realpath(__file__)), + 'cfg/travis_run_pylint_{odoo_version}.cfg'.format( + odoo_version=odoo_version)) + if os.path.isfile(custom_cfg): + config = ConfigParser.ConfigParser() + config.readfp(open(custom_cfg)) + for section in config.sections(): + for option, value in config.items(section): + params.extend(['--' + option, value]) + return params + + +version = os.environ.get('VERSION', False) +extra_params_cmd = [] +if version: + extra_params = get_extra_params(version) + for extra_param in extra_params: + extra_params_cmd.extend([ + '--extra-params', extra_param + ]) + + pylint_rcfile = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'cfg', "travis_run_pylint.cfg") count_errors = run_pylint.main([ "--config-file=" + pylint_rcfile, -], standalone_mode=False) - + ] + extra_params_cmd, standalone_mode=False) pylint_rcfile_pr = os.path.join( os.path.dirname(os.path.realpath(__file__)), @@ -30,23 +93,40 @@ is_pull_request = os.environ.get( 'TRAVIS_PULL_REQUEST', 'false') != 'false' branch_base = os.environ.get('TRAVIS_BRANCH', False) git_work_dir = os.environ.get('TRAVIS_BUILD_DIR', False) + + if is_pull_request and branch_base and git_work_dir: modules_changed = get_modules_changed( git_work_dir, 'origin/' + branch_base) - modules_changed_cmd = [] - for module_changed in modules_changed: - modules_changed_cmd.extend([ - '--path', - module_changed, - ]) - count_errors += run_pylint.main([ - "--config-file=" + pylint_rcfile_pr, - ] + modules_changed_cmd, standalone_mode=False) + if modules_changed and count_errors >= 0: + print(travis_helpers.green( + 'Start lint check just in modules changed')) + modules_changed_cmd = [] + for module_changed in modules_changed: + modules_changed_cmd.extend([ + '--path', + module_changed, + ]) + pr_errors = run_pylint.main([ + "--config-file=" + pylint_rcfile_pr, + ] + modules_changed_cmd + extra_params_cmd, standalone_mode=False) + if pr_errors: + print(travis_helpers.yellow( + "Found {pr_errors} errors".format(pr_errors=pr_errors) + + " in modules changed." + "\nThese checks are still in beta:" + " they won't affect your build status for now." + )) + pr_errors = 0 + # TODO: Enable next code when change of beta to stable version + # if pr_errors < 0: + # count_errors = pr_errors + # else: + # count_errors += pr_errors else: # TODO: Add git hook case in other PR pass - expected_errors = int( os.environ.get('PYLINT_EXPECTED_ERRORS', 0)) diff --git a/travis/travis_install_nightly b/travis/travis_install_nightly index 28c8f55bf..0fd8a4460 100755 --- a/travis/travis_install_nightly +++ b/travis/travis_install_nightly @@ -1,6 +1,6 @@ #!/bin/bash -pip install -q QUnitSuite flake8 coveralls pylint Click > /dev/null 2>&1 +pip install -q QUnitSuite flake8 coveralls Click oca-pylint-plugin > /dev/null 2>&1 # We can exit here and do nothing if this only a LINT check if [ "${LINT_CHECK}" == "1" ] ; then