Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: respect XDG spec for configuration files #300

Merged
merged 4 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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