[pitivi] Use pylint in the pre commit hook
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Use pylint in the pre commit hook
- Date: Wed, 10 Feb 2016 09:04:46 +0000 (UTC)
commit e24b6764372041181e999d6e62a4eb43683822b7
Author: Thibault Saunier <tsaunier gnome org>
Date: Tue Feb 9 18:40:00 2016 +0100
Use pylint in the pre commit hook
Modernizing our old pylint.rc file
Reviewed-by: Alex Băluț <alexandru balut gmail com>
Differential Revision: https://phabricator.freedesktop.org/D754
docs/pylint.rc | 151 +++++-------------------------------------------------
pre-commit.hook | 68 ++-----------------------
2 files changed, 18 insertions(+), 201 deletions(-)
---
diff --git a/docs/pylint.rc b/docs/pylint.rc
index 7a0cde9..d1b05aa 100644
--- a/docs/pylint.rc
+++ b/docs/pylint.rc
@@ -1,151 +1,30 @@
# lint Python modules using external checkers.
-#
+#
# This is the main checker controling the other ones and the reports
# generation. It is itself both a raw checker and an astng checker in order
# to:
# * handle message activation / deactivation at the module level
# * handle some basic but necessary stats'data (number of classes, methods...)
-#
+#
[MASTER]
-# Specify a configuration file.
-#rcfile=
-
# Python code to execute, usually for sys.path manipulation such as
-# pygtk.require().
-#init-hook=
-
-# Profiled execution.
-profile=no
-
-# Add <file or directory> to the black list. It should be a base name, not a
-# path. You may set this option multiple times.
-ignore=CVS
-
-# Pickle collected data for later comparisons.
-persistent=yes
-
-# Set the cache size for astng objects.
-cache-size=500
-
-# List of plugins (as comma separated values of python modules names) to load,
-# usually to register additional checkers.
-load-plugins=
-
+init-hook='import gi; gi.require_version("Gtk", "3.0"); gi.require_version("Gst", "1.0"); from gi.repository
import Gst; Gst.init(None); gi.require_version("GES", "1.0"); from gi.repository import GES; GES.init()'
[MESSAGES CONTROL]
-# Enable only checker(s) with the given id(s). This option conflicts with the
-# disable-checker option
-#enable-checker=
-
-# Enable all checker(s) except those with the given id(s). This option
-# conflicts with the enable-checker option
-#disable-checker=
-
-# Enable all messages in the listed categories.
-#enable-msg-cat=
-
-# Disable all messages in the listed categories.
-#disable-msg-cat=
-
-# Enable the message(s) with the given id(s).
-#enable-msg=
-
# Disable the message(s) with the given id(s).
-disable-msg=E1101,W0142
-
-
-[REPORTS]
-
-# set the output format. Available formats are text, parseable, colorized, msvs
-# (visual studio) and html
-output-format=text
-
-# Include message's id in output
-include-ids=yes
-
-# Put messages in a separate file for each module / package specified on the
-# command line instead of printing them on stdout. Reports (if any) will be
-# written in a file name "pylint_global.[txt|html]".
-files-output=no
-
-# Tells wether to display a full report or only the messages
-reports=yes
+disable=E1101,W0142,locally-disabled,fixme,superfluous-parens
-# Python expression which should return a note less than 10 (10 is the highest
-# note).You have access to the variables errors warning, statement which
-# respectivly contain the number of errors / warnings messages and the total
-# number of statements analyzed. This is used by the global evaluation report
-# (R0004).
-evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
-# Add a comment according to your evaluation note. This is used by the global
-# evaluation report (R0004).
-comment=no
-
-# Enable the report(s) with the given id(s).
-#enable-report=
-
-# Disable the report(s) with the given id(s).
-#disable-report=
-
-
-# checks for
-# * unused variables / imports
-# * undefined variables
-# * redefinition of variable from builtins or from an outer scope
-# * use of variable before assigment
-#
[VARIABLES]
-# Tells wether we should check for unused import in __init__ files.
-init-import=no
-
# A regular expression matching names used for dummy variables (i.e. not used).
dummy-variables-rgx=_|dummy|unused_.*
-# List of additional names supposed to be defined in builtins. Remember that
-# you should avoid to define new builtins when possible.
-additional-builtins=
-
-
-# try to find bugs in the code using type inference
-#
-[TYPECHECK]
-
-# Tells wether missing members accessed in mixin class should be ignored. A
-# mixin class is detected if its name ends with "mixin" (case insensitive).
-ignore-mixin-members=yes
-# List of classes names for which member attributes should not be checked
-# (useful for classes with attributes dynamicaly set).
-ignored-classes=SQLObject
-
-# When zope mode is activated, consider the acquired-members option to ignore
-# access to some undefined attributes.
-zope=no
-
-# List of members which are usually get through zope's acquisition mecanism and
-# so shouldn't trigger E0201 when accessed (need zope=yes to be considered).
-acquired-members=REQUEST,acl_users,aq_parent
-
-
-# checks for :
-# * doc strings
-# * modules / classes / functions / methods / arguments / variables name
-# * number of arguments, local variables, branchs, returns and statements in
-# functions, methods
-# * required module attributes
-# * dangerous default values as arguments
-# * redefinition of function / method / class
-# * uses of the global statement
-#
[BASIC]
-# Required attributes for module, separated by a comma
-required-attributes=
-
# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=((_.*)|(do_.*))
@@ -165,6 +44,9 @@ function-rgx=[a-z_][a-z0-9_]{2,30}$
# Regular expression which should only match correct method names
method-rgx=[a-z_][a-zA-Z0-9_]{2,30}$
+# Naming hint for method names
+method-name-hint=[a-z_][a-zA-Z0-9_]{2,30}$
+
# Regular expression which should only match correct instance attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$
@@ -179,7 +61,7 @@ variable-rgx=[a-z_][a-z0-9_]{1,30}$
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$
# Good variable names which should always be accepted, separated by a comma
-good-names=i,j,k,ex,Run,_
+good-names=x,y,z,i,j,k,ex,Run,_
# Bad variable names which should always be refused, separated by a comma
bad-names=foo,bar,baz,toto,tutu,tata
@@ -191,7 +73,7 @@ bad-functions=map,filter,apply,input
# checks for sign of poor/misdesign:
# * number of methods, attributes, local variables...
# * size, complexity of functions, methods
-#
+#
[DESIGN]
# Maximum number of arguments for function / method
@@ -227,7 +109,7 @@ max-public-methods=20
# * relative / wildcard imports
# * cyclic imports
# * uses of deprecated modules
-#
+#
[IMPORTS]
# Deprecated modules which should not be used, separated by a comma
@@ -253,21 +135,16 @@ int-import-graph=
# * attributes not defined in the __init__ method
# * supported interfaces implementation
# * unreachable code
-#
+#
[CLASSES]
-# List of interface methods to ignore, separated by a comma. This is used for
-# instance to not check methods defines in Zope's Interface base class.
-ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
-
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,__new__,setUp,_reset,_createUi,_addSource
-
# checks for similarities and duplicated code. This computation may be
# memory / CPU intensive, so you should disable it if you experiments some
# problems.
-#
+#
[SIMILARITIES]
# Minimum lines number of a similarity.
@@ -283,7 +160,7 @@ ignore-docstrings=yes
# checks for:
# * warning notes in the code like FIXME, XXX
# * PEP 263: source code with non ascii character but no encoding declaration
-#
+#
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
@@ -295,7 +172,7 @@ notes=FIXME,XXX,TODO
# * strict indentation
# * line length
# * use of <> instead of !=
-#
+#
[FORMAT]
# Maximum number of characters on a single line.
diff --git a/pre-commit.hook b/pre-commit.hook
index 3e3a93e..2abbc12 100755
--- a/pre-commit.hook
+++ b/pre-commit.hook
@@ -1,65 +1,5 @@
-#!/usr/bin/env python3
-import os
-import shutil
-import subprocess
-import sys
-import tempfile
+#!/usr/bin/env bash
-
-def system(*args, **kwargs):
- kwargs.setdefault('stdout', subprocess.PIPE)
- proc = subprocess.Popen(args, **kwargs)
- out, err = proc.communicate()
- if type(out) == bytes:
- out = out.decode()
- return out
-
-
-def copy_files_to_tmp_dir(files):
- tempdir = tempfile.mkdtemp()
- for name in files:
- filename = os.path.join(tempdir, name)
- filepath = os.path.dirname(filename)
- if not os.path.exists(filepath):
- os.makedirs(filepath)
- with open(filename, 'w') as f:
- system('git', 'show', ':' + name, stdout=f)
-
- return tempdir
-
-
-def main():
- modified_files = system('git', 'diff-index', '--cached',
- '--name-only', 'HEAD', '--diff-filter=ACMR').split("\n")[:-1]
- output_message = None
-
- tempdir = copy_files_to_tmp_dir(modified_files)
- try:
- pep8_errors = system('pep8', '--repeat', '--ignore', 'E501,E128', '.',
- cwd=tempdir)
- if pep8_errors:
- output_message = "Your code is not fully pep8 compliant and contains"\
- " the following coding style issues:\n\n" + pep8_errors +\
- "\n"\
- "We encourage you to use\n\n $autopep8 -i file/with/pep8/error.py\n\n"\
- "\n"\
- "Thanks for correcting them before commiting!\n"
- except OSError:
- output_message = "You should install the pep8 style checker to be able"\
- " to commit in this repo.\nIt allows us to garantee that "\
- "anything that is commited respects the pep8 coding style "\
- "standard.\nYou can install it:\n"\
- " * on ubuntu, debian: $sudo apt-get install pep8 \n"\
- " * on fedora: #yum install python-pep8 \n"\
- " * on arch: #pacman -S pep8-python3 \n"\
- " * or add the official pep8 from http://www.python.org/dev/peps/pep-0008/"\
- " in your $PATH"
-
- shutil.rmtree(tempdir)
- if output_message:
- print(output_message, end=' ')
- sys.exit(1)
-
-
-if __name__ == '__main__':
- main()
+RCFILE=$(git rev-parse --show-toplevel)/docs/pylint.rc
+git-pylint-commit-hook --pylintrc=$RCFILE --limit=10.0 --suppress-report &&\
+ git_pep8_commit_hook --pep8-params="--repeat --ignore=E501,E128"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]