From 343c6e6e732e80633c7ed1491723b67ff614223f Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 20 Mar 2023 20:56:48 +0100 Subject: [PATCH 1/3] [deprecation] Remove the warning about the old pylint home --- doc/whatsnew/fragments/8447.breaking | 5 +++ pylint/config/help_formatter.py | 5 ++- pylint/constants.py | 50 ---------------------------- 3 files changed, 7 insertions(+), 53 deletions(-) create mode 100644 doc/whatsnew/fragments/8447.breaking diff --git a/doc/whatsnew/fragments/8447.breaking b/doc/whatsnew/fragments/8447.breaking new file mode 100644 index 0000000000..32a3b6d4ef --- /dev/null +++ b/doc/whatsnew/fragments/8447.breaking @@ -0,0 +1,5 @@ +The warning when the now useless old pylint cache directory (pylint.d) was +found was removed. The cache dir is documented in +[the FAQ](https://pylint.readthedocs.io/en/latest/faq.html#where-is-the-persistent-data-stored-to-compare-between-successive-runs). + +Refs #8447 diff --git a/pylint/config/help_formatter.py b/pylint/config/help_formatter.py index 5e517d9443..47caa3ffff 100644 --- a/pylint/config/help_formatter.py +++ b/pylint/config/help_formatter.py @@ -7,7 +7,7 @@ import argparse from pylint.config.callback_actions import _CallbackAction -from pylint.constants import DEFAULT_PYLINT_HOME, OLD_DEFAULT_PYLINT_HOME +from pylint.constants import DEFAULT_PYLINT_HOME class _HelpFormatter(argparse.RawDescriptionHelpFormatter): @@ -35,8 +35,7 @@ def get_long_description() -> str: Environment variables: The following environment variables are used: * PYLINTHOME Path to the directory where persistent data for the run will - be stored. If not found, it defaults to '{DEFAULT_PYLINT_HOME}' - or '{OLD_DEFAULT_PYLINT_HOME}' (in the current working directory). + be stored. If not found, it defaults to '{DEFAULT_PYLINT_HOME}'. * PYLINTRC Path to the configuration file. See the documentation for the method used to search for configuration file. diff --git a/pylint/constants.py b/pylint/constants.py index ad7fc2256f..1818eed529 100644 --- a/pylint/constants.py +++ b/pylint/constants.py @@ -5,10 +5,8 @@ from __future__ import annotations import os -import pathlib import platform import sys -from datetime import datetime import astroid import platformdirs @@ -49,9 +47,6 @@ # on all project using [MAIN] in their rcfile. MAIN_CHECKER_NAME = "main" -USER_HOME = os.path.expanduser("~") -# TODO: 3.0: Remove in 3.0 with all the surrounding code -OLD_DEFAULT_PYLINT_HOME = ".pylint.d" DEFAULT_PYLINT_HOME = platformdirs.user_cache_dir("pylint") DEFAULT_IGNORE_LIST = ("CVS",) @@ -101,55 +96,10 @@ class WarningScope: ) -def _warn_about_old_home(pylint_home: pathlib.Path) -> None: - """Warn users about the old pylint home being deprecated. - - The spam prevention mechanism is due to pylint being used in parallel by - pre-commit, and the message being spammy in this context - Also if you work with an old version of pylint that recreates the - old pylint home, you can get the old message for a long time. - """ - prefix_spam_prevention = "pylint_warned_about_old_cache_already" - spam_prevention_file = pathlib.Path(pylint_home) / datetime.now().strftime( - prefix_spam_prevention + "_%Y-%m-%d.temp" - ) - old_home = pathlib.Path(USER_HOME) / OLD_DEFAULT_PYLINT_HOME - - if old_home.exists() and not spam_prevention_file.exists(): - print( - f"PYLINTHOME is now '{pylint_home}' but obsolescent '{old_home}' is found; " - "you can safely remove the latter", - file=sys.stderr, - ) - - # Remove old spam prevention file - if pylint_home.exists(): - for filename in pylint_home.iterdir(): - if prefix_spam_prevention in str(filename): - try: - os.remove(pylint_home / filename) - except OSError: # pragma: no cover - pass - - # Create spam prevention file for today - try: - pylint_home.mkdir(parents=True, exist_ok=True) - with open(spam_prevention_file, "w", encoding="utf8") as f: - f.write("") - except Exception as exc: # pragma: no cover # pylint: disable=broad-except - print( - "Can't write the file that was supposed to " - f"prevent 'pylint.d' deprecation spam in {pylint_home} because of {exc}." - ) - - def _get_pylint_home() -> str: """Return the pylint home.""" if "PYLINTHOME" in os.environ: return os.environ["PYLINTHOME"] - - _warn_about_old_home(pathlib.Path(DEFAULT_PYLINT_HOME)) - return DEFAULT_PYLINT_HOME From a8a1472284ba5ffc79cf3d29df99139b42264812 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 20 Mar 2023 21:14:33 +0100 Subject: [PATCH 2/3] Refs the right PR --- doc/whatsnew/fragments/{8447.breaking => 8462.breaking} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename doc/whatsnew/fragments/{8447.breaking => 8462.breaking} (95%) diff --git a/doc/whatsnew/fragments/8447.breaking b/doc/whatsnew/fragments/8462.breaking similarity index 95% rename from doc/whatsnew/fragments/8447.breaking rename to doc/whatsnew/fragments/8462.breaking index 32a3b6d4ef..c794235c04 100644 --- a/doc/whatsnew/fragments/8447.breaking +++ b/doc/whatsnew/fragments/8462.breaking @@ -2,4 +2,4 @@ The warning when the now useless old pylint cache directory (pylint.d) was found was removed. The cache dir is documented in [the FAQ](https://pylint.readthedocs.io/en/latest/faq.html#where-is-the-persistent-data-stored-to-compare-between-successive-runs). -Refs #8447 +Refs #8462 From 5fc4efc4ec1f61b3340831f5f50b82040392be6f Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Mon, 20 Mar 2023 21:25:46 +0100 Subject: [PATCH 3/3] Remove related tests, simplify existing one --- tests/lint/unittest_lint.py | 55 +++---------------------------------- 1 file changed, 4 insertions(+), 51 deletions(-) diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 57c9a83d04..9a7e788a62 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -7,7 +7,6 @@ from __future__ import annotations import argparse -import datetime import os import re import sys @@ -19,6 +18,7 @@ from os.path import abspath, dirname, join, sep from pathlib import Path from shutil import copy, rmtree +from unittest import mock import platformdirs import pytest @@ -31,11 +31,8 @@ MSG_STATE_CONFIDENCE, MSG_STATE_SCOPE_CONFIG, MSG_STATE_SCOPE_MODULE, - OLD_DEFAULT_PYLINT_HOME, PYLINT_HOME, - USER_HOME, _get_pylint_home, - _warn_about_old_home, ) from pylint.exceptions import InvalidMessageError from pylint.lint import PyLinter, expand_modules @@ -930,58 +927,14 @@ def pop_pylintrc() -> None: @pytest.mark.usefixtures("pop_pylintrc") def test_pylint_home() -> None: - uhome = os.path.expanduser("~") - if uhome == "~": - expected = OLD_DEFAULT_PYLINT_HOME - else: - expected = platformdirs.user_cache_dir("pylint") + expected = platformdirs.user_cache_dir("pylint") assert constants.PYLINT_HOME == expected assert PYLINT_HOME == expected +@mock.patch.dict(os.environ, {"PYLINTHOME": "whatever.d"}) def test_pylint_home_from_environ() -> None: - try: - pylintd = join(tempfile.gettempdir(), OLD_DEFAULT_PYLINT_HOME) - os.environ["PYLINTHOME"] = pylintd - try: - assert _get_pylint_home() == pylintd - finally: - try: - rmtree(pylintd) - except FileNotFoundError: - pass - finally: - del os.environ["PYLINTHOME"] - - -def test_warn_about_old_home(capsys: CaptureFixture[str]) -> None: - """Test that we correctly warn about old_home.""" - # Create old home - old_home = Path(USER_HOME) / OLD_DEFAULT_PYLINT_HOME - old_home.mkdir(parents=True, exist_ok=True) - - # Create spam prevention file - ten_years_ago = datetime.datetime.now() - datetime.timedelta(weeks=520) - new_prevention_file = Path(PYLINT_HOME) / ten_years_ago.strftime( - "pylint_warned_about_old_cache_already_%Y-%m-%d.temp" - ) - with open(new_prevention_file, "w", encoding="utf8") as f: - f.write("") - - # Remove current prevention file - cur_prevention_file = Path(PYLINT_HOME) / datetime.datetime.now().strftime( - "pylint_warned_about_old_cache_already_%Y-%m-%d.temp" - ) - if cur_prevention_file.exists(): - os.remove(cur_prevention_file) - - _warn_about_old_home(Path(PYLINT_HOME)) - - assert not new_prevention_file.exists() - assert cur_prevention_file.exists() - - out = capsys.readouterr() - assert "PYLINTHOME is now" in out.err + assert _get_pylint_home() == "whatever.d" class _CustomPyLinter(PyLinter):