Skip to content

Commit 7754250

Browse files
hubatishcopybara-github
authored andcommitted
Add a default .pylintrc & update CONTRIBUTING.md to use it
PiperOrigin-RevId: 822728507
1 parent f2b8d5f commit 7754250

File tree

4 files changed

+179
-0
lines changed

4 files changed

+179
-0
lines changed

CHANGES.next.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,3 +632,5 @@
632632
- Add new general purpose fio benchmark for device - fio_raw_device_benchmark
633633
- Add support for GCP HdML disks.
634634
- Add fio benchmark for object storage via FUSE.
635+
- Updated the CONTRIBUTING.md guide with steps to minimize merging & review
636+
friction for new PRs.

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ Start from the master branch of the repository. This is the default.
111111
pyink --pyink-indentation 2 --pyink-use-majority-quotes --unstable --line-length=80 {file_path}
112112
```
113113
114+
1. Run lint-diffs on your changes.
115+
116+
```
117+
git diff -U0 origin | lint-diffs
118+
```
119+
120+
This will likely give some errors like:
121+
122+
```
123+
elastic_kubernetes_service.py:1032:0: C0301: Line too long (120/80) (line-too-long)
124+
```
125+
126+
Address all these errors before sending out the PR (& after making changes
127+
to the PR).
128+
114129
1. Update the appropriate sections in CHANGES.next.md with a summary of your
115130
changes. For example, under "Bug fixes and maintenance updates" you might
116131
put something like: `- Fix crazy bug X (GH-<insert PR number here> from
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# copybara:strip_begin(internal)
2+
# This is based on http://google3/devtools/gpylint/config/base/rc
3+
# copybara:strip_end
4+
5+
6+
# Default configuration for pylint, which should pass for all (incremental) changes.
7+
# See CONTRIBUTING.md for more.
8+
9+
[MESSAGES CONTROL]
10+
# List of checkers and warnings to enable.
11+
enable=indexing-exception,old-raise-syntax
12+
13+
disable=abstract-method,
14+
attribute-defined-outside-init,
15+
bad-option-value,
16+
c-extension-no-member,
17+
design,
18+
file-ignored,
19+
fixme,
20+
global-statement,
21+
invalid-metaclass,
22+
locally-disabled,
23+
locally-enabled,
24+
misplaced-comparison-constant,
25+
no-else-break,
26+
no-else-continue,
27+
no-else-raise,
28+
no-else-return,
29+
no-self-use,
30+
pointless-except,
31+
redundant-u-string-prefix,
32+
similarities,
33+
star-args,
34+
suppressed-message,
35+
trailing-newlines,
36+
ungrouped-imports,
37+
unnecessary-pass,
38+
unspecified-encoding,
39+
unsubscriptable-object,
40+
useless-else-on-loop,
41+
useless-object-inheritance,
42+
useless-suppression,
43+
44+
[BASIC]
45+
46+
# Regular expression which should only match the name
47+
# of functions or classes which do not require a docstring.
48+
no-docstring-rgx=(__.*__|main)
49+
50+
# Min length in lines of a function that requires a docstring.
51+
docstring-min-length=12
52+
53+
# Regular expression which should only match correct module names. The
54+
# leading underscore is sanctioned for private modules by Google's style
55+
# guide.
56+
#
57+
# There are exceptions to the basic rule (_?[a-z][a-z0-9_]*) to cover
58+
# requirements of Python's module system and of the presubmit framework.
59+
module-rgx=^(_?[a-z][a-z0-9_]*)|__init__|PRESUBMIT|PRESUBMIT_unittest$
60+
61+
# Regular expression which should only match correct module level names
62+
const-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$
63+
64+
# Regular expression which should only match correct class attribute
65+
class-attribute-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$
66+
67+
# Regular expression which should only match correct class names
68+
class-rgx=^_?[A-Z][a-zA-Z0-9]*$
69+
70+
# Regular expression which should only match correct function names.
71+
# 'PascalCase' and 'snake_case' group names are used for consistency of naming
72+
# styles across functions and methods.
73+
function-rgx=^(?:(?P<PascalCase>_?[A-Z][a-zA-Z0-9]*)|(?P<snake_case>_?[a-z][a-z0-9_]*))$
74+
75+
# Regular expression which should only match correct method names.
76+
# 'PascalCase' and 'snake_case' group names are used for consistency of naming
77+
# styles across functions and methods. 'exempt' indicates a name which is
78+
# consistent with all naming styles.
79+
method-rgx=(?x)^(?:(?P<exempt>_[a-z0-9_]+__|next)|(?P<PascalCase>_{0,2}[A-Z][a-zA-Z0-9_]*)|(?P<snake_case>_{0,2}[a-z][a-z0-9_]*))$
80+
81+
# Regular expression which should only match correct instance attribute names
82+
attr-rgx=^_{0,2}[a-z][a-z0-9_]*$
83+
84+
# Regular expression which should only match correct argument names
85+
argument-rgx=^[a-z][a-z0-9_]*$
86+
87+
# Regular expression which should only match correct variable names
88+
variable-rgx=^[a-z][a-z0-9_]*$
89+
90+
# Regular expression which should only match correct list comprehension /
91+
# generator expression variable names
92+
inlinevar-rgx=^[a-z][a-z0-9_]*$
93+
94+
# Regular expression which should only match correct TypeVar names
95+
typevar-rgx=^_{0,2}(?:[^\W\da-z_]+|(?:[^\W\da-z_]+[^\WA-Z_]+)+T?)(?:_co(?:ntra)?)?$
96+
97+
# Good variable names which should always be accepted, separated by a comma
98+
good-names=main,_
99+
100+
# List of decorators that define properties, such as abc.abstractproperty.
101+
property-classes=abc.abstractproperty,functools.cached_property,google3.pyglib.function_utils.cached.property,cached_property.cached_property,cached_property.threaded_cached_property,cached_property.cached_property_with_ttl,cached_property.threaded_cached_property_with_ttl,werkzeug.utils.cached_property
102+
103+
[VARIABLES]
104+
105+
# Tells whether we should check for unused import in __init__ files.
106+
init-import=no
107+
108+
# A regular expression matching names used for dummy variables (i.e. not used).
109+
dummy-variables-rgx=^\*{0,2}(_$|unused_|dummy_)
110+
111+
# List of additional names supposed to be defined in builtins. Remember that
112+
# you should avoid to define new builtins when possible.
113+
additional-builtins=
114+
115+
# List of modules that are allowed to redefine builtins.
116+
redefining-builtins-modules=six,six.moves,past.builtins,future.builtins,functools
117+
118+
[STRING]
119+
120+
# This flag controls whether the implicit-str-concat should
121+
# generate a warning on implicit string concatenation in sequences defined over
122+
# several lines.
123+
check-str-concat-over-line-jumps=yes
124+
125+
[CLASSES]
126+
127+
# List of method names used to declare (i.e. assign) instance attributes.
128+
defining-attr-methods=__init__,__new__,setUp
129+
130+
# "class_" is also a valid for the first argument to a class method.
131+
valid-classmethod-first-arg=cls,class_
132+
133+
134+
[FORMAT]
135+
136+
# Maximum number of characters on a single line.
137+
max-line-length=80
138+
139+
# Regexp for a line that is allowed to be longer than the limit.
140+
# This "ignore" regex is today composed of:
141+
# (1) p4 expansion $Id$ lines
142+
# (2) Depot paths for go/ifthisthenthatlint directives.
143+
# (3) Long string constants not containing whitespaces. This is needed now we
144+
# have switched Pyformat to use Pyink, and it would wrap strings constants
145+
# with a narrow range of lengths (less than 80 - indentation) in parens.
146+
# This causes GPylint to complain otherwise allowed per
147+
# go/pystyle#line-length. See b/262137806 for more information.
148+
# Other lines might be allowed to be long by gpylint.pyformat_filter: see that
149+
# module for more information.
150+
ignore-long-lines=(?x)(\$Id:\s\/\/depot\/.+\#\d+\s\$|^\s*\#\ LINT\.ThenChange|^\s*\w+\ =\ (?P<quote>['"])\S+(?P=quote)$)
151+
152+
# Maximum number of lines in a module
153+
max-module-lines=99999
154+
155+
# String used as indentation unit. We differ from PEP8's normal 4 spaces.
156+
indent-string=' '
157+
158+
# Do not warn about multiple statements on a single line for constructs like
159+
# if test: stmt
160+
single-line-if-stmt=y

requirements-testing.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ google-cloud-pubsub
3737
requests-mock
3838
pyfakefs
3939
pyink
40+
pylint
41+
lint-diffs

0 commit comments

Comments
 (0)