-
Notifications
You must be signed in to change notification settings - Fork 69
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
Conversation
Thanks for the new PR! I'm bit confused thought. Shouldn't this PR add support for the XDG spec? I don't see usage of the expected env. variable... Or does the Path module handle this as expected? |
The Path module handles it automatically. This PR actually updates the old |
Hmmm, I don't know about it. Quick googling nor the documentation did not confirm that the |
Yeah, I thought so. That is the reason why #126 was created...
Yeah I would go with the route to check if it is set and if so, to use that otherwise, fall back to the IMHO, it is not our problem as to what is the |
If XDG_CONFIG_HOME is set, use it; or else default to $HOME(~) directory.
Sorry, it was only that specific container.. Hence, we can just check if There you go. Done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually 🙈 I thought about it a bit more and realize that this is a breaking change, which we can and should avoid in this form.
The problem is that existing users have their configuration under ~/.togglrc
. For users that have configured XDG_CONFIG_HOME
and updated toggl-cli to the new version with this change, toggl-cli will look for configuration under $XDG_CONFIG_HOME/.togglrc
, which will fail because it does not exist. But it exists under ~/.togglrc
... Which will break things.
I would therefore suggest this solution. If XDG_CONFIG_HOME
is configured, and $XDG_CONFIG_HOME/.togglrc
does not exists, fallback to ~/.togglrc
. We could also log a warning for this case.
We could potentially move the configuration from the old place to the new one, but IMHO, that is too proactive and magical behavior, and I would leave the move up to the user so he is aware of that.
Yes, I didn't consider this possibility. I think this sentence is misinterpreting or I might be wrong; |
Yeah, fallback to trying |
Wait, I'm confused. Aren't we creating Edit: This should be better I guess. If 👍 , I will push the changes. _file_path = Path.expanduser(Path('~/.togglrc'))
if "XDG_CONFIG_HOME" in os.environ and not _file_path.exists():
DEFAULT_CONFIG_PATH = Path(os.environ["XDG_CONFIG_HOME"]).joinpath(".togglrc")
else:
DEFAULT_CONFIG_PATH = _file_path |
I suppose this should be able to cover all the mentioned edge cases. Shall _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 |
Yes, that looks about right! 👍 |
if XDG_CONFIG_HOME in os.env: if XDG_CONFIG_HOME/.togglrc exists or ~/.togglrc does not exist: USE XDG_CONFIG_HOME/.togglrc else: FALLBACK to ~/.togglrc else: FALLBACK to ~/.togglrc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the tweaks! 👍
Use Path.expanduser from pathlib module instead of os module
Remove redundant DEFAULT_CONFIG_PATH in commands.py
Closes #126