Skip to content

Commit fa0fbd6

Browse files
committed
Apply black changes.
1 parent a271323 commit fa0fbd6

8 files changed

Lines changed: 179 additions & 177 deletions

File tree

setup.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,48 @@ def get_version(package):
1111
"""
1212
Return package version as listed in `__version__` in `init.py`.
1313
"""
14-
init_py = open(os.path.join(package, '__init__.py')).read()
14+
init_py = open(os.path.join(package, "__init__.py")).read()
1515
return re.search("__version__ = ['\"]([^'\"]+)['\"]", init_py).group(1)
1616

1717

1818
def get_packages(package):
1919
"""
2020
Return root package and all sub-packages.
2121
"""
22-
return [dirpath
23-
for dirpath, dirnames, filenames in os.walk(package)
24-
if os.path.exists(os.path.join(dirpath, '__init__.py'))]
22+
return [
23+
dirpath
24+
for dirpath, dirnames, filenames in os.walk(package)
25+
if os.path.exists(os.path.join(dirpath, "__init__.py"))
26+
]
2527

2628

2729
def get_package_data(package):
2830
"""
2931
Return all files under the root package, that are not in a
3032
package themselves.
3133
"""
32-
walk = [(dirpath.replace(package + os.sep, '', 1), filenames)
33-
for dirpath, dirnames, filenames in os.walk(package)
34-
if not os.path.exists(os.path.join(dirpath, '__init__.py'))]
34+
walk = [
35+
(dirpath.replace(package + os.sep, "", 1), filenames)
36+
for dirpath, dirnames, filenames in os.walk(package)
37+
if not os.path.exists(os.path.join(dirpath, "__init__.py"))
38+
]
3539

3640
filepaths = []
3741
for base, filenames in walk:
38-
filepaths.extend([os.path.join(base, filename)
39-
for filename in filenames])
42+
filepaths.extend([os.path.join(base, filename) for filename in filenames])
4043
return {package: filepaths}
4144

4245

43-
version = get_version('taskflow')
46+
version = get_version("taskflow")
4447

4548

4649
setup(
47-
name='taskflow',
50+
name="taskflow",
4851
version=version,
49-
url='https://git@github.com/Vectorworks/taskflow.git',
50-
description='A simple workflow library.',
51-
packages=get_packages('taskflow'),
52-
package_data=get_package_data('taskflow'),
53-
install_requires=[
54-
],
55-
dependency_links=[
56-
]
52+
url="https://git@github.com/Vectorworks/taskflow.git",
53+
description="A simple workflow library.",
54+
packages=get_packages("taskflow"),
55+
package_data=get_package_data("taskflow"),
56+
install_requires=[],
57+
dependency_links=[],
5758
)

taskflow/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
__title__ = 'Taskflow'
2-
__version__ = '0.2.0'
1+
__title__ = "Taskflow"
2+
__version__ = "0.2.0"
33

44
from .flow import * # noqa
55
from .tasks import * # noqa

taskflow/flow.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Flow(object):
99
def __init__(self, task: BaseTask, uid=None, friendly_name=None):
1010
self.uid = uid or uuid4()
11-
self.friendly_name = friendly_name or ''
11+
self.friendly_name = friendly_name or ""
1212
self.root_task = BaseTask.find_root(task)
1313

1414
# when deserializing, tasks will already have ids, that we want to preserve
@@ -92,13 +92,14 @@ def from_list(cls, task_list: list, uid=None, friendly_name=None):
9292

9393
while remaining_tasks:
9494
for task_data in remaining_tasks:
95-
task_depends_on = ([task_data['prev']] if task_data['prev'] else []) + \
96-
(task_data.get('sub_tasks') or [])
95+
task_depends_on = ([task_data["prev"]] if task_data["prev"] else []) + (
96+
task_data.get("sub_tasks") or []
97+
)
9798

9899
if all(depends_on in created for depends_on in task_depends_on):
99-
task_type = type_from_string(task_data['class'])
100-
task_data['sub_tasks'] = [created[task_id] for task_id in (task_data.get('sub_tasks') or [])]
101-
task_data['prev'] = created[task_data['prev']] if task_data['prev'] else None
100+
task_type = type_from_string(task_data["class"])
101+
task_data["sub_tasks"] = [created[task_id] for task_id in (task_data.get("sub_tasks") or [])]
102+
task_data["prev"] = created[task_data["prev"]] if task_data["prev"] else None
102103

103104
last_created = task_type.from_data(task_data)
104105

taskflow/tasks.py

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66

77
class BaseTask(object):
8-
STATUS_PENDING = 'pending'
9-
STATUS_RUNNING = 'running'
10-
STATUS_HALTED = 'halted'
11-
STATUS_COMPLETE = 'complete'
8+
STATUS_PENDING = "pending"
9+
STATUS_RUNNING = "running"
10+
STATUS_HALTED = "halted"
11+
STATUS_COMPLETE = "complete"
1212

1313
is_standalone = True
1414

@@ -131,7 +131,8 @@ def find_root(cls, task):
131131
def then(self, task):
132132
if self._next:
133133
raise RuntimeError(
134-
'Unsupported operation. Multiple then operations are not support. Use a CompositeTask instead.')
134+
"Unsupported operation. Multiple then operations are not support. Use a CompositeTask instead."
135+
)
135136

136137
task = task.local_root
137138
self._next = task
@@ -140,23 +141,25 @@ def then(self, task):
140141

141142
def _get_task_data(self):
142143
return {
143-
'class': type_to_string(type(self)),
144-
'max_runs': self.max_runs,
145-
'id': self._id,
146-
'name': self._name,
147-
'needs_prev_result': self._needs_prev_result,
148-
'runs': self._runs,
149-
'status': self._status,
150-
'result': self._result,
151-
'is_standalone': self.is_standalone
144+
"class": type_to_string(type(self)),
145+
"max_runs": self.max_runs,
146+
"id": self._id,
147+
"name": self._name,
148+
"needs_prev_result": self._needs_prev_result,
149+
"runs": self._runs,
150+
"status": self._status,
151+
"result": self._result,
152+
"is_standalone": self.is_standalone,
152153
}
153154

154155
def to_list(self):
155156
result = [self._get_task_data()]
156-
result[0].update({
157-
'prev': self._prev.id if self._prev else None,
158-
'next': self._next.id if self._next else None,
159-
})
157+
result[0].update(
158+
{
159+
"prev": self._prev.id if self._prev else None,
160+
"next": self._next.id if self._next else None,
161+
}
162+
)
160163

161164
if self._next:
162165
result.extend(self._next.to_list())
@@ -167,16 +170,16 @@ def to_list(self):
167170
def from_data(cls, task_data):
168171
result = cls()
169172

170-
result.max_runs = task_data['max_runs']
171-
result._runs = task_data['runs']
172-
result._status = task_data['status']
173-
result._result = task_data['result']
174-
result._id = task_data['id']
175-
result._name = task_data['name']
176-
result._needs_prev_result = task_data['needs_prev_result']
173+
result.max_runs = task_data["max_runs"]
174+
result._runs = task_data["runs"]
175+
result._status = task_data["status"]
176+
result._result = task_data["result"]
177+
result._id = task_data["id"]
178+
result._name = task_data["name"]
179+
result._needs_prev_result = task_data["needs_prev_result"]
177180

178-
if task_data['prev']:
179-
task_data['prev'].then(result)
181+
if task_data["prev"]:
182+
task_data["prev"].then(result)
180183

181184
return result
182185

@@ -216,22 +219,19 @@ def run(self, **kwargs):
216219
self._exc_info = sys.exc_info()
217220

218221
def __str__(self):
219-
return self._name if self._name else f'{function_to_string(self._func)}:{self._args}'
222+
return self._name if self._name else f"{function_to_string(self._func)}:{self._args}"
220223

221224
def _get_task_data(self):
222225
result = super()._get_task_data()
223-
result.update({
224-
'func': function_to_string(self._func),
225-
'args': self._args
226-
})
226+
result.update({"func": function_to_string(self._func), "args": self._args})
227227

228228
return result
229229

230230
@classmethod
231231
def from_data(cls, task_data):
232232
result = super().from_data(task_data)
233-
result._func = function_from_string(task_data['func'])
234-
result._args = task_data['args']
233+
result._func = function_from_string(task_data["func"])
234+
result._args = task_data["args"]
235235
return result
236236

237237
@classmethod
@@ -282,24 +282,22 @@ def get_all_tasks(self):
282282
return self._sub_tasks[:]
283283

284284
def run(self, **kwargs):
285-
raise RuntimeError('Composite tasks cannot be run directly')
285+
raise RuntimeError("Composite tasks cannot be run directly")
286286

287287
def to_list(self):
288288
result = []
289289
for sub_task in self._sub_tasks:
290290
result += sub_task.to_list()
291291

292292
base_list = super().to_list()
293-
base_list[0].update({
294-
'sub_tasks': [sub_task.id for sub_task in self._sub_tasks]
295-
})
293+
base_list[0].update({"sub_tasks": [sub_task.id for sub_task in self._sub_tasks]})
296294

297295
return result + base_list
298296

299297
@classmethod
300298
def from_data(cls, task_data):
301299
result = super().from_data(task_data)
302-
result._sub_tasks = [sub_task.local_root for sub_task in task_data['sub_tasks'] or []]
300+
result._sub_tasks = [sub_task.local_root for sub_task in task_data["sub_tasks"] or []]
303301
for sub_task in result._sub_tasks:
304302
sub_task._parent = result
305303

taskflow/test/test_flow.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99

1010
class TestFlow(object):
1111
def test_init(self, mocker):
12-
mocker.patch('taskflow.tasks.BaseTask.set_ids')
12+
mocker.patch("taskflow.tasks.BaseTask.set_ids")
1313

1414
uid = uuid4()
1515
root = BaseTask()
1616

17-
flow = Flow(root.then(BaseTask()), uid=uid, friendly_name='test-flow')
17+
flow = Flow(root.then(BaseTask()), uid=uid, friendly_name="test-flow")
1818

1919
assert flow.root_task == root
2020
assert flow.uid == uid
21-
assert flow.friendly_name == 'test-flow'
21+
assert flow.friendly_name == "test-flow"
2222
root.set_ids.assert_called_once_with()
2323

2424
def test_is_halted(self):
@@ -87,7 +87,7 @@ def before_task_run(self, task):
8787
return False
8888

8989
flow = Flow(root.then(leaf))
90-
mocker.patch('taskflow.flow.Flow._before_task_run', before_task_run)
90+
mocker.patch("taskflow.flow.Flow._before_task_run", before_task_run)
9191

9292
result = flow.step()
9393
assert not flow.is_complete
@@ -139,34 +139,24 @@ def test_get_next(self):
139139

140140
def test_to_list(self):
141141
task1 = Task(Handlers.repeat, args=(1,))
142-
flow = Flow(task1.then(
143-
Task(Handlers.repeat)
144-
).then(
145-
CompositeTask(
146-
Task(Handlers.repeat),
147-
Task(Handlers.repeat)
148-
)
149-
).then(
150-
Task(Handlers.repeat)
151-
))
142+
flow = Flow(
143+
task1.then(Task(Handlers.repeat))
144+
.then(CompositeTask(Task(Handlers.repeat), Task(Handlers.repeat)))
145+
.then(Task(Handlers.repeat))
146+
)
152147

153148
assert task1.to_list() == flow.to_list()
154149

155150
def test_from_list(self):
156151
task1 = Task(Handlers.repeat, args=(1,))
157-
flow1 = Flow(task1.then(
158-
Task(Handlers.repeat)
159-
).then(
160-
CompositeTask(
161-
Task(Handlers.repeat),
162-
Task(Handlers.repeat)
163-
)
164-
).then(
165-
Task(Handlers.repeat)
166-
))
152+
flow1 = Flow(
153+
task1.then(Task(Handlers.repeat))
154+
.then(CompositeTask(Task(Handlers.repeat), Task(Handlers.repeat)))
155+
.then(Task(Handlers.repeat))
156+
)
167157

168158
data_list = flow1.to_list()
169159
shuffle(data_list)
170-
flow2 = Flow.from_list(data_list, uid=uuid4(), friendly_name='Copy')
160+
flow2 = Flow.from_list(data_list, uid=uuid4(), friendly_name="Copy")
171161

172162
assert flow2.to_list() == flow1.to_list()

0 commit comments

Comments
 (0)