1 From 958b63ceec02b179482141cfb846ddbcae711a1b Mon Sep 17 00:00:00 2001
2 From: Scott Mcdermott <scott@smemsh.net>
3 Date: Sat, 28 Aug 2021 21:12:38 -0700
4 Subject: [PATCH] RcFile: _read: try taskrc directory when trying to load
7 Taskwarrior itself tries includes as absolute path, then cwd, then
8 relative to rcfile, then in various search paths (see
9 GothenburgBitFactory/libshared -> src/Configuration.cpp ->
10 Configuration::parse()).
12 We won't try to duplicate that whole arrangement here, but at least look
13 relative to the rcfile in addition to cwd/absolute, like taskwarrior
14 does. This will allow specification as relative path in most cases.
15 Otherwise, we'd have to chdir anyways because includes are always tried
16 as-is by taskw. They would only work if specified as absolute paths or
19 We use a TaskRc() class variable to store the rcdir because there could
20 be an include chain and all the instances will need to know the same
21 one, but will be processing different paths, so we have to capture the
22 directory of the first one processed, ie the base rcfile.
26 Co-authored-by: Raito Bezarius <masterancpp@gmail.com>
28 taskw/taskrc.py | 15 +++++++++++++++
29 1 file changed, 15 insertions(+)
31 diff --git a/taskw/taskrc.py b/taskw/taskrc.py
32 index 1b6f8e5..b72dee6 100644
40 from taskw.fields import (
42 @@ -39,6 +40,7 @@ class TaskRc(dict):
49 'duration': DurationField,
50 @@ -54,6 +56,8 @@ class TaskRc(dict):
55 + TaskRc.rcdir = os.path.dirname(os.path.realpath(self.path))
56 config = self._read(self.path)
59 @@ -92,6 +96,17 @@ class TaskRc(dict):
61 def _read(self, path):
63 + if not os.path.exists(path) and TaskRc.rcdir is not None:
64 + # include path may be given relative to dir of rcfile
66 + path = os.path.join(TaskRc.rcdir, oldpath)
67 + if not os.path.exists(path):
69 + "rcfile does not exist, tried %s and %s",
72 + raise FileNotFoundError
74 with open(path, 'r') as config_file:
75 for raw_line in config_file.readlines():
76 line = sanitize(raw_line)