Skip to content

Commit

Permalink
[PYLINT-HOME change] Less spam when using pylint in parallel
Browse files Browse the repository at this point in the history
The spam prevention is due to pylint being used in parallel by
pre-commit, and the message being spammy in this context
Also if you work with old version of pylint that recreate the
old pylint home, you can get the old message for a long time.
  • Loading branch information
Pierre-Sassoulas committed Aug 20, 2021
1 parent a3464cb commit 56fdadb
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pylint/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import os
import pickle
import sys
from datetime import datetime

import appdirs

Expand Down Expand Up @@ -66,14 +67,32 @@
PYLINT_HOME = ".pylint.d"
else:
PYLINT_HOME = appdirs.user_cache_dir("pylint")

# The spam prevention is due to pylint being used in parallel by
# pre-commit, and the message being spammy in this context
# Also if you work with old version of pylint that recreate 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 = os.path.join(
PYLINT_HOME,
datetime.now().strftime(prefix_spam_prevention + "_%Y-%m-%d.temp"),
)
old_home = os.path.join(USER_HOME, ".pylint.d")
if os.path.exists(old_home):
if os.path.exists(old_home) and not os.path.exists(spam_prevention_file):
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
for filename in os.listdir(PYLINT_HOME):
if prefix_spam_prevention in filename:
try:
os.remove(os.path.join(PYLINT_HOME, filename))
except OSError:
pass
# Create spam prevention file for today
with open(spam_prevention_file, "w", encoding="utf8") as f:
f.write("")


def _get_pdata_path(base_name, recurs):
Expand Down

0 comments on commit 56fdadb

Please sign in to comment.