Skip to content

Commit

Permalink
Only change order in DEFAULT_CONFIGFILES; XDG_CONFIG_DIRS in orig order
Browse files Browse the repository at this point in the history
This is a little easier to understand.
  • Loading branch information
bartoldeman committed Sep 12, 2024
1 parent 7790978 commit d010c99
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions easybuild/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
from easybuild.tools.repository.repository import avail_repositories
from easybuild.tools.systemtools import DARWIN, UNKNOWN, check_python_version, get_cpu_architecture, get_cpu_family
from easybuild.tools.systemtools import get_cpu_features, get_gpu_info, get_os_type, get_system_info
from easybuild.tools.utilities import flatten
from easybuild.tools.version import this_is_easybuild


Expand All @@ -123,8 +124,8 @@ 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/xdg').split(os.pathsep)[::-1]
DEFAULT_SYS_CFGFILES = [f for d in XDG_CONFIG_DIRS for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))]
XDG_CONFIG_DIRS = os.environ.get('XDG_CONFIG_DIRS', '/etc/xdg').split(os.pathsep)
DEFAULT_SYS_CFGFILES = [[f for f in sorted(glob.glob(os.path.join(d, 'easybuild.d', '*.cfg')))] for d in XDG_CONFIG_DIRS]
DEFAULT_USER_CFGFILE = os.path.join(XDG_CONFIG_HOME, 'easybuild', 'config.cfg')

DEFAULT_LIST_PR_STATE = GITHUB_PR_STATE_OPEN
Expand Down Expand Up @@ -212,7 +213,11 @@ class EasyBuildOptions(GeneralOption):
VERSION = this_is_easybuild()

DEFAULT_LOGLEVEL = 'INFO'
DEFAULT_CONFIGFILES = DEFAULT_SYS_CFGFILES[:]
# https://specifications.freedesktop.org/basedir-spec/latest/
# says precedence should be
# XDG_CONFIG_HOME > 1st entry of XDG_CONFIG_DIRS > 2nd entry ...
# EasyBuild parses this list backwards, gives priority to last entry
DEFAULT_CONFIGFILES = flatten(DEFAULT_SYS_CFGFILES[::-1])
if 'XDG_CONFIG_DIRS' not in os.environ:
old_etc_location = os.path.join('/etc', 'easybuild.d')
if os.path.isdir(old_etc_location) and glob.glob(os.path.join(old_etc_location, '*.cfg')):
Expand Down Expand Up @@ -1329,7 +1334,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/xdg}', 'easybuild.d', '*.cfg'),
" -> %s => %s" % (system_cfg_glob_paths, ', '.join(DEFAULT_SYS_CFGFILES) or "(no matches)"),
" -> %s => %s" % (system_cfg_glob_paths, ', '.join(flatten(DEFAULT_SYS_CFGFILES)) or "(no matches)"),
'',
"Default list of existing configuration files (%d): %s" % (found_cfgfile_cnt, found_cfgfile_list),
]
Expand Down
4 changes: 2 additions & 2 deletions test/framework/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3563,8 +3563,8 @@ def test_show_default_configfiles(self):
logtxt = read_file(self.logfile)
expected = expected_tmpl % (xdg_config_home, os.pathsep.join(xdg_config_dirs),
"%s => found" % os.path.join(xdg_config_home, 'easybuild', 'config.cfg'),
'{' + ', '.join(xdg_config_dirs[::-1]) + '}',
', '.join(cfgfiles[:-1]), 4, ', '.join(cfgfiles))
'{' + ', '.join(xdg_config_dirs) + '}',
', '.join(cfgfiles[1:3]+[cfgfiles[0]]), 4, ', '.join(cfgfiles))
self.assertIn(expected, logtxt)

del os.environ['XDG_CONFIG_DIRS']
Expand Down

0 comments on commit d010c99

Please sign in to comment.