Skip to content

Commit d010c99

Browse files
committed
Only change order in DEFAULT_CONFIGFILES; XDG_CONFIG_DIRS in orig order
This is a little easier to understand.
1 parent 7790978 commit d010c99

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

easybuild/tools/options.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
from easybuild.tools.repository.repository import avail_repositories
106106
from easybuild.tools.systemtools import DARWIN, UNKNOWN, check_python_version, get_cpu_architecture, get_cpu_family
107107
from easybuild.tools.systemtools import get_cpu_features, get_gpu_info, get_os_type, get_system_info
108+
from easybuild.tools.utilities import flatten
108109
from easybuild.tools.version import this_is_easybuild
109110

110111

@@ -123,8 +124,8 @@ def terminal_supports_colors(stream):
123124
CONFIG_ENV_VAR_PREFIX = 'EASYBUILD'
124125

125126
XDG_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]
128129
DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg')
129130

130131
DEFAULT_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
]

test/framework/options.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3563,8 +3563,8 @@ def test_show_default_configfiles(self):
35633563
logtxt = read_file(self.logfile)
35643564
expected = expected_tmpl % (xdg_config_home, os.pathsep.join(xdg_config_dirs),
35653565
"%s => found" % os.path.join(xdg_config_home, 'easybuild', 'config.cfg'),
3566-
'{' + ', '.join(xdg_config_dirs[::-1]) + '}',
3567-
', '.join(cfgfiles[:-1]), 4, ', '.join(cfgfiles))
3566+
'{' + ', '.join(xdg_config_dirs) + '}',
3567+
', '.join(cfgfiles[1:3]+[cfgfiles[0]]), 4, ', '.join(cfgfiles))
35683568
self.assertIn(expected, logtxt)
35693569

35703570
del os.environ['XDG_CONFIG_DIRS']

0 commit comments

Comments
 (0)