Skip to content

Commit c109f28

Browse files
committed
Add pycodestyle.
1 parent 51d3e6a commit c109f28

19 files changed

+83
-57
lines changed

.circleci/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
source activate test-environment
2626
pip install --quiet -e .
2727
pytest fireworks
28+
pycodestyle fireworks
2829
py2test:
2930
working_directory: ~/fireworks
3031
docker:

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ before_script:
99
- python setup.py develop
1010
script:
1111
- pytest fireworks
12+
- pycodestyle fireworks
1213
- source fireworks/tests/cmd_line_test.sh
1314
after_success:
1415
- coveralls

fireworks/core/firework.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class FiretaskBase(defaultdict, FWSerializable):
5151
You can set parameters of a Firetask like you'd use a dict.
5252
"""
5353
required_params = None # list of str of required parameters to check for consistency upon init
54-
optional_params = None # if set to a list of str, only required and optional kwargs are allowed; consistency checked upon init
54+
55+
# if set to a list of str, only required and optional kwargs are allowed; consistency checked upon init
56+
optional_params = None
5557

5658
def __init__(self, *args, **kwargs):
5759
dict.__init__(self, *args, **kwargs)

fireworks/core/launchpad.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def __init__(self, host=None, port=None, name=None, username=None, password=None
119119
authsource=None, uri_mode=False):
120120
"""
121121
Args:
122-
host (str): hostname. If uri_mode is True, a MongoDB connection string URI (https://docs.mongodb.com/manual/reference/connection-string/) can be used instead of the remaining options below.
122+
host (str): hostname. If uri_mode is True, a MongoDB connection string URI
123+
(https://docs.mongodb.com/manual/reference/connection-string/) can be used instead of the remaining
124+
options below.
123125
port (int): port number
124126
name (str): database name
125127
username (str)
@@ -133,8 +135,10 @@ def __init__(self, host=None, port=None, name=None, username=None, password=None
133135
ssl_certfile (str): path to the client certificate to be used for mongodb connection
134136
ssl_keyfile (str): path to the client private key
135137
ssl_pem_passphrase (str): passphrase for the client private key
136-
authsource (str): authsource parameter for MongoDB authentication; defaults to "name" (i.e., db name) if not set
137-
uri_mode (bool): if set True, all Mongo connection parameters occur through a MongoDB URI string (set as the host).
138+
authsource (str): authsource parameter for MongoDB authentication; defaults to "name" (i.e., db name) if
139+
not set
140+
uri_mode (bool): if set True, all Mongo connection parameters occur through a MongoDB URI string (set as
141+
the host).
138142
"""
139143

140144
self.host = host if (host or uri_mode) else "localhost"
@@ -292,8 +296,8 @@ def reset(self, password, require_password=True, max_reset_wo_password=25):
292296
self.m_logger.info('LaunchPad was RESET.')
293297
elif not require_password:
294298
raise ValueError("Password check cannot be overridden since the size of DB ({} workflows) "
295-
"is greater than the max_reset_wo_password parameter ({}).".format(
296-
self.fireworks.count(), max_reset_wo_password))
299+
"is greater than the max_reset_wo_password parameter ({}).".format(self.fireworks.count(),
300+
max_reset_wo_password))
297301
else:
298302
raise ValueError("Invalid password! Password is today's date: {}".format(m_password))
299303

@@ -1612,7 +1616,9 @@ def _steal_launches(self, thief_fw):
16121616
except NotImplementedError:
16131617
verified = True # no dupefinder.verify() implemented, skip verification
16141618

1615-
except Exception: # we want to catch any exceptions from testing an empty dict, which the dupefinder might not be designed for
1619+
except Exception:
1620+
# we want to catch any exceptions from testing an empty dict, which the dupefinder might not be
1621+
# designed for
16161622
pass
16171623

16181624
if not verified:
@@ -1710,7 +1716,8 @@ def recover_offline(self, launch_id, ignore_errors=False, print_errors=False):
17101716
self.ping_launch(launch_id, ptime=ping_dict['ping_time'], checkpoint=checkpoint)
17111717
else:
17121718
warnings.warn(
1713-
"Unable to find FW_ping.json in {}! State history updated_on might be incorrect, trackers may not update.".format(
1719+
"Unable to find FW_ping.json in {}! State history updated_on might be incorrect, trackers "
1720+
"may not update.".format(
17141721
m_launch.launch_dir))
17151722
m_launch.touch_history(checkpoint=checkpoint)
17161723

@@ -1728,9 +1735,7 @@ def recover_offline(self, launch_id, ignore_errors=False, print_errors=False):
17281735
s['created_on'] = reconstitute_dates(offline_data['completed_on'])
17291736
self.launches.find_one_and_update(
17301737
{'launch_id': m_launch.launch_id},
1731-
{'$set':
1732-
{'state_history': m_launch.state_history}
1733-
})
1738+
{'$set': {'state_history': m_launch.state_history}})
17341739

17351740
self.offline_runs.update_one({"launch_id": launch_id},
17361741
{"$set": {"completed": True}})
@@ -1740,11 +1745,8 @@ def recover_offline(self, launch_id, ignore_errors=False, print_errors=False):
17401745
m_launch.to_db_dict(), upsert=True)
17411746
fw_id = l['fw_id']
17421747
f = self.fireworks.find_one_and_update({'fw_id': fw_id},
1743-
{'$set':
1744-
{'state': 'RUNNING',
1745-
'updated_on': datetime.datetime.utcnow()
1746-
}
1747-
})
1748+
{'$set': {'state': 'RUNNING',
1749+
'updated_on': datetime.datetime.utcnow()}})
17481750
if f:
17491751
self._refresh_wf(fw_id)
17501752

fireworks/features/stats.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,15 @@ def _aggregate(coll, group_by="state", match=None, project=None, unwind=None,
269269
:param match: (dict) Query for the match step in Mongodb aggregation framework.
270270
:param project: (dict) Query for the project step in Mongodb aggregation framework
271271
:param unwind: (dict) Query for the unwind step in Mongodb aggregation framework
272-
:param group_op: (dict) Additional operations to generate values in the group step in Mongodb aggregation framework.
272+
:param group_op: (dict) Additional operations to generate values in the group step in Mongodb aggregation
273+
framework.
273274
:param sort: (tuple) Defines how to sort the aggregation results. Default is to sort by field in group_by.
274275
:param return_query_only: (bool) If only return the query expression for aggregation. Default is False.
275276
:return: (list) Aggregation results if the operation is successful.
276277
"""
277278
for arg in [match, project, unwind, group_op]:
278-
if arg is None: arg = {}
279+
if arg is None:
280+
arg = {}
279281
group_op.update({"_id": "$" + group_by})
280282
if sort is None:
281283
sort_query = ("_id", 1)

fireworks/flask_site/app.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ def wf_metadata_find(key, value, state):
317317
page = int(request.args.get('page', 1))
318318
except ValueError:
319319
page = 1
320-
rows = list(db.find(q).sort([('_id', DESCENDING)]). \
321-
skip(page - 1).limit(PER_PAGE))
320+
rows = list(db.find(q).sort([('_id', DESCENDING)]).skip(page - 1).limit(PER_PAGE))
322321
for r in rows:
323322
r["fw_id"] = r["nodes"][0]
324323
pagination = Pagination(page=page, total=wf_count,

fireworks/flask_site/gunicorn.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def load_config(self):
3131
def load(self):
3232
return self.application
3333

34+
3435
if __name__ == '__main__':
3536
options = {
3637
'bind': '%s:%s' % ('127.0.0.1', '8080'),

fireworks/flask_site/helpers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def get_totals(states, lp):
44
for state in states:
55
fw_stats[state] = lp.get_fw_ids(query={'state': state}, count_only=True)
66
wf_stats[state] = lp.get_wf_ids(query={'state': state}, count_only=True)
7-
return {"fw_stats": fw_stats, "wf_stats":wf_stats}
7+
return {"fw_stats": fw_stats, "wf_stats": wf_stats}
88

99

1010
def fw_filt_given_wf_filt(filt, lp):
@@ -20,6 +20,7 @@ def wf_filt_given_fw_filt(filt, lp):
2020
wf_ids.add(doc['fw_id'])
2121
return {"nodes": {"$in": list(wf_ids)}}
2222

23+
2324
def uses_index(filt, coll):
2425
ii = coll.index_information()
2526
fields_filtered = set(filt.keys())

fireworks/fw_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
WEBSERVER_PORT = 5000 # default port on which the Flask web server runs
9595

96-
WEBSERVER_PERFWARNINGS = False # enable performance-related warnings
96+
WEBSERVER_PERFWARNINGS = False # enable performance-related warnings
9797

9898
# value of socketTimeoutMS when connection to mongoDB. See pymongo official
9999
# documentation http://api.mongodb.org/python/current/api/pymongo/mongo_client.html
@@ -117,7 +117,7 @@ def override_user_settings():
117117
if fp not in config_paths and os.path.exists(fp):
118118
config_paths.append(fp)
119119

120-
if "FW_CONFIG_FILE" in os.environ and os.environ["FW_CONFIG_FILE"] not in\
120+
if "FW_CONFIG_FILE" in os.environ and os.environ["FW_CONFIG_FILE"] not in \
121121
config_paths:
122122
config_paths.append(os.environ["FW_CONFIG_FILE"])
123123

fireworks/scripts/__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/scripts/lpad_run.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ def init_yaml(args):
127127
("host", None, "Example: mongodb+srv://USER:[email protected]/fireworks"),
128128
("ssl_ca_file", None, "Path to any client certificate to be used for mongodb connection"),
129129
("authsource", None,
130-
"Database used for authentication, if not connection db. e.g., for MongoDB Atlas this is sometimes 'admin'."))
130+
"Database used for authentication, if not connection db. e.g., for MongoDB Atlas this is sometimes "
131+
"'admin'."))
131132
else:
132133
fields = (
133134
("host", "localhost", "Example: 'localhost' or 'mongodb+srv://CLUSTERNAME.mongodb.net'"),
@@ -137,12 +138,15 @@ def init_yaml(args):
137138
("password", None, "Password for MongoDB authentication"),
138139
("ssl_ca_file", None, "Path to any client certificate to be used for Mongodb connection"),
139140
("authsource", None,
140-
"Database used for authentication, if not connection db. e.g., for MongoDB Atlas this is sometimes 'admin'."))
141+
"Database used for authentication, if not connection db. e.g., for MongoDB Atlas this is sometimes "
142+
"'admin'."))
141143

142144
doc = {}
143145
if args.uri_mode:
144146
print(
145-
"Note 1: You are in URI format mode. This means that all database parameters (username, password, host, port, database name, etc.) must be present in the URI. See: https://docs.mongodb.com/manual/reference/connection-string/ for details.")
147+
"Note 1: You are in URI format mode. This means that all database parameters (username, password, host, "
148+
"port, database name, etc.) must be present in the URI. See: "
149+
"https://docs.mongodb.com/manual/reference/connection-string/ for details.")
146150
print("(Enter your connection URI in under the 'host' parameter)")
147151
print("Please supply the following configuration values")
148152
print("(press Enter if you want to accept the defaults)\n")
@@ -750,7 +754,8 @@ def lpad():
750754
'init', help='Initialize a Fireworks launchpad YAML file.')
751755
init_parser.add_argument('-u', '--uri_mode',
752756
action="store_true",
753-
help="Connect via a URI, see: https://docs.mongodb.com/manual/reference/connection-string/")
757+
help="Connect via a URI, see: "
758+
"https://docs.mongodb.com/manual/reference/connection-string/")
754759
init_parser.add_argument('--config-file', default=DEFAULT_LPAD_YAML,
755760
type=str,
756761
help="Filename to write to.")
@@ -776,14 +781,17 @@ def lpad():
776781
check_wf_parser = subparsers.add_parser('check_wflow', help='validate and graph a workflow from launchpad')
777782
check_wf_parser.add_argument('-i', '--fw_id', type=int, help='the id of a firework from the workflow')
778783
check_wf_parser.add_argument('-g', '--graph', type=str,
779-
help='graph the workflow in DOT format; allowed views: dataflow, controlflow, combined.',
784+
help='graph the workflow in DOT format; allowed views: dataflow, controlflow, '
785+
'combined.',
780786
dest='view', default=None)
781787
check_wf_parser.add_argument('-f', '--dot_file', help='path to store the workflow graph, default: workflow.dot',
782788
default='workflow.dot')
783789
check_wf_parser.set_defaults(func=check_wf, control_flow=False, data_flow=False)
784790

785791
get_launchdir_parser = subparsers.add_parser('get_launchdir',
786-
help='get the directory of the most recent launch of the given fw_id. A common usage is "cd `get_launchdir <FW_ID>`" to change the working directory that of the FW launch')
792+
help='get the directory of the most recent launch of the given fw_id.'
793+
' A common usage is "cd `get_launchdir <FW_ID>`" to change the '
794+
'working directory that of the FW launch')
787795
get_launchdir_parser.add_argument('fw_id', type=int, help='fw_id to chdir to')
788796
get_launchdir_parser.add_argument('--launch_idx', type=int,
789797
help='the index of the launch to get (default of -1 is most recent launch)',
@@ -1075,9 +1083,11 @@ def lpad():
10751083

10761084
webgui_parser = subparsers.add_parser('webgui', help='launch the web GUI')
10771085
webgui_parser.add_argument("--port", dest="port", type=int, default=WEBSERVER_PORT,
1078-
help="Port to run the web server on (default: 5000 or WEBSERVER_PORT arg in FW_config.yaml)")
1086+
help="Port to run the web server on (default: 5000 or WEBSERVER_PORT arg in "
1087+
"FW_config.yaml)")
10791088
webgui_parser.add_argument("--host", dest="host", type=str, default=WEBSERVER_HOST,
1080-
help="Host to run the web server on (default: 127.0.0.1 or WEBSERVER_HOST arg in FW_config.yaml)")
1089+
help="Host to run the web server on (default: 127.0.0.1 or WEBSERVER_HOST arg in "
1090+
"FW_config.yaml)")
10811091
webgui_parser.add_argument('--debug', help='print debug messages', action='store_true')
10821092
webgui_parser.add_argument('-s', '--server_mode', help='run in server mode (skip opening the browser)',
10831093
action='store_true')

fireworks/user_objects/dupefinders/__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__ = 'Mar 01, 2013'
6+
__date__ = 'Mar 01, 2013'

fireworks/user_objects/firetasks/fileio_tasks.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class FileDeleteTask(FiretaskBase):
5555
_fw_name = 'FileDeleteTask'
5656
required_params = ["files_to_delete"]
5757

58-
5958
def run_task(self, fw_spec):
6059
pth = self.get("dest", os.getcwd())
6160
ignore_errors = self.get('ignore_errors', True)
@@ -89,13 +88,13 @@ class FileTransferTask(FiretaskBase):
8988
optional_params = ["server", "user", "key_filename", "max_retry", "retry_delay"]
9089

9190
fn_list = {
92-
"move": shutil.move,
93-
"mv": shutil.move,
94-
"copy": shutil.copy,
95-
"cp": shutil.copy,
96-
"copy2": shutil.copy2,
97-
"copytree": shutil.copytree,
98-
"copyfile": shutil.copyfile,
91+
"move": shutil.move,
92+
"mv": shutil.move,
93+
"copy": shutil.copy,
94+
"cp": shutil.copy,
95+
"copy2": shutil.copy2,
96+
"copytree": shutil.copytree,
97+
"copyfile": shutil.copyfile,
9998
}
10099

101100
def run_task(self, fw_spec):
@@ -128,7 +127,7 @@ def run_task(self, fw_spec):
128127
sftp.mkdir(dest)
129128

130129
for f in os.listdir(src):
131-
if os.path.isfile(os.path.join(src,f)):
130+
if os.path.isfile(os.path.join(src, f)):
132131
sftp.put(os.path.join(src, f), os.path.join(dest, f))
133132
else:
134133
if not self._rexists(sftp, dest):

fireworks/user_objects/firetasks/filepad_tasks.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class GetFilesByQueryTask(FiretaskBase):
105105
"""
106106
_fw_name = 'GetFilesByQueryTask'
107107
required_params = ["query"]
108-
optional_params = ["sort_key","sort_direction", "limit",
109-
"filepad_file", "dest_dir", "new_file_names"]
108+
optional_params = ["sort_key", "sort_direction", "limit",
109+
"filepad_file", "dest_dir", "new_file_names"]
110110

111111
def run_task(self, fw_spec):
112112
import pymongo
@@ -116,14 +116,15 @@ def run_task(self, fw_spec):
116116
query = self.get("query", {})
117117
sort_key = self.get("sort_key", None)
118118
sort_direction = self.get("sort_direction", pymongo.DESCENDING)
119-
limit = self.get("limit",None)
119+
limit = self.get("limit", None)
120120

121-
l = fpad.get_file_by_query(query,sort_key,sort_direction)
121+
l = fpad.get_file_by_query(query, sort_key, sort_direction)
122122
for i, (file_contents, doc) in enumerate(l[:limit]):
123123
file_name = new_file_names[i] if new_file_names else doc["original_file_name"]
124124
with open(os.path.join(dest_dir, file_name), "wb") as f:
125125
f.write(file_contents)
126126

127+
127128
class DeleteFilesTask(FiretaskBase):
128129
"""
129130
A Firetask to delete files from the filepad
@@ -148,4 +149,4 @@ def get_fpad(fpad_file):
148149
if fpad_file:
149150
return FilePad.from_db_file(fpad_file)
150151
else:
151-
return FilePad.auto_load()
152+
return FilePad.auto_load()

fireworks/user_objects/firetasks/templatewriter_task.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import os
1111

12-
from jinja2 import Environment,FileSystemLoader
12+
from jinja2 import Environment, FileSystemLoader
1313

1414
from fireworks.core.firework import FiretaskBase
1515
from fireworks.fw_config import TEMPLATE_DIR

fireworks/user_objects/queue_adapters/common_adapter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def _get_status_cmd(self, username):
108108
if self.get('queue'):
109109
status_cmd.extend(['-p', self['queue']])
110110
elif self.q_type == "LoadSharingFacility":
111-
# use no header and the wide format so that there is one line per job, and display only running and pending jobs
111+
# use no header and the wide format so that there is one line per job, and display only running and
112+
# pending jobs
112113
status_cmd.extend(['-p', '-r', '-o', 'jobID user queue', '-noheader', '-u', username])
113114
elif self.q_type == "Cobalt":
114115
header = "JobId:User:Queue:Jobname:Nodes:Procs:Mode:WallTime:State:RunTime:Project:Location"

0 commit comments

Comments
 (0)