From b0ef1777c75b675794c07594d434bfd75bf4bb38 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 7 Oct 2024 13:52:42 -0700 Subject: [PATCH] Update copyright checker and switch to pylint-3 (#1439) * Bump up to the latest pylint-3.3.1 * Adjust `pylint_copyright_checker` for the pylint-3 API Follow the `examples/custom_raw.py` in the pylint repository. * Refresh development dependencies * Temporarily disable rules that started failing in pylint-3 Cherry-picked from https://github.com/quantumlib/Cirq/pull/6751 Related to #1440 --- dev_tools/conf/.pylintrc | 4 +++ .../pylint_copyright_checker.py | 25 ++++++++++--------- dev_tools/requirements/deps/pylint.txt | 4 +-- dev_tools/requirements/envs/dev.env.txt | 20 ++++++--------- dev_tools/requirements/envs/docs.env.txt | 6 ++--- dev_tools/requirements/envs/format.env.txt | 6 ++--- dev_tools/requirements/envs/pylint.env.txt | 22 ++++++---------- dev_tools/requirements/envs/pytest.env.txt | 10 ++++---- dev_tools/requirements/envs/runtime.env.txt | 6 ++--- 9 files changed, 48 insertions(+), 55 deletions(-) diff --git a/dev_tools/conf/.pylintrc b/dev_tools/conf/.pylintrc index b8b9e295a..8fcb6dc09 100644 --- a/dev_tools/conf/.pylintrc +++ b/dev_tools/conf/.pylintrc @@ -7,6 +7,10 @@ score=no reports=no py-version=3.9 disable= + abstract-class-instantiated, # TODO: #1440 - enable and fix + deprecated-class, # TODO: #1440 - enable and fix + possibly-used-before-assignment, # TODO: #1440 - enable and fix + used-before-assignment, # TODO: #1440 - enable and fix C, R, missing-raises-doc, diff --git a/dev_tools/qualtran_dev_tools/pylint_copyright_checker.py b/dev_tools/qualtran_dev_tools/pylint_copyright_checker.py index 497b012b5..d6e7a4c1b 100644 --- a/dev_tools/qualtran_dev_tools/pylint_copyright_checker.py +++ b/dev_tools/qualtran_dev_tools/pylint_copyright_checker.py @@ -12,23 +12,24 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + +from typing import TYPE_CHECKING + from astroid import nodes -from pylint.checkers import BaseChecker -from pylint.interfaces import IRawChecker +from pylint.checkers import BaseRawFileChecker + +if TYPE_CHECKING: + from pylint.lint import PyLinter -class CopyrightChecker(BaseChecker): - r"""Check for the copyright notices at the beginning of a Python source file. +class CopyrightChecker(BaseRawFileChecker): + """Check for the copyright notices at the beginning of a Python source file. This checker can be disabled by putting `# pylint: disable=wrong-or-nonexistent-copyright-notice` at the beginning of a file. """ - __implements__ = IRawChecker - - # The priority must be negative. Pylint runs plugins with smaller priorities first. - priority = -1 - name = "copyright-notice" msgs = { "R0001": ( @@ -40,7 +41,7 @@ class CopyrightChecker(BaseChecker): options = () def process_module(self, node: nodes.Module) -> None: - r"""Check whether the copyright notice is correctly placed in the source file of a module. + """Check whether the copyright notice is correctly placed in the source file of a module. Compare the first lines of a source file against the standard copyright notice (i.e., the `golden` variable below). Suffix whitespace (including newline symbols) is not considered @@ -108,8 +109,8 @@ def skip_shebang(stream): return -def register(linter): - r"""Register this checker to pylint. +def register(linter: PyLinter): + """Register this checker to pylint. The registration is done automatically if this file is in $PYTHONPATH. """ diff --git a/dev_tools/requirements/deps/pylint.txt b/dev_tools/requirements/deps/pylint.txt index 52b96772e..a4380741b 100644 --- a/dev_tools/requirements/deps/pylint.txt +++ b/dev_tools/requirements/deps/pylint.txt @@ -1,4 +1,4 @@ -pylint~=2.15 +pylint~=3.3.1 # for checking _test.py files pytest @@ -7,4 +7,4 @@ openfermion[resources] # dev tools tensorflow-docs sphinx -filelock \ No newline at end of file +filelock diff --git a/dev_tools/requirements/envs/dev.env.txt b/dev_tools/requirements/envs/dev.env.txt index 60b9216e4..e536aa3d7 100644 --- a/dev_tools/requirements/envs/dev.env.txt +++ b/dev_tools/requirements/envs/dev.env.txt @@ -30,7 +30,7 @@ astor==0.8.1 # via # flynt # tensorflow-docs -astroid==2.15.8 +astroid==3.3.5 # via pylint asttokens==2.4.1 # via stack-data @@ -105,7 +105,7 @@ cryptography==43.0.1 # via secretstorage cycler==0.12.1 # via matplotlib -cytoolz==0.12.3 +cytoolz==1.0.0 # via quimb dash==2.18.1 # via -r deps/runtime.txt @@ -228,9 +228,9 @@ jaraco-context==6.0.1 # via keyring jaraco-functools==4.1.0 # via keyring -jax==0.4.33 +jax==0.4.34 # via openfermion -jaxlib==0.4.33 +jaxlib==0.4.34 # via # jax # openfermion @@ -304,8 +304,6 @@ keyring==25.4.1 # via twine kiwisolver==1.4.7 # via matplotlib -lazy-object-proxy==1.10.0 - # via astroid llvmlite==0.43.0 # via numba markdown-it-py==3.0.0 @@ -515,7 +513,7 @@ pygments==2.18.0 # readme-renderer # rich # sphinx -pylint==2.17.7 +pylint==3.3.1 # via -r deps/pylint.txt pyparsing==3.1.4 # via @@ -602,7 +600,7 @@ rfc3986-validator==0.1.1 # via # jsonschema # jupyter-events -rich==13.9.1 +rich==13.9.2 # via twine rpds-py==0.20.0 # via @@ -696,7 +694,7 @@ tomli==2.0.2 # sphinx tomlkit==0.13.2 # via pylint -toolz==0.12.1 +toolz==1.0.0 # via cytoolz tornado==6.4.1 # via @@ -729,7 +727,7 @@ twine==5.1.1 # via -r deps/packaging.txt types-protobuf==5.28.0.20240924 # via mypy-protobuf -types-python-dateutil==2.9.0.20240906 +types-python-dateutil==2.9.0.20241003 # via arrow typing-extensions==4.12.2 # via @@ -780,8 +778,6 @@ wheel==0.44.0 # pip-tools widgetsnbextension==4.0.13 # via ipywidgets -wrapt==1.16.0 - # via astroid zipp==3.20.2 # via importlib-metadata diff --git a/dev_tools/requirements/envs/docs.env.txt b/dev_tools/requirements/envs/docs.env.txt index 2468fd901..d712bd9b1 100644 --- a/dev_tools/requirements/envs/docs.env.txt +++ b/dev_tools/requirements/envs/docs.env.txt @@ -133,7 +133,7 @@ cycler==0.12.1 # via # -c envs/dev.env.txt # matplotlib -cytoolz==0.12.3 +cytoolz==1.0.0 # via # -c envs/dev.env.txt # quimb @@ -767,7 +767,7 @@ tomli==2.0.2 # -c envs/dev.env.txt # jupyterlab # sphinx -toolz==0.12.1 +toolz==1.0.0 # via # -c envs/dev.env.txt # cytoolz @@ -801,7 +801,7 @@ traitlets==5.14.3 # nbclient # nbconvert # nbformat -types-python-dateutil==2.9.0.20240906 +types-python-dateutil==2.9.0.20241003 # via # -c envs/dev.env.txt # arrow diff --git a/dev_tools/requirements/envs/format.env.txt b/dev_tools/requirements/envs/format.env.txt index 14fdefc6a..22872de48 100644 --- a/dev_tools/requirements/envs/format.env.txt +++ b/dev_tools/requirements/envs/format.env.txt @@ -121,7 +121,7 @@ cycler==0.12.1 # via # -c envs/dev.env.txt # matplotlib -cytoolz==0.12.3 +cytoolz==1.0.0 # via # -c envs/dev.env.txt # quimb @@ -658,7 +658,7 @@ tomli==2.0.2 # black # flynt # jupyterlab -toolz==0.12.1 +toolz==1.0.0 # via # -c envs/dev.env.txt # cytoolz @@ -692,7 +692,7 @@ traitlets==5.14.3 # nbclient # nbconvert # nbformat -types-python-dateutil==2.9.0.20240906 +types-python-dateutil==2.9.0.20241003 # via # -c envs/dev.env.txt # arrow diff --git a/dev_tools/requirements/envs/pylint.env.txt b/dev_tools/requirements/envs/pylint.env.txt index d705b6bd9..0e3dddb6e 100644 --- a/dev_tools/requirements/envs/pylint.env.txt +++ b/dev_tools/requirements/envs/pylint.env.txt @@ -45,7 +45,7 @@ astor==0.8.1 # via # -c envs/dev.env.txt # tensorflow-docs -astroid==2.15.8 +astroid==3.3.5 # via # -c envs/dev.env.txt # pylint @@ -134,7 +134,7 @@ cycler==0.12.1 # via # -c envs/dev.env.txt # matplotlib -cytoolz==0.12.3 +cytoolz==1.0.0 # via # -c envs/dev.env.txt # quimb @@ -287,11 +287,11 @@ itsdangerous==2.2.0 # via # -c envs/dev.env.txt # flask -jax==0.4.33 +jax==0.4.34 # via # -c envs/dev.env.txt # openfermion -jaxlib==0.4.33 +jaxlib==0.4.34 # via # -c envs/dev.env.txt # jax @@ -385,10 +385,6 @@ kiwisolver==1.4.7 # via # -c envs/dev.env.txt # matplotlib -lazy-object-proxy==1.10.0 - # via - # -c envs/dev.env.txt - # astroid llvmlite==0.43.0 # via # -c envs/dev.env.txt @@ -606,7 +602,7 @@ pygments==2.18.0 # ipython # nbconvert # sphinx -pylint==2.17.7 +pylint==3.3.1 # via # -c envs/dev.env.txt # -r deps/pylint.txt @@ -805,7 +801,7 @@ tomlkit==0.13.2 # via # -c envs/dev.env.txt # pylint -toolz==0.12.1 +toolz==1.0.0 # via # -c envs/dev.env.txt # cytoolz @@ -839,7 +835,7 @@ traitlets==5.14.3 # nbclient # nbconvert # nbformat -types-python-dateutil==2.9.0.20240906 +types-python-dateutil==2.9.0.20241003 # via # -c envs/dev.env.txt # arrow @@ -895,10 +891,6 @@ widgetsnbextension==4.0.13 # via # -c envs/dev.env.txt # ipywidgets -wrapt==1.16.0 - # via - # -c envs/dev.env.txt - # astroid zipp==3.20.2 # via # -c envs/dev.env.txt diff --git a/dev_tools/requirements/envs/pytest.env.txt b/dev_tools/requirements/envs/pytest.env.txt index c740dd068..3ecafa454 100644 --- a/dev_tools/requirements/envs/pytest.env.txt +++ b/dev_tools/requirements/envs/pytest.env.txt @@ -121,7 +121,7 @@ cycler==0.12.1 # via # -c envs/dev.env.txt # matplotlib -cytoolz==0.12.3 +cytoolz==1.0.0 # via # -c envs/dev.env.txt # quimb @@ -263,11 +263,11 @@ itsdangerous==2.2.0 # via # -c envs/dev.env.txt # flask -jax==0.4.33 +jax==0.4.34 # via # -c envs/dev.env.txt # openfermion -jaxlib==0.4.33 +jaxlib==0.4.34 # via # -c envs/dev.env.txt # jax @@ -734,7 +734,7 @@ tomli==2.0.2 # coverage # jupyterlab # pytest -toolz==0.12.1 +toolz==1.0.0 # via # -c envs/dev.env.txt # cytoolz @@ -768,7 +768,7 @@ traitlets==5.14.3 # nbclient # nbconvert # nbformat -types-python-dateutil==2.9.0.20240906 +types-python-dateutil==2.9.0.20241003 # via # -c envs/dev.env.txt # arrow diff --git a/dev_tools/requirements/envs/runtime.env.txt b/dev_tools/requirements/envs/runtime.env.txt index e8ccda755..18d4d020b 100644 --- a/dev_tools/requirements/envs/runtime.env.txt +++ b/dev_tools/requirements/envs/runtime.env.txt @@ -112,7 +112,7 @@ cycler==0.12.1 # via # -c envs/dev.env.txt # matplotlib -cytoolz==0.12.3 +cytoolz==1.0.0 # via # -c envs/dev.env.txt # quimb @@ -629,7 +629,7 @@ tomli==2.0.2 # via # -c envs/dev.env.txt # jupyterlab -toolz==0.12.1 +toolz==1.0.0 # via # -c envs/dev.env.txt # cytoolz @@ -663,7 +663,7 @@ traitlets==5.14.3 # nbclient # nbconvert # nbformat -types-python-dateutil==2.9.0.20240906 +types-python-dateutil==2.9.0.20241003 # via # -c envs/dev.env.txt # arrow