Skip to content

[deprecation] Remove the warning about the old pylint home #8462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/whatsnew/fragments/8462.breaking
Original file line number Diff line number Diff line change
@@ -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 #8462
5 changes: 2 additions & 3 deletions pylint/config/help_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.

Expand Down
50 changes: 0 additions & 50 deletions pylint/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
from __future__ import annotations

import os
import pathlib
import platform
import sys
from datetime import datetime

import astroid
import platformdirs
Expand Down Expand Up @@ -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",)
Expand Down Expand Up @@ -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


Expand Down
55 changes: 4 additions & 51 deletions tests/lint/unittest_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from __future__ import annotations

import argparse
import datetime
import os
import re
import sys
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down