Skip to content

Commit

Permalink
Use XDG_CONFIG_DIRS value from XDG basedir spec
Browse files Browse the repository at this point in the history
The spec mandates `/etc/xdg` instead of `/etc` for the default value of `XDG_CONFIG_DIRS` [1].

[1] https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
  • Loading branch information
Patrice Peterson committed Aug 1, 2024
1 parent e913a78 commit 5724b91
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def terminal_supports_colors(stream):
CONFIG_ENV_VAR_PREFIX = 'EASYBUILD'

XDG_CONFIG_HOME = os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), ".config"))
XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc').split(os.pathsep)
XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep)
DEFAULT_SYS_CFGFILES = [f for d in XDG_CONFIG_DIRS for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))]
DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg')

Expand Down Expand Up @@ -1313,7 +1313,7 @@ def show_default_configfiles(self):
'',
"* user-level: %s" % os.path.join('${XDG_CONFIG_HOME:-$HOME/.config}', 'easybuild', 'config.cfg'),
" -> %s => %s" % (DEFAULT_USER_CFGFILE, ('not found', 'found')[os.path.exists(DEFAULT_USER_CFGFILE)]),
"* system-level: %s" % os.path.join('${XDG_CONFIG_DIRS:-/etc}', 'easybuild.d', '*.cfg'),
"* system-level: %s" % os.path.join('${XDG_CONFIG_DIRS:-/etc/xdg}', 'easybuild.d', '*.cfg'),
" -> %s => %s" % (system_cfg_glob_paths, ', '.join(DEFAULT_SYS_CFGFILES) or "(no matches)"),
'',
"Default list of existing configuration files (%d): %s" % (found_cfgfile_cnt, found_cfgfile_list),
Expand Down
10 changes: 5 additions & 5 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3493,7 +3493,7 @@ def test_show_default_configfiles(self):
'',
"* user-level: ${XDG_CONFIG_HOME:-$HOME/.config}/easybuild/config.cfg",
" -> %s",
"* system-level: ${XDG_CONFIG_DIRS:-/etc}/easybuild.d/*.cfg",
"* system-level: ${XDG_CONFIG_DIRS:-/etc/xdg}/easybuild.d/*.cfg",
" -> %s/easybuild.d/*.cfg => ",
])

Expand All @@ -3508,12 +3508,12 @@ def test_show_default_configfiles(self):
homecfgfile_str += " => found"
else:
homecfgfile_str += " => not found"
expected = expected_tmpl % ('(not set)', '(not set)', homecfgfile_str, '{/etc}')
expected = expected_tmpl % ('(not set)', '(not set)', homecfgfile_str, '{/etc/xdg}')
self.assertIn(expected, logtxt)

# to predict the full output, we need to take control over $HOME and $XDG_CONFIG_DIRS
os.environ['HOME'] = self.test_prefix
xdg_config_dirs = os.path.join(self.test_prefix, 'etc')
xdg_config_dirs = os.path.join(self.test_prefix, 'etc', 'xdg')
os.environ['XDG_CONFIG_DIRS'] = xdg_config_dirs

expected_tmpl += '\n'.join([
Expand All @@ -3538,12 +3538,12 @@ def test_show_default_configfiles(self):

xdg_config_home = os.path.join(self.test_prefix, 'home')
os.environ['XDG_CONFIG_HOME'] = xdg_config_home
xdg_config_dirs = [os.path.join(self.test_prefix, 'etc'), os.path.join(self.test_prefix, 'moaretc')]
xdg_config_dirs = [os.path.join(self.test_prefix, 'etc', 'xdg'), os.path.join(self.test_prefix, 'moaretc')]
os.environ['XDG_CONFIG_DIRS'] = os.pathsep.join(xdg_config_dirs)

# put various dummy cfgfiles in place
cfgfiles = [
os.path.join(self.test_prefix, 'etc', 'easybuild.d', 'config.cfg'),
os.path.join(self.test_prefix, 'etc', 'xdg', 'easybuild.d', 'config.cfg'),
os.path.join(self.test_prefix, 'moaretc', 'easybuild.d', 'bar.cfg'),
os.path.join(self.test_prefix, 'moaretc', 'easybuild.d', 'foo.cfg'),
os.path.join(xdg_config_home, 'easybuild', 'config.cfg'),
Expand Down

0 comments on commit 5724b91

Please sign in to comment.