106106from easybuild .tools .repository .repository import avail_repositories
107107from easybuild .tools .systemtools import DARWIN , UNKNOWN , check_python_version , get_cpu_architecture , get_cpu_family
108108from easybuild .tools .systemtools import get_cpu_features , get_gpu_info , get_os_type , get_system_info
109+ from easybuild .tools .utilities import flatten
109110from easybuild .tools .version import this_is_easybuild
110111
111112
@@ -125,7 +126,8 @@ def terminal_supports_colors(stream):
125126
126127XDG_CONFIG_HOME = os .environ .get ('XDG_CONFIG_HOME' , os .path .join (os .path .expanduser ('~' ), ".config" ))
127128XDG_CONFIG_DIRS = os .environ .get ('XDG_CONFIG_DIRS' , '/etc/xdg' ).split (os .pathsep )
128- DEFAULT_SYS_CFGFILES = [f for d in XDG_CONFIG_DIRS for f in sorted (glob .glob (os .path .join (d , 'easybuild.d' , '*.cfg' )))]
129+ DEFAULT_SYS_CFGFILES = [[f for f in sorted (glob .glob (os .path .join (d , 'easybuild.d' , '*.cfg' )))]
130+ for d in XDG_CONFIG_DIRS ]
129131DEFAULT_USER_CFGFILE = os .path .join (XDG_CONFIG_HOME , 'easybuild' , 'config.cfg' )
130132
131133DEFAULT_LIST_PR_STATE = GITHUB_PR_STATE_OPEN
@@ -213,7 +215,11 @@ class EasyBuildOptions(GeneralOption):
213215 VERSION = this_is_easybuild ()
214216
215217 DEFAULT_LOGLEVEL = 'INFO'
216- DEFAULT_CONFIGFILES = DEFAULT_SYS_CFGFILES [:]
218+ # https://specifications.freedesktop.org/basedir-spec/latest/
219+ # says precedence should be
220+ # XDG_CONFIG_HOME > 1st entry of XDG_CONFIG_DIRS > 2nd entry ...
221+ # EasyBuild parses this list backwards, gives priority to last entry
222+ DEFAULT_CONFIGFILES = flatten (DEFAULT_SYS_CFGFILES [::- 1 ])
217223 if 'XDG_CONFIG_DIRS' not in os .environ :
218224 old_etc_location = os .path .join ('/etc' , 'easybuild.d' )
219225 if os .path .isdir (old_etc_location ) and glob .glob (os .path .join (old_etc_location , '*.cfg' )):
@@ -1394,9 +1400,10 @@ def show_default_configfiles(self):
13941400 "* user-level: %s" % os .path .join ('${XDG_CONFIG_HOME:-$HOME/.config}' , 'easybuild' , 'config.cfg' ),
13951401 " -> %s => %s" % (DEFAULT_USER_CFGFILE , ('not found' , 'found' )[os .path .exists (DEFAULT_USER_CFGFILE )]),
13961402 "* system-level: %s" % os .path .join ('${XDG_CONFIG_DIRS:-/etc/xdg}' , 'easybuild.d' , '*.cfg' ),
1397- " -> %s => %s" % (system_cfg_glob_paths , ', ' .join (DEFAULT_SYS_CFGFILES ) or "(no matches)" ),
1403+ " -> %s => %s" % (system_cfg_glob_paths , ', ' .join (flatten ( DEFAULT_SYS_CFGFILES ) ) or "(no matches)" ),
13981404 '' ,
1399- "Default list of existing configuration files (%d): %s" % (found_cfgfile_cnt , found_cfgfile_list ),
1405+ "Default list of existing configuration files (%d, most important last):" % found_cfgfile_cnt ,
1406+ found_cfgfile_list ,
14001407 ]
14011408 return '\n ' .join (lines )
14021409
0 commit comments