File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import logging
22import os
33from pathlib import Path
4- from typing import Dict
4+ from typing import Dict , Optional
55
66import black
77import toml
88from pylsp import hookimpl
99
1010logger = logging .getLogger (__name__ )
1111
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 )
1922
2023
2124@hookimpl (tryfirst = True )
@@ -92,7 +95,7 @@ def load_config(filename: str) -> Dict:
9295 pyproject_filename = root / "pyproject.toml"
9396
9497 if not pyproject_filename .is_file ():
95- if GLOBAL_CONFIG .exists ():
98+ if GLOBAL_CONFIG is not None and GLOBAL_CONFIG .exists ():
9699 pyproject_filename = GLOBAL_CONFIG
97100 logger .info ("Using global black config at %s" , pyproject_filename )
98101 else :
You can’t perform that action at this time.
0 commit comments