Repository: spyder-ide/spyder

Issue:
Spyder crashes at startup because it's unable to ready `pylintrc` file
This was reported by a Spyder user on this issue: https://github.com/ContinuumIO/anaconda-issues/issues/13095

> My Spyder crashes a few seconds after double-clicking 'Launch'. Using console also doesn't work. I tried to reinstall anaconda3 but there's an installation failure.

```
Error reported while opening spyder:
The available OpenGL surface format was either not version 3.2 or higher or not a Core Profile.
Chromium on macOS will fall back to software rendering in this case.
Hardware acceleration and features such as WebGL will not be available.
fromIccProfile: failed minimal tag size sanity
Traceback (most recent call last):
File "/Users/macbookair/anaconda3/bin/spyder", line 11, in
sys.exit(main())
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/app/start.py", line 252, in main
mainwindow.main(options, args)
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/app/mainwindow.py", line 1956, in main
mainwindow = create_window(MainWindow, app, splash, options, args)
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/app/utils.py", line 289, in create_window
main.setup()
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/app/mainwindow.py", line 736, in setup
internal_plugins = find_internal_plugins()
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/app/find_plugins.py", line 40, in find_internal_plugins
mod = importlib.import_module(entry_point.module_name)
File "/Users/macbookair/anaconda3/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 850, in exec_module
File "", line 228, in _call_with_frames_removed
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/plugins/pylint/plugin.py", line 22, in
from spyder.plugins.pylint.confpage import PylintConfigPage
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/plugins/pylint/confpage.py", line 16, in
from spyder.plugins.pylint.main_widget import (MAX_HISTORY_ENTRIES,
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/plugins/pylint/main_widget.py", line 35, in
from spyder.plugins.pylint.utils import get_pylintrc_path
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/spyder/plugins/pylint/utils.py", line 16, in
import pylint.config
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/pylint/config/init.py", line 27, in
from pylint.config.environment_variable import PYLINTRC
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/pylint/config/environment_variable.py", line 11, in
PYLINTRC = find_pylintrc()
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/pylint/config/find_default_config_files.py", line 94, in find_pylintrc
for config_file in find_default_config_files():
File "/Users/macbookair/anaconda3/lib/python3.9/site-packages/pylint/config/find_default_config_files.py", line 76, in find_default_config_files
if home_rc.is_file():
File "/Users/macbookair/anaconda3/lib/python3.9/pathlib.py", line 1456, in is_file
return S_ISREG(self.stat().st_mode)
File "/Users/macbookair/anaconda3/lib/python3.9/pathlib.py", line 1232, in stat
return self._accessor.stat(self)
PermissionError: [Errno 13] Permission denied: '/Users/macbookair/.config/pylintrc'
```


Discussion:

Resolving patch:
diff --git a/spyder/plugins/pylint/utils.py b/spyder/plugins/pylint/utils.py
--- a/spyder/plugins/pylint/utils.py
+++ b/spyder/plugins/pylint/utils.py
@@ -13,12 +13,18 @@
 import os.path as osp
 
 # Third party imports
-import pylint.config
+# This is necessary to avoid a crash at startup
+# Fixes spyder-ide/spyder#20079
+try:
+    from pylint import config as pylint_config
+except Exception:
+    pylint_config = None
 
 
 def _find_pylintrc_path(path):
-    os.chdir(path)
-    return pylint.config.find_pylintrc()
+    if pylint_config is not None:
+        os.chdir(path)
+        return pylint_config.find_pylintrc()
 
 
 def get_pylintrc_path(search_paths=None, home_path=None):
@@ -31,11 +37,15 @@ def get_pylintrc_path(search_paths=None, home_path=None):
     # Iterate through the search paths until a unique pylintrc file is found
     try:
         pylintrc_paths = [
-            _find_pylintrc_path(path) for path in search_paths if path]
+            _find_pylintrc_path(path) for path in search_paths if path
+        ]
         pylintrc_path_home = _find_pylintrc_path(home_path)
+
         for pylintrc_path in pylintrc_paths:
-            if (pylintrc_path is not None
-                    and pylintrc_path != pylintrc_path_home):
+            if (
+                pylintrc_path is not None
+                and pylintrc_path != pylintrc_path_home
+            ):
                 break
     finally:  # Ensure working directory is restored if any an error occurs
         os.chdir(current_cwd)


Test patch: