Skip to content

Commit dcf6974

Browse files
committed
Merge branch 'develop'
2 parents 2fd5546 + 922cec4 commit dcf6974

9 files changed

Lines changed: 488 additions & 324 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
.cache
12
*.pyc
23
*~
34
tasklib.egg-info
45
/dist
56
/build
67
docs/_build
8+
.project
9+
.coverage

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ env:
1111
- TASK_VERSION=v2.4.4
1212
- TASK_VERSION=v2.5.0
1313
- TASK_VERSION=v2.5.1
14-
- TASK_VERSION=2.6.0
1514
python:
1615
- "2.7"
1716
- "3.3"
@@ -25,8 +24,8 @@ install:
2524
- sudo apt-get update -qq
2625
- sudo apt-get install -qq build-essential cmake uuid-dev g++-4.8
2726
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
28-
- git clone --recursive https://git.tasktools.org/scm/tm/task.git
29-
- cd task
27+
- git clone --recursive https://github.com/GothenburgBitFactory/taskwarrior
28+
- cd taskwarrior
3029
- git checkout $TASK_VERSION
3130
- git clean -dfx
3231
- git submodule init

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Usage
3030

3131
tasklib has a similar API to that of Django's ORM::
3232

33-
>>> from tasklib.task import TaskWarrior
33+
>>> from tasklib import TaskWarrior
3434

3535
>>> tw = TaskWarrior('/home/rob/.task')
3636
>>> tasks = tw.tasks.pending()
@@ -40,7 +40,7 @@ tasklib has a similar API to that of Django's ORM::
4040
['Tidy the house']
4141
>>> type(tasks[0])
4242
<class 'tasklib.task.Task'>
43-
>>> task[0].done()
43+
>>> tasks[0].done()
4444
>>> tasks = tw.tasks.pending()
4545
>>> tasks
4646
['Learn German']

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
# built documents.
5252
#
5353
# The short X.Y version.
54-
version = '1.1.0'
54+
version = '1.2.0'
5555
# The full version, including alpha/beta/rc tags.
56-
release = '1.1.0'
56+
release = '1.2.0'
5757

5858
# The language for content autogenerated by Sphinx. Refer to documentation
5959
# for a list of supported languages.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
install_requirements = ['six>=1.4', 'pytz', 'tzlocal']
44

5-
version = '1.1.0'
5+
version = '1.2.0'
66

77
try:
88
import importlib

tasklib/backends.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,22 @@ class TaskWarrior(Backend):
9494
VERSION_2_4_4 = six.u('2.4.4')
9595
VERSION_2_4_5 = six.u('2.4.5')
9696

97-
def __init__(self, data_location=None, create=True, taskrc_location='~/.taskrc'):
98-
self.taskrc_location = os.path.expanduser(taskrc_location)
97+
def __init__(self, data_location=None, create=True,
98+
taskrc_location=None, task_command='task',
99+
version_override=None):
100+
self.taskrc_location = None
101+
if taskrc_location:
102+
self.taskrc_location = os.path.expanduser(taskrc_location)
99103

100-
# If taskrc does not exist, pass / to use defaults and avoid creating
101-
# dummy .taskrc file by TaskWarrior
102-
if not os.path.exists(self.taskrc_location):
103-
self.taskrc_location = '/'
104+
# If taskrc does not exist, pass / to use defaults and avoid creating
105+
# dummy .taskrc file by TaskWarrior
106+
if not os.path.exists(self.taskrc_location):
107+
self.taskrc_location = '/'
108+
109+
self.task_command = task_command
104110

105111
self._config = None
106-
self.version = self._get_version()
112+
self.version = version_override or self._get_version()
107113
self.overrides = {
108114
'confirmation': 'no',
109115
'dependency.confirmation': 'no', # See TW-1483 or taskrc man page
@@ -126,8 +132,11 @@ def __init__(self, data_location=None, create=True, taskrc_location='~/.taskrc')
126132

127133
self.tasks = TaskQuerySet(self)
128134

135+
def _get_task_command(self):
136+
return self.task_command.split()
137+
129138
def _get_command_args(self, args, config_override=None):
130-
command_args = ['task', 'rc:{0}'.format(self.taskrc_location)]
139+
command_args = self._get_task_command()
131140
overrides = self.overrides.copy()
132141
overrides.update(config_override or dict())
133142
for item in overrides.items():
@@ -140,7 +149,7 @@ def _get_command_args(self, args, config_override=None):
140149

141150
def _get_version(self):
142151
p = subprocess.Popen(
143-
['task', '--version'],
152+
self._get_task_command() + ['--version'],
144153
stdout=subprocess.PIPE,
145154
stderr=subprocess.PIPE)
146155
stdout, stderr = [x.decode('utf-8') for x in p.communicate()]
@@ -214,21 +223,25 @@ def format_description(self, task):
214223
if self.version < self.VERSION_2_4_0:
215224
return task._data['description']
216225
else:
217-
return six.u("description:'{0}'").format(task._data['description'] or '')
226+
return six.u("description:'{0}'").format(
227+
task._data['description'] or '',
228+
)
218229

219230
def convert_datetime_string(self, value):
220231

221232
if self.version >= self.VERSION_2_4_0:
222-
# For strings, use 'task calc' to evaluate the string to datetime
233+
# For strings, use 'calc' to evaluate the string to datetime
223234
# available since TW 2.4.0
224235
args = value.split()
225236
result = self.execute_command(['calc'] + args)
226237
naive = datetime.datetime.strptime(result[0], DATE_FORMAT_CALC)
227238
localized = local_zone.localize(naive)
228239
else:
229-
raise ValueError("Provided value could not be converted to "
230-
"datetime, its type is not supported: {}"
231-
.format(type(value)))
240+
raise ValueError(
241+
'Provided value could not be converted to '
242+
'datetime, its type is not supported: {}'
243+
.format(type(value)),
244+
)
232245

233246
return localized
234247

@@ -269,8 +282,11 @@ def execute_command(self, args, config_override=None, allow_failure=True,
269282
args, config_override=config_override)
270283
logger.debug(u' '.join(command_args))
271284

285+
env = os.environ.copy()
286+
if self.taskrc_location:
287+
env['TASKRC'] = self.taskrc_location
272288
p = subprocess.Popen(command_args, stdout=subprocess.PIPE,
273-
stderr=subprocess.PIPE)
289+
stderr=subprocess.PIPE, env=env)
274290
stdout, stderr = [x.decode('utf-8') for x in p.communicate()]
275291
if p.returncode and allow_failure:
276292
if stderr.strip():
@@ -338,8 +354,10 @@ def save_task(self, task):
338354
# Expected output: Created task 1.
339355
# Created task 1 (recurrence template).
340356
if len(id_lines) != 1 or len(id_lines[0].split(' ')) not in (3, 5):
341-
raise TaskWarriorException("Unexpected output when creating "
342-
"task: %s" % '\n'.join(id_lines))
357+
raise TaskWarriorException(
358+
'Unexpected output when creating '
359+
'task: %s' % '\n'.join(id_lines),
360+
)
343361

344362
# Circumvent the ID storage, since ID is considered read-only
345363
identifier = id_lines[0].split(' ')[2].rstrip('.')
@@ -411,8 +429,8 @@ def valid(output):
411429
# If more than 1 task has been matched still, raise an exception
412430
if not valid(output):
413431
raise TaskWarriorException(
414-
"Unique identifiers {0} with description: {1} matches "
415-
"multiple tasks: {2}".format(
432+
'Unique identifiers {0} with description: {1} matches '
433+
'multiple tasks: {2}'.format(
416434
task['uuid'] or task['id'], task['description'], output)
417435
)
418436

tasklib/lazy.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __hash__(self):
4343
return self['uuid'].__hash__()
4444

4545
def __repr__(self):
46-
return "LazyUUIDTask: {0}".format(self._uuid)
46+
return 'LazyUUIDTask: {0}'.format(self._uuid)
4747

4848
def __copy__(self):
4949
return LazyUUIDTask(self._tw, self._uuid)
@@ -103,7 +103,7 @@ def __getattr__(self, name):
103103
return getattr(self, name)
104104

105105
def __repr__(self):
106-
return "LazyUUIDTaskSet([{0}])".format(', '.join(self._uuids))
106+
return 'LazyUUIDTaskSet([{0}])'.format(', '.join(self._uuids))
107107

108108
def __eq__(self, other):
109109
return set(t['uuid'] for t in other) == self._uuids
@@ -128,8 +128,10 @@ def __isub__(self, other):
128128
return self.difference_update(other)
129129

130130
def __rsub__(self, other):
131-
return LazyUUIDTaskSet(self._tw,
132-
set(t['uuid'] for t in other) - self._uuids)
131+
return LazyUUIDTaskSet(
132+
self._tw,
133+
set(t['uuid'] for t in other) - self._uuids,
134+
)
133135

134136
def __or__(self, other):
135137
return self.union(other)
@@ -171,20 +173,28 @@ def issuperset(self, other):
171173
return all([task in self for task in other])
172174

173175
def union(self, other):
174-
return LazyUUIDTaskSet(self._tw,
175-
self._uuids | set(t['uuid'] for t in other))
176+
return LazyUUIDTaskSet(
177+
self._tw,
178+
self._uuids | set(t['uuid'] for t in other),
179+
)
176180

177181
def intersection(self, other):
178-
return LazyUUIDTaskSet(self._tw,
179-
self._uuids & set(t['uuid'] for t in other))
182+
return LazyUUIDTaskSet(
183+
self._tw,
184+
self._uuids & set(t['uuid'] for t in other),
185+
)
180186

181187
def difference(self, other):
182-
return LazyUUIDTaskSet(self._tw,
183-
self._uuids - set(t['uuid'] for t in other))
188+
return LazyUUIDTaskSet(
189+
self._tw,
190+
self._uuids - set(t['uuid'] for t in other),
191+
)
184192

185193
def symmetric_difference(self, other):
186-
return LazyUUIDTaskSet(self._tw,
187-
self._uuids ^ set(t['uuid'] for t in other))
194+
return LazyUUIDTaskSet(
195+
self._tw,
196+
self._uuids ^ set(t['uuid'] for t in other),
197+
)
188198

189199
def update(self, other):
190200
self._uuids |= set(t['uuid'] for t in other)

0 commit comments

Comments
 (0)