Skip to content

Commit ec77d2f

Browse files
Luca VenturiniLuca Venturini
Luca Venturini
authored and
Luca Venturini
committed
Refactored docstrings to obey to PEP. Patch for pharmbio#56
1 parent a98161d commit ec77d2f

9 files changed

+221
-168
lines changed

sciluigi/audit.py

+19-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
'''
1+
"""
22
This module contains functionality for the audit-trail logging functionality
3-
'''
3+
"""
44

55
import logging
66
import luigi
@@ -15,20 +15,22 @@
1515

1616
# ==============================================================================
1717

18+
1819
class AuditTrailHelpers(object):
19-
'''
20+
"""
2021
Mixin for luigi.Task:s, with functionality for writing audit logs of running tasks
21-
'''
22+
"""
2223
def add_auditinfo(self, infotype, infoval):
23-
'''
24+
"""
2425
Alias to _add_auditinfo(), that can be overridden.
25-
'''
26+
"""
2627
return self._add_auditinfo(self.instance_name, infotype, infoval)
2728

29+
2830
def _add_auditinfo(self, instance_name, infotype, infoval):
29-
'''
31+
"""
3032
Save audit information in a designated file, specific for this task.
31-
'''
33+
"""
3234
dirpath = self.workflow_task.get_auditdirpath()
3335
if not os.path.isdir(dirpath):
3436
time.sleep(random.random())
@@ -42,32 +44,35 @@ def _add_auditinfo(self, instance_name, infotype, infoval):
4244
with open(auditfile, 'a') as afile:
4345
afile.write('%s: %s\n' % (infotype, infoval))
4446

47+
4548
def get_instance_name(self):
46-
'''
49+
"""
4750
Return the luigi instance_name
48-
'''
51+
"""
4952
instance_name = None
5053
if self.instance_name is not None:
5154
instance_name = self.instance_name
5255
else:
5356
instance_name = self.task_id
5457
return instance_name
5558

59+
5660
@luigi.Task.event_handler(luigi.Event.START)
5761
def save_start_time(self):
58-
'''
62+
"""
5963
Log start of execution of task.
60-
'''
64+
"""
6165
if hasattr(self, 'workflow_task') and self.workflow_task is not None:
6266
msg = 'Task {task} started'.format(
6367
task=self.get_instance_name())
6468
log.info(msg)
6569

70+
6671
@luigi.Task.event_handler(luigi.Event.PROCESSING_TIME)
6772
def save_end_time(self, task_exectime_sec):
68-
'''
73+
"""
6974
Log end of execution of task, with execution time.
70-
'''
75+
"""
7176
if hasattr(self, 'workflow_task') and self.workflow_task is not None:
7277
msg = 'Task {task} finished after {proctime:.3f}s'.format(
7378
task=self.get_instance_name(),

sciluigi/dependencies.py

+26-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'''
1+
"""
22
This module contains functionality for dependency resolution for constructing
33
the dependency graph of workflows.
4-
'''
4+
"""
55

66
import luigi
77
from luigi.contrib.postgres import PostgresTarget
@@ -10,11 +10,12 @@
1010

1111
# ==============================================================================
1212

13+
1314
class TargetInfo(object):
14-
'''
15+
"""
1516
Class to be used for sending specification of which target, from which
1617
task, to use, when stitching workflow tasks' outputs and inputs together.
17-
'''
18+
"""
1819
task = None
1920
path = None
2021
target = None
@@ -25,21 +26,24 @@ def __init__(self, task, path, format=None, is_tmp=False):
2526
self.target = luigi.LocalTarget(path, format, is_tmp)
2627

2728
def open(self, *args, **kwargs):
28-
'''
29+
"""
2930
Forward open method, from luigi's target class
30-
'''
31+
"""
3132
return self.target.open(*args, **kwargs)
3233

3334
# ==============================================================================
3435

36+
3537
class S3TargetInfo(TargetInfo):
38+
3639
def __init__(self, task, path, format=None, client=None):
3740
self.task = task
3841
self.path = path
3942
self.target = S3Target(path, format=format, client=client)
4043

4144
# ==============================================================================
4245

46+
4347
class PostgresTargetInfo(TargetInfo):
4448
def __init__(self, task, host, database, user, password, update_id, table=None, port=None):
4549
self.task = task
@@ -54,28 +58,30 @@ def __init__(self, task, host, database, user, password, update_id, table=None,
5458

5559
# ==============================================================================
5660

61+
5762
class DependencyHelpers(object):
58-
'''
63+
64+
"""
5965
Mixin implementing methods for supporting dynamic, and target-based
6066
workflow definition, as opposed to the task-based one in vanilla luigi.
61-
'''
67+
"""
6268

6369
# --------------------------------------------------------
6470
# Handle inputs
6571
# --------------------------------------------------------
6672

6773
def requires(self):
68-
'''
74+
"""
6975
Implement luigi API method by returning upstream tasks
70-
'''
76+
"""
7177
return self._upstream_tasks()
7278

7379
def _upstream_tasks(self):
74-
'''
80+
"""
7581
Extract upstream tasks from the TargetInfo objects
7682
or functions returning those (or lists of both the earlier)
7783
for use in luigi's requires() method.
78-
'''
84+
"""
7985
upstream_tasks = []
8086
for attrname, attrval in iteritems(self.__dict__):
8187
if 'in_' == attrname[0:3]:
@@ -84,11 +90,11 @@ def _upstream_tasks(self):
8490
return upstream_tasks
8591

8692
def _parse_inputitem(self, val, tasks):
87-
'''
93+
"""
8894
Recursively loop through lists of TargetInfos, or
8995
callables returning TargetInfos, or lists of ...
9096
(repeat recursively) ... and return all tasks.
91-
'''
97+
"""
9298
if callable(val):
9399
val = val()
94100
if isinstance(val, TargetInfo):
@@ -108,17 +114,17 @@ def _parse_inputitem(self, val, tasks):
108114
# --------------------------------------------------------
109115

110116
def output(self):
111-
'''
117+
"""
112118
Implement luigi API method
113-
'''
119+
"""
114120
return self._output_targets()
115121

116122
def _output_targets(self):
117-
'''
123+
"""
118124
Extract output targets from the TargetInfo objects
119125
or functions returning those (or lists of both the earlier)
120126
for use in luigi's output() method.
121-
'''
127+
"""
122128
output_targets = []
123129
for attrname in dir(self):
124130
attrval = getattr(self, attrname)
@@ -128,11 +134,11 @@ def _output_targets(self):
128134
return output_targets
129135

130136
def _parse_outputitem(self, val, targets):
131-
'''
137+
"""
132138
Recursively loop through lists of TargetInfos, or
133139
callables returning TargetInfos, or lists of ...
134140
(repeat recursively) ... and return all targets.
135-
'''
141+
"""
136142
if callable(val):
137143
val = val()
138144
if isinstance(val, TargetInfo):

sciluigi/interface.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
'''
1+
"""
22
This module contains mappings of methods that are part of the sciluigi API
3-
'''
3+
"""
44

55
import luigi
66
import logging
@@ -11,10 +11,11 @@
1111
LOGFMT_SCILUIGI = '%(asctime)s %(levelname)8s SCILUIGI %(message)s'
1212
DATEFMT = '%Y-%m-%d %H:%M:%S'
1313

14+
1415
def setup_logging():
15-
'''
16+
"""
1617
Set up SciLuigi specific logging
17-
'''
18+
"""
1819
sciluigi.util.ensuredir('log')
1920
log_path = 'log/sciluigi_run_%s_detailed.log' % sciluigi.util.timepath()
2021

@@ -49,16 +50,19 @@ def setup_logging():
4950
sciluigi_logger.addHandler(sciluigi_file_handler)
5051
sciluigi_logger.setLevel(logging.DEBUG)
5152

53+
5254
setup_logging()
5355

56+
5457
def run(*args, **kwargs):
55-
'''
58+
"""
5659
Forwarding luigi's run method
57-
'''
60+
"""
5861
luigi.run(*args, **kwargs)
5962

63+
6064
def run_local(*args, **kwargs):
61-
'''
65+
"""
6266
Forwarding luigi's run method, with local scheduler
63-
'''
67+
"""
6468
run(local_scheduler=True, *args, **kwargs)

sciluigi/parameter.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
'''
1+
"""
22
This module contains a sciluigi subclass of luigi's Parameter, where
33
custom functionality might be added in the future.
4-
'''
4+
"""
55

66
import luigi
77

8+
89
class Parameter(luigi.Parameter):
9-
'''
10+
"""
1011
Subclass of luigi's Parameter, where custom functionality might be added in the future.
11-
'''
12+
"""
1213
pass

0 commit comments

Comments
 (0)