Skip to content

Commit a3f0157

Browse files
committed
Codestyle.
1 parent 7ca8b36 commit a3f0157

29 files changed

+264
-237
lines changed

fireworks/core/firework.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ def __init__(self, *args, **kwargs):
625625
else: # maybe it's a String?
626626
try:
627627
self[int(k)] = self[k] # k must be int
628-
except:
628+
except Exception:
629629
pass # garbage input
630630
del self[k]
631631

fireworks/core/launchpad.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@
3737
from fireworks.utilities.fw_utilities import get_fw_logger
3838
from fireworks.utilities.fw_serializers import recursive_dict
3939

40-
4140
__author__ = 'Anubhav Jain'
4241
__copyright__ = 'Copyright 2013, The Materials Project'
4342
__version__ = '0.1'
4443
__maintainer__ = 'Anubhav Jain'
4544
__email__ = '[email protected]'
4645
__date__ = 'Jan 30, 2013'
4746

47+
4848
# TODO: lots of duplication reduction and cleanup possible
4949

5050

@@ -86,7 +86,7 @@ def __enter__(self):
8686
# could not acquire lock b/c WF is already locked for writing
8787
while not links_dict:
8888
ctr += 1
89-
time_incr = ctr/10.0+random.random()/100.0
89+
time_incr = ctr / 10.0 + random.random() / 100.0
9090
time.sleep(time_incr) # wait a bit for lock to free up
9191
waiting_time += time_incr
9292
if waiting_time > self.expire_secs: # too much time waiting, expire lock
@@ -225,15 +225,15 @@ def update_spec(self, fw_ids, spec_document, mongo=False):
225225
if mongo:
226226
mod_spec = spec_document
227227
else:
228-
mod_spec = {"$set": {("spec." + k): v for k, v in spec_document.items()} }
228+
mod_spec = {"$set": {("spec." + k): v for k, v in spec_document.items()}}
229229

230230
allowed_states = ["READY", "WAITING", "FIZZLED", "DEFUSED", "PAUSED"]
231231
self.fireworks.update_many({'fw_id': {"$in": fw_ids},
232232
'state': {"$in": allowed_states}}, mod_spec)
233233
for fw in self.fireworks.find({'fw_id': {"$in": fw_ids}, 'state': {"$nin": allowed_states}},
234234
{"fw_id": 1, "state": 1}):
235235
self.m_logger.warning("Cannot update spec of fw_id: {} with state: {}. "
236-
"Try rerunning first".format(fw['fw_id'], fw['state']))
236+
"Try rerunning first".format(fw['fw_id'], fw['state']))
237237

238238
@classmethod
239239
def from_dict(cls, d):
@@ -246,11 +246,12 @@ def from_dict(cls, d):
246246
user_indices = d.get('user_indices', [])
247247
wf_user_indices = d.get('wf_user_indices', [])
248248
ssl = d.get('ssl', False)
249-
ssl_ca_certs = d.get('ssl_ca_certs', d.get('ssl_ca_file', None)) # ssl_ca_file was the old notation for FWS < 1.5.5
249+
ssl_ca_certs = d.get('ssl_ca_certs',
250+
d.get('ssl_ca_file', None)) # ssl_ca_file was the old notation for FWS < 1.5.5
250251
ssl_certfile = d.get('ssl_certfile', None)
251252
ssl_keyfile = d.get('ssl_keyfile', None)
252253
ssl_pem_passphrase = d.get('ssl_pem_passphrase', None)
253-
authsource= d.get('authsource', None)
254+
authsource = d.get('authsource', None)
254255
uri_mode = d.get('uri_mode', False)
255256
return LaunchPad(d['host'], port, name, username, password,
256257
logdir, strm_lvl, user_indices, wf_user_indices, ssl,
@@ -770,17 +771,17 @@ def tuneup(self, bkground=True):
770771
try:
771772
self.db.command({'compact': 'fireworks'})
772773
self.db.command({'compact': 'launches'})
773-
except:
774+
except Exception:
774775
self.m_logger.debug('Database compaction failed (not critical)')
775776

776-
def pause_fw(self,fw_id):
777+
def pause_fw(self, fw_id):
777778
"""
778779
Given the firework id, pauses the firework and refresh the workflow
779780
780781
Args:
781782
fw_id(int): firework id
782783
"""
783-
allowed_states = ['WAITING', 'READY', 'RESERVED']
784+
allowed_states = ['WAITING', 'READY', 'RESERVED']
784785
f = self.fireworks.find_one_and_update(
785786
{'fw_id': fw_id, 'state': {'$in': allowed_states}},
786787
{'$set': {'state': 'PAUSED', 'updated_on': datetime.datetime.utcnow()}})
@@ -790,7 +791,6 @@ def pause_fw(self,fw_id):
790791
self.m_logger.error('No pausable (WAITING,READY,RESERVED) Firework exists with fw_id: {}'.format(fw_id))
791792
return f
792793

793-
794794
def defuse_fw(self, fw_id, rerun_duplicates=True):
795795
"""
796796
Given the firework id, defuse the firework and refresh the workflow.
@@ -809,8 +809,8 @@ def defuse_fw(self, fw_id, rerun_duplicates=True):
809809
if not f:
810810
self.rerun_fw(fw_id, rerun_duplicates)
811811
f = self.fireworks.find_one_and_update(
812-
{'fw_id': fw_id, 'state': {'$in': allowed_states}},
813-
{'$set': {'state': 'DEFUSED', 'updated_on': datetime.datetime.utcnow()}})
812+
{'fw_id': fw_id, 'state': {'$in': allowed_states}},
813+
{'$set': {'state': 'DEFUSED', 'updated_on': datetime.datetime.utcnow()}})
814814
if f:
815815
self._refresh_wf(fw_id)
816816
return f
@@ -966,7 +966,7 @@ def _get_a_fw_to_run(self, query=None, fw_id=None, checkout=True):
966966
if checkout:
967967
m_fw = self.fireworks.find_one_and_update(m_query,
968968
{'$set': {'state': 'RESERVED',
969-
'updated_on': datetime.datetime.utcnow()}},
969+
'updated_on': datetime.datetime.utcnow()}},
970970
sort=sortby)
971971
else:
972972
m_fw = self.fireworks.find_one(m_query, {'fw_id': 1, 'spec': 1}, sort=sortby)
@@ -1149,8 +1149,8 @@ def detect_lostruns(self, expiration_secs=RUN_EXPIRATION_SECS, fizzle=False, rer
11491149
m_l = self.get_launch_by_id(ld['launch_id'])
11501150
utime = m_l._get_time('RUNNING', use_update_time=True)
11511151
ctime = m_l._get_time('RUNNING', use_update_time=False)
1152-
if (not max_runtime or (utime-ctime).seconds <= max_runtime) and \
1153-
(not min_runtime or (utime-ctime).seconds >= min_runtime):
1152+
if (not max_runtime or (utime - ctime).seconds <= max_runtime) and \
1153+
(not min_runtime or (utime - ctime).seconds >= min_runtime):
11541154
bad_launch = True
11551155
if bad_launch:
11561156
lost_launch_ids.append(ld['launch_id'])
@@ -1344,12 +1344,11 @@ def complete_launch(self, launch_id, action=None, state='COMPLETED'):
13441344
metadata={"launch_id": launch_id})
13451345
launch_db_dict["action"] = {"gridfs_id": str(action_id)}
13461346
self.m_logger.warning("The size of the launch document was too large. Saving "
1347-
"the action in gridfs.")
1347+
"the action in gridfs.")
13481348

13491349
self.launches.find_one_and_replace({'launch_id': m_launch.launch_id},
13501350
launch_db_dict, upsert=True)
13511351

1352-
13531352
# find all the fws that have this launch
13541353
for fw in self.fireworks.find({'launches': launch_id}, {'fw_id': 1}):
13551354
fw_id = fw['fw_id']
@@ -1385,7 +1384,7 @@ def get_new_fw_id(self, quantity=1):
13851384
"""
13861385
try:
13871386
return self.fw_id_assigner.find_one_and_update({}, {'$inc': {'next_fw_id': quantity}})['next_fw_id']
1388-
except:
1387+
except Exception:
13891388
raise ValueError("Could not get next FW id! If you have not yet initialized the database,"
13901389
" please do so by performing a database reset (e.g., lpad reset)")
13911390

@@ -1395,7 +1394,7 @@ def get_new_launch_id(self):
13951394
"""
13961395
try:
13971396
return self.fw_id_assigner.find_one_and_update({}, {'$inc': {'next_launch_id': 1}})['next_launch_id']
1398-
except:
1397+
except Exception:
13991398
raise ValueError("Could not get next launch id! If you have not yet initialized the "
14001399
"database, please do so by performing a database reset (e.g., lpad reset)")
14011400

@@ -1421,7 +1420,7 @@ def _upsert_fws(self, fws, reassign_all=False):
14211420
# this is the FIRST fw_id we should use
14221421
first_new_id = self.get_new_fw_id(quantity=len(fws))
14231422

1424-
for new_id, fw in enumerate(fws, start=first_new_id):
1423+
for new_id, fw in enumerate(fws, start=first_new_id):
14251424
old_new[fw.fw_id] = new_id
14261425
fw.fw_id = new_id
14271426
used_ids.append(new_id)
@@ -1467,7 +1466,7 @@ def rerun_fw(self, fw_id, rerun_duplicates=True, recover_launch=None, recover_mo
14671466
reruns = []
14681467
if rerun_duplicates:
14691468
f = self.fireworks.find_one({"fw_id": fw_id, "spec._dupefinder": {"$exists": True}},
1470-
{'launches':1})
1469+
{'launches': 1})
14711470
if f:
14721471
for d in self.fireworks.find({"launches": {"$in": f['launches']},
14731472
"fw_id": {"$ne": fw_id}}, {"fw_id": 1}):
@@ -1486,12 +1485,11 @@ def rerun_fw(self, fw_id, rerun_duplicates=True, recover_launch=None, recover_mo
14861485

14871486
# If no launch recovery specified, unset the firework recovery spec
14881487
else:
1489-
set_spec = {"$unset":{"spec._recovery":""}}
1490-
self.fireworks.find_one_and_update({"fw_id":fw_id}, set_spec)
1491-
1488+
set_spec = {"$unset": {"spec._recovery": ""}}
1489+
self.fireworks.find_one_and_update({"fw_id": fw_id}, set_spec)
14921490

14931491
# rerun this FW
1494-
if m_fw['state'] in ['ARCHIVED', 'DEFUSED'] :
1492+
if m_fw['state'] in ['ARCHIVED', 'DEFUSED']:
14951493
self.m_logger.info("Cannot rerun fw_id: {}: it is {}.".format(fw_id, m_fw['state']))
14961494
elif m_fw['state'] == 'WAITING' and not recover_launch:
14971495
self.m_logger.debug("Skipping rerun fw_id: {}: it is already WAITING.".format(fw_id))
@@ -1546,7 +1544,7 @@ def _refresh_wf(self, fw_id):
15461544
self._update_wf(wf, updated_ids)
15471545
except LockedWorkflowError:
15481546
self.m_logger.info("fw_id {} locked. Can't refresh!".format(fw_id))
1549-
except:
1547+
except Exception:
15501548
# some kind of internal error - an example is that fws serialization changed due to
15511549
# code updates and thus the Firework object can no longer be loaded from db description
15521550
# Action: *manually* mark the fw and workflow as FIZZLED
@@ -1614,7 +1612,7 @@ def _steal_launches(self, thief_fw):
16141612
except NotImplementedError:
16151613
verified = True # no dupefinder.verify() implemented, skip verification
16161614

1617-
except: # we want to catch any exceptions from testing an empty dict, which the dupefinder might not be designed for
1615+
except Exception: # we want to catch any exceptions from testing an empty dict, which the dupefinder might not be designed for
16181616
pass
16191617

16201618
if not verified:
@@ -1755,7 +1753,7 @@ def recover_offline(self, launch_id, ignore_errors=False, print_errors=False):
17551753
{"$set": {"updated_on": datetime.datetime.utcnow().isoformat()}})
17561754
return None
17571755

1758-
except:
1756+
except Exception:
17591757
if print_errors:
17601758
self.m_logger.error("failed recovering launch_id {}.\n{}".format(
17611759
launch_id, traceback.format_exc()))
@@ -1961,7 +1959,7 @@ def partial_fw(self):
19611959

19621960
@property
19631961
def full_fw(self):
1964-
#map(self._get_launch_data, self.db_launch_fields)
1962+
# map(self._get_launch_data, self.db_launch_fields)
19651963
for launch_field in self.db_launch_fields:
19661964
self._get_launch_data(launch_field)
19671965
return self._fw
@@ -2000,7 +1998,7 @@ def get_action_from_gridfs(action_dict, fallback_fs):
20001998
on its identifier, otherwise simply returns the dictionary in input.
20011999
Should be used when accessing a launch to ensure the presence of the
20022000
correct action dictionary.
2003-
2001+
20042002
Args:
20052003
action_dict (dict): the dictionary contained in the "action" key of a launch
20062004
document.

fireworks/core/rocket.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def run(self, pdb_on_exception=False):
179179
if not os.listdir(prev_dir) and REMOVE_USELESS_DIRS:
180180
try:
181181
os.rmdir(prev_dir)
182-
except:
182+
except Exception:
183183
pass
184184

185185
recovery = m_fw.spec.get('_recovery', None)
@@ -243,7 +243,7 @@ def run(self, pdb_on_exception=False):
243243
'_all_update_spec': all_update_spec,
244244
'_all_mod_spec': all_mod_spec}
245245
Rocket.update_checkpoint(lp, launch_dir, launch_id, checkpoint)
246-
246+
247247
if lp:
248248
l_logger.log(logging.INFO, "Task started: %s." % t.fw_name)
249249

@@ -280,7 +280,7 @@ def run(self, pdb_on_exception=False):
280280

281281
try:
282282
m_task = t.to_dict()
283-
except:
283+
except Exception:
284284
m_task = None
285285

286286
m_action = FWAction(stored_data={'_message': 'runtime error during task',
@@ -377,7 +377,7 @@ def run(self, pdb_on_exception=False):
377377
self.fw_id, final_state, e, self.fw_id))
378378
return True
379379

380-
except:
380+
except Exception:
381381
# problems while processing the results. high probability of malformed data.
382382
traceback.print_exc()
383383
stop_backgrounds(ping_stop, btask_stops)
@@ -394,7 +394,7 @@ def run(self, pdb_on_exception=False):
394394

395395
try:
396396
m_action = self.decorate_fwaction(m_action, my_spec, m_fw, launch_dir)
397-
except:
397+
except Exception:
398398
traceback.print_exc()
399399

400400
if lp:

fireworks/core/tests/test_launchpad.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def setUpClass(cls):
8282
try:
8383
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
8484
cls.lp.reset(password=None, require_password=False)
85-
except:
85+
except Exception:
8686
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
8787

8888
@classmethod
@@ -184,7 +184,7 @@ def setUpClass(cls):
184184
try:
185185
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
186186
cls.lp.reset(password=None, require_password=False)
187-
except:
187+
except Exception:
188188
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
189189

190190
@classmethod
@@ -303,7 +303,7 @@ def test_pause_fw(self):
303303
self.assertIn(self.zeus_fw_id,completed_ids)
304304
self.assertTrue(self.zeus_child_fw_ids.issubset(completed_ids))
305305

306-
except:
306+
except Exception:
307307
raise
308308

309309

@@ -328,7 +328,7 @@ def test_defuse_fw(self):
328328
fws_no_run = set(self.lp.get_fw_ids({'state':{'$nin':['COMPLETED']}}))
329329
self.assertIn(self.zeus_fw_id,fws_no_run)
330330
self.assertTrue(self.zeus_child_fw_ids.issubset(fws_no_run))
331-
except:
331+
except Exception:
332332
raise
333333

334334
def test_defuse_fw_after_completion(self):
@@ -535,7 +535,7 @@ def setUpClass(cls):
535535
try:
536536
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
537537
cls.lp.reset(password=None, require_password=False)
538-
except:
538+
except Exception:
539539
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
540540

541541
@classmethod
@@ -678,7 +678,7 @@ def setUpClass(cls):
678678
try:
679679
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
680680
cls.lp.reset(password=None, require_password=False)
681-
except:
681+
except Exception:
682682
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
683683

684684
@classmethod
@@ -791,7 +791,7 @@ def test_defuse_fw(self):
791791
fw_state = fws[fw_id].state
792792
fw_cache_state = wf.fw_states[fw_id]
793793
self.assertEqual(fw_state, fw_cache_state)
794-
except:
794+
except Exception:
795795
raise
796796

797797
def test_defuse_fw_after_completion(self):
@@ -953,7 +953,7 @@ def setUpClass(cls):
953953
try:
954954
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
955955
cls.lp.reset(password=None, require_password=False)
956-
except:
956+
except Exception:
957957
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
958958

959959
@classmethod
@@ -1043,7 +1043,7 @@ def setUpClass(cls):
10431043
try:
10441044
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
10451045
cls.lp.reset(password=None, require_password=False)
1046-
except:
1046+
except Exception:
10471047
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
10481048

10491049
@classmethod
@@ -1175,7 +1175,7 @@ def setUpClass(cls):
11751175
try:
11761176
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
11771177
cls.lp.reset(password=None, require_password=False)
1178-
except:
1178+
except Exception:
11791179
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
11801180

11811181
@classmethod
@@ -1259,7 +1259,7 @@ def setUpClass(cls):
12591259
try:
12601260
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
12611261
cls.lp.reset(password=None, require_password=False)
1262-
except:
1262+
except Exception:
12631263
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
12641264

12651265
@classmethod

fireworks/core/tests/test_rocket.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setUpClass(cls):
2121
try:
2222
cls.lp = LaunchPad(name=TESTDB_NAME, strm_lvl='ERROR')
2323
cls.lp.reset(password=None, require_password=False)
24-
except:
24+
except Exception:
2525
raise unittest.SkipTest('MongoDB is not running in localhost:27017! Skipping tests.')
2626

2727
@classmethod

0 commit comments

Comments
 (0)