This commit is contained in:
Noa Emien 2026-01-06 08:16:15 -03:00 committed by GitHub
commit 9b82a85895
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View File

@ -38,6 +38,7 @@ class _Location(enum.Enum):
APPNAME = 'qutebrowser'
CONFIG_LOCATIONS = [os.path.normpath(os.getenv('XDG_CONFIG_HOME', '~/.config')) + '/', '~/.']
class EmptyValueError(Exception):
@ -82,7 +83,7 @@ def _init_config(args: Optional[argparse.Namespace]) -> None:
if utils.is_mac:
path = _from_args(typ, args)
if path is None: # pragma: no branch
path = os.path.expanduser('~/.' + APPNAME)
path = _get_config_location()
_create(path)
_locations[_Location.config] = path
@ -93,6 +94,18 @@ def _init_config(args: Optional[argparse.Namespace]) -> None:
_locations[_Location.config_py] = config_py_file
def _get_config_location() -> str:
"""Get the optimal location for the config directory on disk.
Searches CONFIG_LOCATIONS in order for existing config folder, defaults to
CONFIG_LOCATIONS[0]
"""
it = (p + APPNAME for p in CONFIG_LOCATIONS if
os.path.exists(os.path.expanduser(p + APPNAME)))
path = next(it, CONFIG_LOCATIONS[0] + APPNAME)
return os.path.expanduser(path)
def config(auto: bool = False) -> str:
"""Get the location for the config directory.

View File

@ -74,7 +74,7 @@ def test_unset_organization_no_qapp(monkeypatch):
@pytest.mark.posix
def test_fake_mac_config(tmp_path, fake_home_envvar):
"""Test standardir.config on a fake Mac."""
expected = str(tmp_path) + '/.qute_test' # always with /
expected = str(tmp_path) + '/.config/qute_test' # always with /
standarddir._init_config(args=None)
assert standarddir.config() == expected
@ -220,7 +220,7 @@ class TestStandardDir:
(standarddir.data, 2, ['Application Support', APPNAME]),
(lambda: standarddir.config(auto=True), 1, [APPNAME]),
(standarddir.config, 0,
os.path.expanduser('~').split(os.sep) + ['.qute_test']),
os.path.expanduser('~').split(os.sep) + ['.config'] + ['qute_test']),
(standarddir.cache, 2, ['Caches', APPNAME]),
(standarddir.download, 1, ['Downloads']),
])