Skip to content

Commit 3b03ef6

Browse files
authored
Move pylint configuration to pyproject.toml (#7859)
- Move pylint configuration settings to pyproject.toml - Exclude `cirq_web/node_modules` directory from pylint check Avoid pylint failure on vendor files if user runs `check/npm ci`. - Update `check/pylint` and `check/pylint-changed-files` to load configuration from pyproject.toml. - Update docs to reference pyproject.toml instead of pylintrc This should prevent inconsistent outcomes between `check/pylint` and `pylint` runs. Partially implements #6800
1 parent 4e65c20 commit 3b03ef6

9 files changed

Lines changed: 81 additions & 74 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
- name: Lint with ruff
129129
run: FORCE_COLOR=1 ruff check
130130
- name: Lint with pylint
131-
run: check/pylint -v
131+
run: check/pylint
132132
doc_test:
133133
if: github.repository_owner == 'quantumlib'
134134
name: Doc test

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ with a `# pragma: no cover` comment on its own line.
134134
135135
Code should meet common style standards for Python and be free of error-prone
136136
constructs. We use [Pylint](https://www.pylint.org/) to check for code lint.
137-
To see which lint checks we enforce, see the
138-
[dev_tools/conf/.pylintrc](dev_tools/conf/.pylintrc) file. When Pylint produces
137+
To see which lint checks we enforce, see the `[tool.pylint.messages_control]`
138+
section in the [pyproject.toml](./pyproject.toml) file. When Pylint produces
139139
a false positive, it can be silenced with annotations. For example, the
140140
annotation `# pylint: disable=wrong-import-order` would silence a warning about
141141
wrong import order.

check/pylint

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
################################################################################
4-
# Runs pylint on the repository using a preconfigured .pylintrc file.
4+
# Runs pylint on the repository.
55
#
66
# Usage:
77
# check/pylint [--flags for pylint]
@@ -12,9 +12,5 @@ thisdir=$(dirname "${BASH_SOURCE[0]:?}") || exit $?
1212
repo_dir=$(git -C "${thisdir}" rev-parse --show-toplevel) || exit $?
1313
cd "${repo_dir}" || exit $?
1414

15-
read -r -a CIRQ_MODULES < \
16-
<(env PYTHONPATH=. python dev_tools/modules.py list --mode package-path)
17-
18-
# Add dev_tools to $PYTHONPATH so that pylint can find custom checkers
19-
env PYTHONPATH=dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc "$@" \
20-
"${CIRQ_MODULES[@]}" benchmarks dev_tools examples
15+
source dev_tools/pypath || exit $?
16+
pylint --jobs=0 "$@" .

check/pylint-changed-files

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
################################################################################
4-
# Runs pylint on changed files using a preconfigured .pylintrc file.
4+
# Runs pylint on changed Python sources.
55
#
66
# Usage:
77
# check/pylint-changed-files [BASE_REVISION]
@@ -65,7 +65,7 @@ num_changed=${#changed[@]}
6565

6666
# Run it.
6767
echo "Found ${num_changed} lintable files associated with changes." >&2
68-
if [ "${num_changed}" -eq 0 ]; then
69-
exit 0
68+
if (( num_changed )); then
69+
source dev_tools/pypath || exit $?
70+
pylint --jobs=0 "${changed[@]}"
7071
fi
71-
env PYTHONPATH=dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc "${changed[@]}"

dev_tools/bash_scripts_test.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,7 @@ def test_pylint_changed_files_file_selection(tmpdir_factory) -> None:
605605
).split()
606606
)
607607

608-
intercepted_prefix = (
609-
'INTERCEPTED env PYTHONPATH=dev_tools pylint --jobs=0 --rcfile=dev_tools/conf/.pylintrc '
610-
)
608+
intercepted_prefix = 'INTERCEPTED pylint --jobs=0 '
611609

612610
result = run(
613611
script_file='check/pylint-changed-files',

dev_tools/conf/.pylintrc

Lines changed: 0 additions & 54 deletions
This file was deleted.

docs/dev/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ The simplest way to run checks is to invoke `pytest`, `pylint`, or `mypy` for yo
167167
168168
```bash
169169
pytest
170-
pylint --rcfile=dev_tools/conf/.pylintrc cirq
170+
pylint cirq
171171
mypy --config-file=dev_tools/conf/mypy.ini .
172172
```
173173

docs/dev/style.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
As mentioned in [CONTRIBUTING.md](https://github.com/quantumlib/Cirq/blob/main/CONTRIBUTING.md) we use use [Pylint](https://pylint.pycqa.org/)
44
to check for style violations. Pylint attempts to enforce styles in
5-
[PEP 8](https://www.python.org/dev/peps/pep-0008/). To see which lint checks we enforce, see the
6-
[dev_tools/conf/.pylintrc](https://github.com/quantumlib/Cirq/blob/main/dev_tools/conf/.pylintrc) file.
5+
[PEP 8](https://www.python.org/dev/peps/pep-0008/). To see which lint checks we enforce,
6+
see the `[tool.pylint.messages_control]` section in the
7+
[pyproject.toml](https://github.com/quantumlib/Cirq/blob/main/pyproject.toml) file.
78

89
Here we include some extra style guidelines.
910

pyproject.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,72 @@ markers = [
5353
asyncio_default_fixture_loop_scope = "function"
5454

5555

56+
[tool.pylint.main]
57+
fail-on = ["I"]
58+
ignore-long-lines = "^(.*#\\w*pylint: disable.*|\\s*(# )?[<\\[\\(]?https?://\\S+[>\\]\\)]?)$"
59+
ignore-paths=[
60+
"cirq-google/cirq_google/cloud/",
61+
"cirq-web/cirq_web/node_modules/",
62+
]
63+
ignore-patterns = [".*_pb2\\.py"]
64+
load-plugins = [
65+
"dev_tools.pylint_copyright_checker",
66+
"pylint.extensions.docparams",
67+
"pylint.extensions.docstyle",
68+
]
69+
max-line-length = 100
70+
71+
[tool.pylint.messages_control]
72+
disable = ["all"]
73+
enable= [
74+
"abstract-class-instantiated",
75+
"assert-on-tuple",
76+
"assignment-from-no-return",
77+
"bad-chained-comparison",
78+
"bad-indentation",
79+
"bad-mcs-classmethod-argument",
80+
"bad-mcs-method-argument",
81+
"bad-option-value",
82+
"bad-reversed-sequence",
83+
"bad-super-call",
84+
"consider-using-f-string",
85+
"deprecated-decorator",
86+
"docstyle",
87+
"duplicate-argument-name",
88+
"inconsistent-mro",
89+
"method-hidden",
90+
"missing-kwoa",
91+
"missing-param-doc",
92+
"missing-raises-doc",
93+
"mixed-line-endings",
94+
"no-value-for-parameter",
95+
"raising-bad-type",
96+
"raising-format-tuple",
97+
"redefined-slots-in-subclass",
98+
"return-arg-in-generator",
99+
"self-cls-assignment",
100+
"shadowed-import",
101+
"simplifiable-condition",
102+
"simplifiable-if-statement",
103+
"too-many-function-args",
104+
"trailing-whitespace",
105+
"unhashable-dict-key",
106+
"unnecessary-semicolon",
107+
"unreachable",
108+
"unrecognized-inline-option",
109+
"use-maxsplit-arg",
110+
"useless-suppression",
111+
"using-constant-test",
112+
"wrong-import-order",
113+
"wrong-or-nonexistent-copyright-notice",
114+
]
115+
116+
[tool.pylint.reports]
117+
output-format = "colorized"
118+
reports = false
119+
score = false
120+
121+
56122
[tool.ruff]
57123
line-length = 100
58124
preview = true

0 commit comments

Comments
 (0)