Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

[ADD] pylint_oca: Add pylint plugin script to check OCA guidelines #234

Merged
merged 3 commits into from
Sep 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/test_repo/broken_lint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import case_import
11 changes: 11 additions & 0 deletions tests/test_repo/broken_lint/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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,
}
49 changes: 49 additions & 0 deletions tests/test_repo/broken_lint/case_import.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/test_repo/broken_module/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Module broken
===============
``````````
syntax error
5 changes: 4 additions & 1 deletion tests/test_repo/broken_module/__init__.py
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion tests/test_repo/broken_module/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions tests/test_repo/broken_module/doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Module broken
===============
``````````
syntax error
5 changes: 5 additions & 0 deletions tests/test_repo/broken_module/interpreter_wox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-


"Module python with interpreter but without execute permission."
1 change: 1 addition & 0 deletions tests/test_repo/broken_module/ipdb.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# -*- coding: utf-8 -*-
# W0402(deprecated-module) require module present
4 changes: 3 additions & 1 deletion tests/test_repo/broken_module/model.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# missing coding
from openerp.osv import orm, fields

import os
Expand Down Expand Up @@ -70,3 +70,5 @@ def method_w1111():
class E0101(object):
def __init__(self):
return 'E0101'

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
33 changes: 33 additions & 0 deletions tests/test_repo/broken_module/model_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="view_model_form" model="ir.ui.view">
<field name="name">view.model.form</field>
<field name="model">test.model</field>
<field name="arch" type="xml">
<form string="Test model">
<field name="name"/>
</form>
</field>
</record>
<!-- duplicate record id-->
<record id="view_model_form" model="ir.ui.view">
<field name="name">view.model.form</field>
<field name="model">test.model</field>
<field name="arch" type="xml">
<tree string="Test model">
<field name="name"/>
</tree>
</field>
</record>

<!--ir.filters without explicit user_id-->
<record id="filter_test_model" model="ir.filters">
<field name="name">By name</field>
<field name="model_id">test.model</field>
<field name="context">{'group_by': ['name']}</field>
</record>

</data>
</openerp>
1 change: 1 addition & 0 deletions tests/test_repo/broken_module/pdb.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# -*- coding: utf-8 -*-
# W0402(deprecated-module) require module present
1 change: 1 addition & 0 deletions tests/test_repo/broken_module/pudb.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# -*- coding: utf-8 -*-
# W0402(deprecated-module) require module present
2 changes: 2 additions & 0 deletions tests/test_repo/broken_module/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import dummy_test
13 changes: 13 additions & 0 deletions tests/test_repo/broken_module/tests/dummy_test.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion tests/test_repo/second_module/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
9 changes: 9 additions & 0 deletions tests/test_repo/test_module/README.rst
Original file line number Diff line number Diff line change
@@ -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.

2 changes: 2 additions & 0 deletions tests/test_repo/test_module/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
9 changes: 9 additions & 0 deletions tests/test_repo/test_module/doc/index.rst
Original file line number Diff line number Diff line change
@@ -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.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion travis/cfg/travis_run_pylint.cfg
Original file line number Diff line number Diff line change
@@ -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

Expand Down
21 changes: 21 additions & 0 deletions travis/cfg/travis_run_pylint_61.cfg
Original file line number Diff line number Diff line change
@@ -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

21 changes: 21 additions & 0 deletions travis/cfg/travis_run_pylint_70.cfg
Original file line number Diff line number Diff line change
@@ -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

42 changes: 38 additions & 4 deletions travis/cfg/travis_run_pylint_pr.cfg
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
6 changes: 3 additions & 3 deletions travis/run_pylint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion travis/self_tests
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading