-
Notifications
You must be signed in to change notification settings - Fork 46
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
Taskrc discovery: check ${XDG_CONFIG_DIR}/task/taskrc; raise execption if not found #163
base: develop
Are you sure you want to change the base?
Conversation
|
||
raise FileNotFoundError("Unable to find taskrc. Set environment variable 'TASKRC=<file>' for a non-standard location") | ||
|
||
|
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.
Any reason not to assign TASKRC = find_taskrc()
here? Then you wouldn't have to change anything else in this module and we could avoid the extra conditionals in this module.
taskw/warrior.py
Outdated
* Specified taskrc is not a file | ||
* No taskrc was found | ||
""" | ||
if "TASKRC" in os.environ.keys(): |
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.
FYI, python automatically applies the in
operator to dictionary keys so would be idiomatic to write this as if "TASKRC" in os.environ:
I'm assuming this is the order in which taskwarrior itself looks for a configuration file? |
I thought so, but I'm glad you asked because that made me double check. I was wrong. From the manual
I'll update to mirror that order. Edit: Fixed in latest commit |
By the way, thank you @ryneeverett for such a quick response! |
else: | ||
raise FileNotFoundError("Environment variable 'TASKRC' did not resolve to a taskrc file") | ||
|
||
if "XDG_CONFIG_HOME" in os.environ.keys(): |
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.
You could remove the .keys()
here as well.
Where are you reading this configuration file search order? https://taskwarrior.org/docs/configuration/ ? I don't know the whole lookup order but I'm pretty sure the |
From the man page:
I read this as:
I suspect you got it right the first time. |
I have my taskrc in
${XDG_CONFIG_HOME}/task/taskrc
, a location that taskwarrior checks by default. Since this is a default location, I would like to add support totaskw
to check without needing to set the TASKRC env var.I've added a function,
find_taskrc()
, that checks these locations, in this order:${TASKRC}
env var${HOME}/.taskrc
${XDG_CONFIG_HOME}/task/taskrc
Additionally, this function raises
FileNotFoundError
when eitherI'm happy to make changes to get the basic idea of searching
${XDG_CONFIG_HOME}/task/taskrc
in.