ralphbean / taskw

python taskwarrior api
http://threebean.org
GNU General Public License v3.0
175 stars 47 forks source link

TaskWarrior.load_config() ignores TASKRC environment variable #94

Closed khaeru closed 9 years ago

khaeru commented 9 years ago

I have set the TASKRC environment variable to set a custom location for the taskwarrior configuration file:

$ env | grep TASK
TASKRC=/home/khaeru/vc/dotfiles/taskwarrior

I installed the taskwarrior-time-tracking-hook by @kostajh, but it fails because taskw does not check this environment variable and instead looks for the configuration file at ~/.taskrc:

$ task 43 stop
Traceback (most recent call last):
  File "/home/khaeru/.local/share/taskwarrior/hooks/on-modify.timetracking", line 9, in <module>
    load_entry_point('taskwarrior-time-tracking-hook==0.1.4', 'console_scripts', 'taskwarrior_time_tracking_hook')()
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 356, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2476, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2190, in load
    ['__name__'])
  File "/home/khaeru/vc/other/taskwarrior-time-tracking-hook/taskwarrior_time_tracking_hook/__init__.py", line 11, in <module>
    w = TaskWarrior()
  File "/home/khaeru/.local/lib/python3.4/site-packages/taskw/warrior.py", line 453, in __init__
    super(TaskWarriorShellout, self).__init__(config_filename)
  File "/home/khaeru/.local/lib/python3.4/site-packages/taskw/warrior.py", line 54, in __init__
    self.config = TaskWarriorBase.load_config(config_filename)
  File "/home/khaeru/.local/lib/python3.4/site-packages/taskw/warrior.py", line 173, in load_config
    with open(os.path.expanduser(config_filename), 'r') as f:
  File "/home/khaeru/.local/lib/python3.4/site-packages/taskw/warrior.py", line 37, in <lambda>
    open = lambda fname, mode: codecs.open(fname, mode, "utf-8")
  File "/usr/lib/python3.4/codecs.py", line 896, in open
    file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: '/home/khaeru/.taskrc'
Hook Error: Expected feedback from a failing hook script.
ralphbean commented 9 years ago

Hm, since taskw is a library.. I'm not sure it should be responsible for checking environment variables. Should taskwarrior-time-tracking-hook do this instead and pass the value to taskw? @kostajh, do you have an opinion on this?

coddingtonbear commented 9 years ago

Hrm -- I hadn't realized that that environment variable could be used to point at one's Taskrc file. Given that we already automatically calculate where one's Taskrc file is in taskw, though, I think it might make the most sense to do this calculation in taskw. Even better: if it's possible for us to ask taskwarrior where it will be reading its config from, we could use that path?

On Tue, Feb 24, 2015 at 12:19 PM, Ralph Bean notifications@github.com wrote:

Hm, since taskw is a library.. I'm not sure it should be responsible for checking environment variables. Should taskwarrior-time-tracking-hook do this instead and pass the value to taskw? @kostajh https://github.com/kostajh, do you have an opinion on this?

— Reply to this email directly or view it on GitHub https://github.com/ralphbean/taskw/issues/94#issuecomment-75837209.

khaeru commented 9 years ago

This could be as simple as replacing "~/.taskrc" with os.getenv('TASKRC', '~/.taskrc'). Since the former appears in multiple places, perhaps set a global variable near the top of warrior.py:

TASKRC = os.getenv('TASKRC', '~/.taskrc')

…if that's consistent with your coding style.

ralphbean commented 9 years ago

Sure. Want to submit the pull-request @khaeru?