ralphbean / taskw

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

taskrc includes as relative paths cause FileNotFoundError in taskw #150

Open smemsh opened 3 years ago

smemsh commented 3 years ago

TaskWarrior config files can have include directives which are specified as paths relative to the location of the rcfile. taskw library always tries to load the path as-is without searching for it using the algorithm that TaskWarrior does. This means it can only work with taskw if it is specified as absolute, or, if relative, the program happens to have its cwd in the .taskrc location.

Example .taskrc:

...
include .taskrc.private

this will crash with FileNotFoundError exception in taskw:

>>> from taskw import TaskWarrior
>>> tw = TaskWarrior()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/scott/.local/lib/python3.9/site-packages/taskw/warrior.py", line 434, in __init__
    super(TaskWarriorShellout, self).__init__(config_filename)
  File "/home/scott/.local/lib/python3.9/site-packages/taskw/warrior.py", line 61, in __init__
    self.config = TaskWarriorBase.load_config(config_filename)
  File "/home/scott/.local/lib/python3.9/site-packages/taskw/warrior.py", line 179, in load_config
    return TaskRc(config_filename, overrides=overrides)
  File "/home/scott/.local/lib/python3.9/site-packages/taskw/taskrc.py", line 58, in __init__
    config = self._read(self.path)
  File "/home/scott/.local/lib/python3.9/site-packages/taskw/taskrc.py", line 106, in _read
    TaskRc(right.strip())
  File "/home/scott/.local/lib/python3.9/site-packages/taskw/taskrc.py", line 58, in __init__
    config = self._read(self.path)
  File "/home/scott/.local/lib/python3.9/site-packages/taskw/taskrc.py", line 96, in _read
    with codecs.open(path, 'r', 'utf8') as config_file:
  File "/usr/local/bin/../../../opt/python-3.9.5/lib/python3.9/codecs.py", line 905, in open
    file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: '.taskrc.private'