summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Whetter <AWhetter@users.noreply.github.com>2021-08-20 19:40:14 -0700
committerGitHub <noreply@github.com>2021-08-20 19:40:14 -0700
commitd701a979d95c5e4ca6dd4860ab30e08880a904d0 (patch)
tree9dcd380826f5ccd25bb3b0207548762ea46abba6
parentbbc4f6690724c3fa2325d6e3e4f1e5414a27983c (diff)
downloadpylint-git-d701a979d95c5e4ca6dd4860ab30e08880a904d0.tar.gz
pylint does not crash when PYLINT_HOME does not exist (#4884)
Closes #4883
-rw-r--r--ChangeLog4
-rw-r--r--pylint/config/__init__.py16
2 files changed, 12 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 29228417a..5a1398356 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,9 +15,9 @@ What's New in Pylint 2.10.1?
============================
Release date: TBA
-..
- Put bug fixes that should not wait for a new minor version here
+* pylint does not crash when PYLINT_HOME does not exist.
+ Closes #4883
What's New in Pylint 2.10.0?
diff --git a/pylint/config/__init__.py b/pylint/config/__init__.py
index 01c3e671e..b73d43e2d 100644
--- a/pylint/config/__init__.py
+++ b/pylint/config/__init__.py
@@ -35,6 +35,7 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE
import os
+import pathlib
import pickle
import sys
from datetime import datetime
@@ -86,14 +87,17 @@ else:
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
+ if os.path.exists(PYLINT_HOME):
+ 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
try:
+ pathlib.Path(PYLINT_HOME).mkdir(parents=True, exist_ok=True)
with open(spam_prevention_file, "w", encoding="utf8") as f:
f.write("")
except Exception: # pylint: disable=broad-except