From 81c7be88b255f51c76304abb79c06e1b5c594d0f Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 6 Apr 2023 09:25:15 +1000 Subject: [PATCH] Improve `pylintrc`. - Move it to `auxprogs/`, alongside `pybuild.sh`. - Disable the annoying design lints, instead of just modifying the values (which often requires modifying them again later). --- auxprogs/pybuild.sh | 7 +++--- auxprogs/pylintrc | 28 +++++++++++++++++++++ cachegrind/Makefile.am | 6 ++--- cachegrind/cg_annotate.in | 4 +-- cachegrind/pylintrc | 53 --------------------------------------- 5 files changed, 37 insertions(+), 61 deletions(-) create mode 100644 auxprogs/pylintrc delete mode 100644 cachegrind/pylintrc diff --git a/auxprogs/pybuild.sh b/auxprogs/pybuild.sh index 432a768c51..371189a68f 100755 --- a/auxprogs/pybuild.sh +++ b/auxprogs/pybuild.sh @@ -44,8 +44,9 @@ set -e ver=3.9 pyver=py39 -infile=$1 -outfile=$2 +auxprogs=$1 +infile=$2 +outfile=$3 if [ -z "$outfile" ] ; then exit 1 fi @@ -80,7 +81,7 @@ ruff check --target-version $pyver $infile echo echo "== pylint ==" -pylint --py-version $ver $infile +pylint --rcfile=$auxprogs/pylintrc --py-version $ver $infile echo "== config.status ==" make $outfile diff --git a/auxprogs/pylintrc b/auxprogs/pylintrc new file mode 100644 index 0000000000..8f51d2d686 --- /dev/null +++ b/auxprogs/pylintrc @@ -0,0 +1,28 @@ +# How to create this file. +# - Generate with `pylint --generate-rcfile > pylintrc`. Do this in a directory +# that doesn't already contain a `pylintrc` file, because the output is +# affected by any existing `pylintrc` file. +# - Then modify entries resulting in unreasonable warnings. +# - If a lint is never interesting, add it to the `disable=` list with an +# explanatory comment. +# - If a lint is interesting but needs modification, comment out the original +# value, add a new value along with an explanatory comment. +# - Remove all non-modified entries. + +[MESSAGES CONTROL] + +disable= + # We don't care about having docstrings for all functions/classes. + missing-class-docstring, missing-function-docstring, + # We don't care about large functions, sometimes it's necessary. + too-many-branches, too-many-locals, too-many-statements, + # Zero or one public methods in a class is fine. + too-few-public-methods, + +[BASIC] + +# Good variable names regexes, separated by a comma. If names match any regex, +# they will always be accepted +#good-names-rgxs= +# We allow any lower-case variable name of length 1 or 2. +good-names-rgxs=\b[a-z]\b,\b[a-z][a-z0-9]\b diff --git a/cachegrind/Makefile.am b/cachegrind/Makefile.am index cbaa90522b..0e0ef12b4d 100644 --- a/cachegrind/Makefile.am +++ b/cachegrind/Makefile.am @@ -76,14 +76,14 @@ endif # "Build" `cg_annotate`. The `+` avoids warnings about the jobserver. pyann: - +../auxprogs/pybuild.sh cg_annotate.in cg_annotate + +../auxprogs/pybuild.sh ../auxprogs cg_annotate.in cg_annotate # "Build" `cg_diff`. The `+` avoids warnings about the jobserver. pydiff: - +../auxprogs/pybuild.sh cg_diff.in cg_diff + +../auxprogs/pybuild.sh ../auxprogs cg_diff.in cg_diff # "Build" `cg_merge`. The `+` avoids warnings about the jobserver. pymerge: - +../auxprogs/pybuild.sh cg_merge.in cg_merge + +../auxprogs/pybuild.sh ../auxprogs cg_merge.in cg_merge .PHONY: pyann pydiff pymerge diff --git a/cachegrind/cg_annotate.in b/cachegrind/cg_annotate.in index dcc60de2e6..5dad969f6a 100755 --- a/cachegrind/cg_annotate.in +++ b/cachegrind/cg_annotate.in @@ -73,7 +73,7 @@ class Args(Namespace): raise ValueError def add_bool_argument( - p: ArgumentParser, new_name: str, old_name: str, help: str + p: ArgumentParser, new_name: str, old_name: str, help_: str ) -> None: """ Add a bool argument that defaults to true. @@ -92,7 +92,7 @@ class Args(Namespace): new_flag, default=True, action=BooleanOptionalAction, - help=help, + help=help_, ) p.add_argument( f"{old_flag}=yes", diff --git a/cachegrind/pylintrc b/cachegrind/pylintrc deleted file mode 100644 index 4b2cfb34af..0000000000 --- a/cachegrind/pylintrc +++ /dev/null @@ -1,53 +0,0 @@ -# How to create this file. -# - Generate with `pylint --generate-rcfile > pylintrc`. -# - Then modify entries resulting in unreasonable warnings. Comment out the -# original value, and add another comment line explaining the modification. -# - Remove all non-modified entries. - -[BASIC] - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -#docstring-min-length=-1 -# We don't care about having docstrings for all functions/classes. -docstring-min-length=1000 - -# Good variable names regexes, separated by a comma. If names match any regex, -# they will always be accepted -#good-names-rgxs= -# We allow any lower-case variable name of length 1 or 2. -good-names-rgxs=\b[a-z]\b,\b[a-z][a-z0-9]\b - -[VARIABLES] - -# List of names allowed to shadow builtins -#allowed-redefined-builtins= -# We use `help` reasonably as an argument. -allowed-redefined-builtins=help - -[DESIGN] - -# Maximum number of arguments for function / method. -#max-args=5 -# We have some large functions. -max-args=7 - -# Maximum number of branch for function / method body. -#max-branches=12 -# We have some large functions. -max-branches=25 - -# Maximum number of locals for function / method body. -#max-locals=15 -# We have some large functions. -max-locals=25 - -# Maximum number of statements in function / method body. -#max-statements=50 -# We have some large functions. -max-statements=65 - -# Minimum number of public methods for a class (see R0903). -#min-public-methods=2 -# We have some useful classes with little more than `__init__`. -min-public-methods=0 -- 2.47.2