@@ -355,17 +355,23 @@ def load_user_config():
355
355
# Create empty config object.
356
356
config = __build_class__ (lambda : None , "Config" )()
357
357
config .commands = {}
358
-
359
- # Get config file name.
360
- path = os .getenv ("XDG_CONFIG_HOME" )
361
- if path is None :
362
- path = os .getenv ("HOME" )
363
- if path is None :
364
- return config
365
- path = os .path .join (path , ".config" )
366
- path = os .path .join (path , _PROG )
358
+ # use $XDG_CONFIG_HOME,$HOME $env:USERPROFILE% or $env:APPDATA
359
+ path = None
360
+ for env_var in ("XDG_CONFIG_HOME" , "HOME" , "USERPROFILE" , "APPDATA" ):
361
+ path = os .getenv (env_var )
362
+ if not path :
363
+ continue
364
+ if os .path .exists ( os .path .join (path ,".config" , _PROG , "config.py" )):
365
+ # Unix style
366
+ path = os .path .join (path ,".config" , _PROG , "config.py" )
367
+ break
368
+ elif os .path .exists ( os .path .join (path , _PROG , "config.py" )):
369
+ # Windows style
370
+ path = os .path .join (path , _PROG ,"config.py" )
371
+ break
372
+ if not path :
373
+ return config
367
374
config_file = os .path .join (path , "config.py" )
368
-
369
375
# Check if config file exists.
370
376
if not os .path .exists (config_file ):
371
377
return config
@@ -375,6 +381,9 @@ def load_user_config():
375
381
config_data = f .read ()
376
382
prev_cwd = os .getcwd ()
377
383
os .chdir (path )
384
+ # pass in the config path so that the config file can use it
385
+ config .__dict__ ["config_path" ] = path
386
+ config .__dict__ ["__file__" ] = config_file
378
387
exec (config_data , config .__dict__ )
379
388
os .chdir (prev_cwd )
380
389
0 commit comments