105105from easybuild .tools .repository .repository import avail_repositories
106106from easybuild .tools .systemtools import DARWIN , UNKNOWN , check_python_version , get_cpu_architecture , get_cpu_family
107107from easybuild .tools .systemtools import get_cpu_features , get_gpu_info , get_os_type , get_system_info
108+ from easybuild .tools .utilities import flatten
108109from easybuild .tools .version import this_is_easybuild
109110
110111
@@ -123,8 +124,8 @@ def terminal_supports_colors(stream):
123124CONFIG_ENV_VAR_PREFIX = 'EASYBUILD'
124125
125126XDG_CONFIG_HOME = os .environ .get ('XDG_CONFIG_HOME' , os .path .join (os .path .expanduser ('~' ), ".config" ))
126- XDG_CONFIG_DIRS = os .environ .get ('XDG_CONFIG_DIRS' , '/etc/xdg' ).split (os .pathsep )[:: - 1 ]
127- DEFAULT_SYS_CFGFILES = [f for d in XDG_CONFIG_DIRS for f in sorted (glob .glob (os .path .join (d , 'easybuild.d' , '*.cfg' )))]
127+ XDG_CONFIG_DIRS = os .environ .get ('XDG_CONFIG_DIRS' , '/etc/xdg' ).split (os .pathsep )
128+ DEFAULT_SYS_CFGFILES = [[ f for f in sorted (glob .glob (os .path .join (d , 'easybuild.d' , '*.cfg' )))] for d in XDG_CONFIG_DIRS ]
128129DEFAULT_USER_CFGFILE = os .path .join (XDG_CONFIG_HOME , 'easybuild' , 'config.cfg' )
129130
130131DEFAULT_LIST_PR_STATE = GITHUB_PR_STATE_OPEN
@@ -212,7 +213,11 @@ class EasyBuildOptions(GeneralOption):
212213 VERSION = this_is_easybuild ()
213214
214215 DEFAULT_LOGLEVEL = 'INFO'
215- DEFAULT_CONFIGFILES = DEFAULT_SYS_CFGFILES [:]
216+ # https://specifications.freedesktop.org/basedir-spec/latest/
217+ # says precedence should be
218+ # XDG_CONFIG_HOME > 1st entry of XDG_CONFIG_DIRS > 2nd entry ...
219+ # EasyBuild parses this list backwards, gives priority to last entry
220+ DEFAULT_CONFIGFILES = flatten (DEFAULT_SYS_CFGFILES [::- 1 ])
216221 if 'XDG_CONFIG_DIRS' not in os .environ :
217222 old_etc_location = os .path .join ('/etc' , 'easybuild.d' )
218223 if os .path .isdir (old_etc_location ) and glob .glob (os .path .join (old_etc_location , '*.cfg' )):
@@ -1329,7 +1334,7 @@ def show_default_configfiles(self):
13291334 "* user-level: %s" % os .path .join ('${XDG_CONFIG_HOME:-$HOME/.config}' , 'easybuild' , 'config.cfg' ),
13301335 " -> %s => %s" % (DEFAULT_USER_CFGFILE , ('not found' , 'found' )[os .path .exists (DEFAULT_USER_CFGFILE )]),
13311336 "* system-level: %s" % os .path .join ('${XDG_CONFIG_DIRS:-/etc/xdg}' , 'easybuild.d' , '*.cfg' ),
1332- " -> %s => %s" % (system_cfg_glob_paths , ', ' .join (DEFAULT_SYS_CFGFILES ) or "(no matches)" ),
1337+ " -> %s => %s" % (system_cfg_glob_paths , ', ' .join (flatten ( DEFAULT_SYS_CFGFILES ) ) or "(no matches)" ),
13331338 '' ,
13341339 "Default list of existing configuration files (%d): %s" % (found_cfgfile_cnt , found_cfgfile_list ),
13351340 ]
0 commit comments