Skip to content

Commit 51d3e6a

Browse files
committed
MOre codestyle.
1 parent a3f0157 commit 51d3e6a

File tree

15 files changed

+58
-48
lines changed

15 files changed

+58
-48
lines changed

fireworks/core/firework.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from copy import deepcopy
66

7-
87
"""
98
This module contains some of the most central FireWorks classes:
109
@@ -67,7 +66,9 @@ def __init__(self, *args, **kwargs):
6766
allowed_params = required_params + self.optional_params
6867
for k in kwargs:
6968
if k not in allowed_params:
70-
raise RuntimeError("Invalid keyword argument specified for: {}. You specified: {}. Allowed values are: {}.".format(self.__class__, k, allowed_params))
69+
raise RuntimeError(
70+
"Invalid keyword argument specified for: {}. You specified: {}. Allowed values are: {}.".format(
71+
self.__class__, k, allowed_params))
7172

7273
@abc.abstractmethod
7374
def run_task(self, fw_spec):
@@ -195,7 +196,7 @@ class Firework(FWSerializable):
195196
A Firework is a workflow step and might be contain several Firetasks.
196197
"""
197198

198-
STATE_RANKS = {'ARCHIVED': -2, 'FIZZLED': -1, 'DEFUSED': 0, 'PAUSED' : 0,
199+
STATE_RANKS = {'ARCHIVED': -2, 'FIZZLED': -1, 'DEFUSED': 0, 'PAUSED': 0,
199200
'WAITING': 1, 'READY': 2, 'RESERVED': 3, 'RUNNING': 4,
200201
'COMPLETED': 5}
201202

@@ -290,7 +291,7 @@ def _rerun(self):
290291
if self.state == 'FIZZLED':
291292
last_launch = self.launches[-1]
292293
if (EXCEPT_DETAILS_ON_RERUN and last_launch.action and
293-
last_launch.action.stored_data.get('_exception', {}).get('_details')):
294+
last_launch.action.stored_data.get('_exception', {}).get('_details')):
294295
# add the exception details to the spec
295296
self.spec['_exception_details'] = last_launch.action.stored_data['_exception']['_details']
296297
else:
@@ -688,7 +689,7 @@ def __reduce__(self):
688689
arguments
689690
"""
690691
state = list(self.items())
691-
return NestedClassGetter(), (Workflow, self.__class__.__name__, ), state
692+
return NestedClassGetter(), (Workflow, self.__class__.__name__,), state
692693

693694
def __init__(self, fireworks, links_dict=None, name=None, metadata=None, created_on=None,
694695
updated_on=None, fw_states=None):
@@ -763,7 +764,7 @@ def state(self):
763764
state (str): state of workflow
764765
"""
765766
m_state = 'READY'
766-
#states = [fw.state for fw in self.fws]
767+
# states = [fw.state for fw in self.fws]
767768
states = self.fw_states.values()
768769
leaf_fw_ids = self.leaf_fw_ids # to save recalculating this
769770

@@ -782,9 +783,9 @@ def state(self):
782783
for fizzled_id in fizzled_ids:
783784
# If a fizzled fw is a leaf fw, then the workflow is fizzled
784785
if (fizzled_id in leaf_fw_ids or
785-
# Otherwise all children must be ok with the fizzled parent
786-
not all(self.id_fw[child_id].spec.get('_allow_fizzled_parents', False)
787-
for child_id in self.links[fizzled_id])):
786+
# Otherwise all children must be ok with the fizzled parent
787+
not all(self.id_fw[child_id].spec.get('_allow_fizzled_parents', False)
788+
for child_id in self.links[fizzled_id])):
788789
m_state = 'FIZZLED'
789790
break
790791
else:

fireworks/core/rocket.py

+21-21
Original file line numberDiff line numberDiff line change
@@ -192,15 +192,15 @@ def run(self, pdb_on_exception=False):
192192
all_mod_spec.extend(recovery.get('_all_mod_spec'))
193193
if lp:
194194
l_logger.log(
195-
logging.INFO,
196-
'Recovering from task number {} in folder {}.'.format(starting_task,
197-
recovery_dir))
195+
logging.INFO,
196+
'Recovering from task number {} in folder {}.'.format(starting_task,
197+
recovery_dir))
198198
if recovery_mode == 'cp' and launch_dir != recovery_dir:
199199
if lp:
200200
l_logger.log(
201-
logging.INFO,
202-
'Copying data from recovery folder {} to folder {}.'.format(recovery_dir,
203-
launch_dir))
201+
logging.INFO,
202+
'Copying data from recovery folder {} to folder {}.'.format(recovery_dir,
203+
launch_dir))
204204
distutils.dir_util.copy_tree(recovery_dir, launch_dir, update=1)
205205

206206
else:
@@ -215,7 +215,7 @@ def run(self, pdb_on_exception=False):
215215
shutil.copyfileobj(fin, fout)
216216

217217
if lp:
218-
message = 'RUNNING fw_id: {} in directory: {}'.\
218+
message = 'RUNNING fw_id: {} in directory: {}'. \
219219
format(m_fw.fw_id, os.getcwd())
220220
l_logger.log(logging.INFO, message)
221221

@@ -245,7 +245,7 @@ def run(self, pdb_on_exception=False):
245245
Rocket.update_checkpoint(lp, launch_dir, launch_id, checkpoint)
246246

247247
if lp:
248-
l_logger.log(logging.INFO, "Task started: %s." % t.fw_name)
248+
l_logger.log(logging.INFO, "Task started: %s." % t.fw_name)
249249

250250
if my_spec.get("_add_launchpad_and_fw_id"):
251251
t.fw_id = m_fw.fw_id
@@ -275,7 +275,7 @@ def run(self, pdb_on_exception=False):
275275
except BaseException as e:
276276
if lp:
277277
l_logger.log(logging.WARNING,
278-
"Exception couldn't be serialized: %s " % e)
278+
"Exception couldn't be serialized: %s " % e)
279279
exception_details = None
280280

281281
try:
@@ -371,10 +371,10 @@ def run(self, pdb_on_exception=False):
371371
except LockedWorkflowError as e:
372372
l_logger.log(logging.DEBUG, traceback.format_exc())
373373
l_logger.log(logging.WARNING,
374-
"Firework {} reached final state {} but couldn't complete the update of "
375-
"the database. Reason: {}\nRefresh the WF to recover the result "
376-
"(lpad admin refresh -i {}).".format(
377-
self.fw_id, final_state, e, self.fw_id))
374+
"Firework {} reached final state {} but couldn't complete the update of "
375+
"the database. Reason: {}\nRefresh the WF to recover the result "
376+
"(lpad admin refresh -i {}).".format(
377+
self.fw_id, final_state, e, self.fw_id))
378378
return True
379379

380380
except Exception:
@@ -403,10 +403,10 @@ def run(self, pdb_on_exception=False):
403403
except LockedWorkflowError as e:
404404
l_logger.log(logging.DEBUG, traceback.format_exc())
405405
l_logger.log(logging.WARNING,
406-
"Firework {} fizzled but couldn't complete the update of the database."
407-
" Reason: {}\nRefresh the WF to recover the result "
408-
"(lpad admin refresh -i {}).".format(
409-
self.fw_id, final_state, e, self.fw_id))
406+
"Firework {} fizzled but couldn't complete the update of the database."
407+
" Reason: {}\nRefresh the WF to recover the result "
408+
"(lpad admin refresh -i {}).".format(
409+
self.fw_id, final_state, e, self.fw_id))
410410
return True
411411
else:
412412
fpath = zpath("FW_offline.json")
@@ -445,7 +445,7 @@ def decorate_fwaction(self, fwaction, my_spec, m_fw, launch_dir):
445445

446446
if my_spec.get("_pass_job_info"):
447447
job_info = list(my_spec.get("_job_info", []))
448-
this_job_info = {"fw_id": m_fw.fw_id, "name": m_fw.name, "launch_dir": launch_dir, "state":m_fw.state}
448+
this_job_info = {"fw_id": m_fw.fw_id, "name": m_fw.name, "launch_dir": launch_dir, "state": m_fw.state}
449449
if this_job_info not in job_info:
450450
job_info.append(this_job_info)
451451
fwaction.mod_spec.append({"_push_all": {"_job_info": job_info}})
@@ -463,9 +463,9 @@ def decorate_fwaction(self, fwaction, my_spec, m_fw, launch_dir):
463463
files = glob.glob(os.path.join(launch_dir, v))
464464
if files:
465465
filepath = sorted(files)[-1]
466-
fwaction.mod_spec.append( {
467-
"_set": {"_files_prev->{:s}".format(k): filepath }
468-
} )
466+
fwaction.mod_spec.append({
467+
"_set": {"_files_prev->{:s}".format(k): filepath}
468+
})
469469
elif "_files_prev" in my_spec:
470470
# This ensures that _files_prev are not passed from Firework to
471471
# Firework. We do not want output files from fw1 to be used by fw3

fireworks/examples/custom_firetasks/hello_world/hello_world_run.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
lp.add_wf(my_wflow)
1414

1515
# run the workflow
16-
launch_rocket(lp)
16+
launch_rocket(lp)

fireworks/examples/custom_firetasks/hello_world/hello_world_task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
class HelloTask(FiretaskBase):
66

77
def run_task(self, fw_spec):
8-
print("Hello, world!")
8+
print("Hello, world!")

fireworks/examples/custom_firetasks/merge_task/merge_task.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
A workflow where 2 parent Fireworks (A and B) merge into a common child C.
88
"""
99

10+
1011
@explicit_serialize
1112
class TaskA(FiretaskBase):
1213

@@ -22,6 +23,7 @@ def run_task(self, fw_spec):
2223
print("This is task B")
2324
return FWAction(update_spec={"param_B": 20})
2425

26+
2527
@explicit_serialize
2628
class TaskC(FiretaskBase):
2729

@@ -30,6 +32,7 @@ def run_task(self, fw_spec):
3032
print("Task A gave me: {}".format(fw_spec["param_A"]))
3133
print("Task B gave me: {}".format(fw_spec["param_B"]))
3234

35+
3336
if __name__ == "__main__":
3437
# set up the LaunchPad and reset it
3538
launchpad = LaunchPad()
@@ -44,4 +47,4 @@ def run_task(self, fw_spec):
4447

4548
# store workflow and launch it locally
4649
launchpad.add_wf(workflow)
47-
rapidfire(launchpad)
50+
rapidfire(launchpad)

fireworks/examples/tutorial_examples/dynamic_wf1.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
This code is described in the Dynamic Workflow tutorial, https://materialsproject.github.io/fireworks/dynamic_wf_tutorial.html
2+
This code is described in the Dynamic Workflow tutorial,
3+
https://materialsproject.github.io/fireworks/dynamic_wf_tutorial.html
34
"""
45

56
from fireworks import ScriptTask

fireworks/examples/tutorial_examples/dynamic_wf2.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
This code is described in the Dynamic Workflow tutorial, https://materialsproject.github.io/fireworks/dynamic_wf_tutorial.html
2+
This code is described in the Dynamic Workflow tutorial,
3+
https://materialsproject.github.io/fireworks/dynamic_wf_tutorial.html
34
"""
45

56
from fireworks import Firework, FWorker, LaunchPad
@@ -17,4 +18,3 @@
1718
# store workflow and launch it locally
1819
launchpad.add_wf(firework)
1920
rapidfire(launchpad, FWorker())
20-

fireworks/examples/tutorial_examples/firetasks.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
This code is described in the Firetasks tutorial, https://materialsproject.github.io/fireworks/firetask_tutorial.html
2+
This code is described in the Firetasks tutorial,
3+
https://materialsproject.github.io/fireworks/firetask_tutorial.html
34
"""
45

56
from fireworks import Firework, FWorker, LaunchPad
@@ -16,4 +17,4 @@
1617

1718
# store workflow and launch it locally
1819
launchpad.add_wf(firework)
19-
launch_rocket(launchpad, FWorker())
20+
launch_rocket(launchpad, FWorker())

fireworks/examples/tutorial_examples/introduction.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
2-
This code is described in the Introductory tutorial, https://materialsproject.github.io/fireworks/introduction.html
2+
This code is described in the Introductory tutorial,
3+
https://materialsproject.github.io/fireworks/introduction.html
34
"""
45

56
from fireworks import Firework, LaunchPad, ScriptTask
@@ -16,4 +17,4 @@
1617

1718
# store workflow and launch it locally
1819
launchpad.add_wf(firework)
19-
launch_rocket(launchpad)
20+
launch_rocket(launchpad)

fireworks/queue/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
__version__ = '0.1'
44
__maintainer__ = 'Anubhav Jain'
55
__email__ = '[email protected]'
6-
__date__ = 'Feb 28, 2013'
6+
__date__ = 'Feb 28, 2013'

fireworks/queue/queue_launcher.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def rapidfire(launchpad, fworker, qadapter, launch_dir='.', nlaunches=0, njobs_q
228228

229229
# launch a single job
230230
return_code = launch_rocket_to_queue(launchpad, fworker, qadapter, block_dir, reserve,
231-
strm_lvl, True, fill_mode)
231+
strm_lvl, True, fill_mode)
232232
if return_code is None:
233233
l_logger.info('No READY jobs detected...')
234234
break

fireworks/scripts/qlaunch_run.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
try:
1515
import fabric
16+
1617
if int(fabric.__version__.split('.')[0]) < 2:
1718
raise ImportError
1819
except ImportError:
@@ -70,6 +71,7 @@ def do_launch(args):
7071
launch_rocket_to_queue(launchpad, fworker, queueadapter,
7172
args.launch_dir, args.reserve, args.loglvl, False, args.fill_mode, args.fw_id)
7273

74+
7375
def qlaunch():
7476
m_description = 'This program is used to submit jobs to a queueing system. ' \
7577
'Details of the job and queue interaction are handled by the ' \
@@ -149,8 +151,8 @@ def qlaunch():
149151
rapid_parser.add_argument('--timeout', help='timeout (secs) after which to quit (default None)',
150152
default=None, type=int)
151153
rapid_parser.add_argument('--sleep', help='sleep time between loops', default=None, type=int)
152-
153-
single_parser.add_argument('-f', '--fw_id', help='specific fw_id to run in reservation mode',
154+
155+
single_parser.add_argument('-f', '--fw_id', help='specific fw_id to run in reservation mode',
154156
default=None, type=int)
155157

156158
try:

fireworks/utilities/filepad.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from fireworks.fw_config import LAUNCHPAD_LOC
2121
from fireworks.utilities.fw_utilities import get_fw_logger
2222

23-
2423
__author__ = 'Kiran Mathew'
2524
__email__ = '[email protected]'
2625
__credits__ = 'Anubhav Jain'
@@ -42,7 +41,8 @@ def __init__(self, host='localhost', port=27017, database='fireworks', username=
4241
gridfs_coll_name (str): gridfs collection name
4342
logdir (str): path to the log directory
4443
strm_lvl (str): the logger stream level
45-
text_mode (bool): whether to use text_mode for file read/write (instead of binary). Might be useful if working only with text files between Windows and Unix systems
44+
text_mode (bool): whether to use text_mode for file read/write (instead of binary). Might be useful if
45+
working only with text files between Windows and Unix systems
4646
"""
4747
self.host = host
4848
self.port = int(port)
@@ -159,7 +159,7 @@ def get_file_by_query(self, query, sort_key=None,
159159
if sort_key is None:
160160
cursor = self.filepad.find(query)
161161
else:
162-
cursor = self.filepad.find(query).sort(sort_key,sort_direction)
162+
cursor = self.filepad.find(query).sort(sort_key, sort_direction)
163163
for d in cursor:
164164
all_files.append(self._get_file_contents(d))
165165
return all_files

fireworks/utilities/update_collection.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
__date__ = 'Dec 08, 2016'
88

9+
910
def update_launchpad_data(lp, replacements, **kwargs):
1011
"""
1112
If you want to update a text string in your entire FireWorks database with a replacement, use this method.

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ release = register sdist upload
1212

1313
[pycodestyle]
1414
count = True
15-
ignore=E121,E123,E126,E133,E226,E241,E242,E704,W503,W504,W505,E741,W605
15+
ignore=E121,E123,E126,E133,E226,E241,E242,E704,W503,W504,W505,E741,W605,E731
1616
max-line-length = 120
1717
statistics = True
1818
exclude=*test*,docs_rst/*.py,fireworks/__init__.py

0 commit comments

Comments
 (0)