-
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
Open
adam-gaia
wants to merge
7
commits into
ralphbean:develop
Choose a base branch
from
adam-gaia:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6ffddf1
feat: read taskwarrior from ~/.config/task/taskrc
adam-gaia 9a62264
fix: resolve homedir
adam-gaia 883fc15
fix: check XDG_CONFIG_DIR instead of ~/.config
adam-gaia a82f41d
fix: added docs for file not found error raised
adam-gaia b1fce65
fix: XDG_CONFIG_DIR -> XDG_CONFIG_HOME
adam-gaia cafc308
fix: assign TASKRC instead of making logic changes
adam-gaia 26610e2
fix: mirror taskwarrior's config discovery order
adam-gaia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import subprocess | ||
import sys | ||
import json | ||
from pathlib import Path | ||
|
||
import kitchen.text.converters | ||
|
||
|
@@ -32,9 +33,40 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
# Location of configuration file: either specified by TASKRC environment | ||
# variable, or ~/.taskrc (default). | ||
TASKRC = os.getenv("TASKRC", "~/.taskrc") | ||
def find_taskrc(): | ||
""" | ||
Find the location of the taskwarrior configuration file. | ||
|
||
Follows Taskwarrior's config discovery order | ||
* ${HOME}/.taskrc | ||
* ${TASKRC} | ||
* ${XDG_CONFIG_HOME}/task/taskrc | ||
|
||
Raises FileNotFoundError if either | ||
* Specified taskrc is not a file | ||
* No taskrc was found | ||
""" | ||
taskrc = Path.home() / ".taskrc" | ||
if taskrc.is_file(): | ||
return taskrc.as_posix() | ||
|
||
if "TASKRC" in os.environ: | ||
taskrc = Path(os.environ["TASKRC"]) | ||
if taskrc.is_file(): | ||
return taskrc.as_posix() | ||
else: | ||
raise FileNotFoundError("Environment variable 'TASKRC' did not resolve to a taskrc file") | ||
|
||
if "XDG_CONFIG_HOME" in os.environ.keys(): | ||
taskrc = Path(os.environ["XDG_CONFIG_HOME"]) / "task/taskrc" | ||
if taskrc.is_file(): | ||
return taskrc.as_posix() | ||
|
||
raise FileNotFoundError("Unable to find taskrc. Set environment variable 'TASKRC=<file>' for a non-standard location") | ||
|
||
|
||
TASKRC = find_taskrc() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason not to assign |
||
|
||
|
||
class TaskWarriorBase(metaclass=abc.ABCMeta): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.