@@ -331,17 +331,22 @@ def load_user_config():
331
331
# Create empty config object.
332
332
config = __build_class__ (lambda : None , "Config" )()
333
333
config .commands = {}
334
-
335
- # Get config file name.
336
- path = os .getenv ("XDG_CONFIG_HOME" )
337
- if path is None :
338
- path = os .getenv ("HOME" )
334
+ # use $XDG_CONFIG_HOME, if on Windows use $APPDATA
335
+ if os .name != "nt" :
336
+ # Get config file name.
337
+ path = os .getenv ("XDG_CONFIG_HOME" )
338
+ if path is None :
339
+ path = os .getenv ("HOME" )
340
+ if path is None :
341
+ return config
342
+ path = os .path .join (path , ".config" )
343
+ else :
344
+ path = os .getenv ("HOME" ) or os .getenv ("APPDATA" )
339
345
if path is None :
340
346
return config
341
- path = os .path .join (path , ".config" )
342
347
path = os .path .join (path , _PROG )
343
348
config_file = os .path .join (path , "config.py" )
344
-
349
+ print ( "Loading config from: " , config_file )
345
350
# Check if config file exists.
346
351
if not os .path .exists (config_file ):
347
352
return config
@@ -351,6 +356,9 @@ def load_user_config():
351
356
config_data = f .read ()
352
357
prev_cwd = os .getcwd ()
353
358
os .chdir (path )
359
+ # pass in the config path so that the config file can use it
360
+ config .__dict__ ["config_path" ] = path
361
+ config .__dict__ ["__file__" ] = config_file
354
362
exec (config_data , config .__dict__ )
355
363
os .chdir (prev_cwd )
356
364
0 commit comments