Skip to content

Commit 56fdadb

Browse files
[PYLINT-HOME change] Less spam when using pylint in parallel
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.
1 parent a3464cb commit 56fdadb

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pylint/config/__init__.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import os
3636
import pickle
3737
import sys
38+
from datetime import datetime
3839

3940
import appdirs
4041

@@ -66,14 +67,32 @@
6667
PYLINT_HOME = ".pylint.d"
6768
else:
6869
PYLINT_HOME = appdirs.user_cache_dir("pylint")
69-
70+
# The spam prevention is due to pylint being used in parallel by
71+
# pre-commit, and the message being spammy in this context
72+
# Also if you work with old version of pylint that recreate the
73+
# old pylint home, you can get the old message for a long time.
74+
prefix_spam_prevention = "pylint_warned_about_old_cache_already"
75+
spam_prevention_file = os.path.join(
76+
PYLINT_HOME,
77+
datetime.now().strftime(prefix_spam_prevention + "_%Y-%m-%d.temp"),
78+
)
7079
old_home = os.path.join(USER_HOME, ".pylint.d")
71-
if os.path.exists(old_home):
80+
if os.path.exists(old_home) and not os.path.exists(spam_prevention_file):
7281
print(
7382
f"PYLINTHOME is now '{PYLINT_HOME}' but obsolescent '{old_home}' is found; "
7483
"you can safely remove the latter",
7584
file=sys.stderr,
7685
)
86+
# Remove old spam prevention file
87+
for filename in os.listdir(PYLINT_HOME):
88+
if prefix_spam_prevention in filename:
89+
try:
90+
os.remove(os.path.join(PYLINT_HOME, filename))
91+
except OSError:
92+
pass
93+
# Create spam prevention file for today
94+
with open(spam_prevention_file, "w", encoding="utf8") as f:
95+
f.write("")
7796

7897

7998
def _get_pdata_path(base_name, recurs):

0 commit comments

Comments
 (0)