Skip to content

Commit

Permalink
feat: respect XDG spec for configuration files (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkvc authored Feb 17, 2023
1 parent 2a96b49 commit 5086039
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 0 additions & 2 deletions toggl/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from toggl.cli import helpers, types
from toggl.cli.themes import themes

DEFAULT_CONFIG_PATH = '~/.togglrc'

logger = logging.getLogger('toggl.cli.commands')
click_completion.init()

Expand Down
14 changes: 13 additions & 1 deletion toggl/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import click
import requests
from pbr import version
from pathlib import Path

from toggl.utils import metas, bootstrap, migrations
from toggl import exceptions
Expand Down Expand Up @@ -62,7 +63,18 @@ class IniConfigMixin:
'version': IniEntry('version', str),
}

DEFAULT_CONFIG_PATH = os.path.expanduser('~/.togglrc')
_old_file_path = Path.expanduser(Path('~/.togglrc'))

if "XDG_CONFIG_HOME" in os.environ:
_new_file_path = Path(os.environ["XDG_CONFIG_HOME"]).joinpath(".togglrc")

if _new_file_path.exists() or not _old_file_path.exists():
DEFAULT_CONFIG_PATH = _new_file_path
else:
DEFAULT_CONFIG_PATH = _old_file_path

else:
DEFAULT_CONFIG_PATH = _old_file_path

def __init__(self, config_path=sentinel, **kwargs): # type: (typing.Optional[str], **typing.Any) -> None
self._config_path = self.DEFAULT_CONFIG_PATH if config_path == sentinel else config_path
Expand Down

0 comments on commit 5086039

Please sign in to comment.