File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff line change 1
1
import logging
2
2
import os
3
3
from pathlib import Path
4
- from typing import Dict
4
+ from typing import Dict , Optional
5
5
6
6
import black
7
7
import toml
8
8
from pylsp import hookimpl
9
9
10
10
logger = logging .getLogger (__name__ )
11
11
12
- GLOBAL_CONFIG : Path
13
- if os .name == "nt" :
14
- GLOBAL_CONFIG = Path .home () / ".black"
15
- elif "XDG_CONFIG_HOME" in os .environ :
16
- GLOBAL_CONFIG = Path (os .environ ["XDG_CONFIG_HOME" ]) / "black"
17
- else :
18
- GLOBAL_CONFIG = Path .home () / ".config" / "black"
12
+ GLOBAL_CONFIG : Optional [Path ] = None
13
+ try :
14
+ if os .name == "nt" :
15
+ GLOBAL_CONFIG = Path .home () / ".black"
16
+ elif "XDG_CONFIG_HOME" in os .environ :
17
+ GLOBAL_CONFIG = Path (os .environ ["XDG_CONFIG_HOME" ]) / "black"
18
+ else :
19
+ GLOBAL_CONFIG = Path .home () / ".config" / "black"
20
+ except Exception as e :
21
+ logger .error ("Error determining black global config file path: %s" , e )
19
22
20
23
21
24
@hookimpl (tryfirst = True )
@@ -92,7 +95,7 @@ def load_config(filename: str) -> Dict:
92
95
pyproject_filename = root / "pyproject.toml"
93
96
94
97
if not pyproject_filename .is_file ():
95
- if GLOBAL_CONFIG .exists ():
98
+ if GLOBAL_CONFIG is not None and GLOBAL_CONFIG .exists ():
96
99
pyproject_filename = GLOBAL_CONFIG
97
100
logger .info ("Using global black config at %s" , pyproject_filename )
98
101
else :
You can’t perform that action at this time.
0 commit comments