Skip to content

Commit 1d8d042

Browse files
committed
pyupgrade for Python 3.6
1 parent ab8a0f6 commit 1d8d042

File tree

9 files changed

+34
-33
lines changed

9 files changed

+34
-33
lines changed

cwl_flask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class Job(threading.Thread):
1818
def __init__(self, jobid, path, inputobj):
19-
super(Job, self).__init__()
19+
super().__init__()
2020
self.jobid = jobid
2121
self.path = path
2222
self.inputobj = inputobj
@@ -108,7 +108,7 @@ def jobcontrol(jobid):
108108

109109

110110
def logspooler(job):
111-
with open(job.logname, "r") as f:
111+
with open(job.logname) as f:
112112
while True:
113113
r = f.read(4096)
114114
if r:

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
url="https://github.com/common-workflow-language/cwltool-service",
2121
download_url="https://github.com/common-workflow-language/cwltool-service",
2222
license="Apache 2.0",
23-
python_requires="~=3.5",
23+
python_requires="~=3.6",
2424
setup_requires=["pytest-runner"],
2525
tests_require=["pytest"],
2626
packages=["wes_service", "wes_client"],
@@ -53,6 +53,7 @@
5353
"Programming Language :: Python :: 3.6",
5454
"Programming Language :: Python :: 3.7",
5555
"Programming Language :: Python :: 3.8",
56+
"Programming Language :: Python :: 3.9",
5657
"Topic :: Software Development :: Libraries :: Python Modules",
5758
],
5859
)

wes_client/util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def wes_reponse(postresult):
196196
return json.loads(postresult.text)
197197

198198

199-
class WESClient(object):
199+
class WESClient:
200200
def __init__(self, service):
201201
self.auth = service["auth"]
202202
self.proto = service["proto"]
@@ -216,7 +216,7 @@ def get_service_info(self):
216216
:return: The body of the get result as a dictionary.
217217
"""
218218
postresult = requests.get(
219-
"%s://%s/ga4gh/wes/v1/service-info" % (self.proto, self.host),
219+
f"{self.proto}://{self.host}/ga4gh/wes/v1/service-info",
220220
headers=self.auth,
221221
)
222222
return wes_reponse(postresult)
@@ -234,7 +234,7 @@ def list_runs(self):
234234
:return: The body of the get result as a dictionary.
235235
"""
236236
postresult = requests.get(
237-
"%s://%s/ga4gh/wes/v1/runs" % (self.proto, self.host), headers=self.auth
237+
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs", headers=self.auth
238238
)
239239
return wes_reponse(postresult)
240240

@@ -254,7 +254,7 @@ def run(self, wf, jsonyaml, attachments):
254254
attachments = list(expand_globs(attachments))
255255
parts = build_wes_request(wf, jsonyaml, attachments)
256256
postresult = requests.post(
257-
"%s://%s/ga4gh/wes/v1/runs" % (self.proto, self.host),
257+
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs",
258258
files=parts,
259259
headers=self.auth,
260260
)
@@ -271,7 +271,7 @@ def cancel(self, run_id):
271271
:return: The body of the delete result as a dictionary.
272272
"""
273273
postresult = requests.post(
274-
"%s://%s/ga4gh/wes/v1/runs/%s/cancel" % (self.proto, self.host, run_id),
274+
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}/cancel",
275275
headers=self.auth,
276276
)
277277
return wes_reponse(postresult)
@@ -287,7 +287,7 @@ def get_run_log(self, run_id):
287287
:return: The body of the get result as a dictionary.
288288
"""
289289
postresult = requests.get(
290-
"%s://%s/ga4gh/wes/v1/runs/%s" % (self.proto, self.host, run_id),
290+
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}",
291291
headers=self.auth,
292292
)
293293
return wes_reponse(postresult)
@@ -303,7 +303,7 @@ def get_run_status(self, run_id):
303303
:return: The body of the get result as a dictionary.
304304
"""
305305
postresult = requests.get(
306-
"%s://%s/ga4gh/wes/v1/runs/%s/status" % (self.proto, self.host, run_id),
306+
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}/status",
307307
headers=self.auth,
308308
)
309309
return wes_reponse(postresult)

wes_client/wes_client_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def main(argv=sys.argv[1:]):
7171

7272
if args.version:
7373
pkg = pkg_resources.require("wes_service")
74-
print(u"%s %s" % (sys.argv[0], pkg[0].version))
74+
print(f"{sys.argv[0]} {pkg[0].version}")
7575
exit(0)
7676

7777
auth = {}

wes_service/arvados_wes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def invoke_cwl_runner(
175175

176176
self.log_for_run(
177177
cr_uuid,
178-
"Contents of %s:\n%s" % (tempdir, msg),
178+
f"Contents of {tempdir}:\n{msg}",
179179
env["ARVADOS_API_TOKEN"],
180180
)
181181

@@ -367,7 +367,7 @@ def GetRunLog(self, run_id):
367367

368368
def keepref(d):
369369
if isinstance(d, dict) and "location" in d:
370-
d["location"] = "%sc=%s/_/%s" % (
370+
d["location"] = "{}c={}/_/{}".format(
371371
api._resourceDesc["keepWebServiceUrl"],
372372
c.portable_data_hash(),
373373
d["location"],
@@ -395,12 +395,12 @@ def log_object(cr):
395395
"exit_code": containerlog["exit_code"] or 0,
396396
}
397397
if containerlog["log"]:
398-
r["stdout_keep"] = "%sc=%s/_/%s" % (
398+
r["stdout_keep"] = "{}c={}/_/{}".format(
399399
api._resourceDesc["keepWebServiceUrl"],
400400
containerlog["log"],
401401
"stdout.txt",
402402
) # NOQA
403-
r["stderr_keep"] = "%sc=%s/_/%s" % (
403+
r["stderr_keep"] = "{}c={}/_/{}".format(
404404
api._resourceDesc["keepWebServiceUrl"],
405405
containerlog["log"],
406406
"stderr.txt",

wes_service/cwl_runner.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
from wes_service.util import WESBackend
77

88

9-
class Workflow(object):
9+
class Workflow:
1010
def __init__(self, run_id):
11-
super(Workflow, self).__init__()
11+
super().__init__()
1212
self.run_id = run_id
1313
self.workdir = os.path.join(os.getcwd(), "workflows", self.run_id)
1414
self.outdir = os.path.join(self.workdir, "outdir")
@@ -94,7 +94,7 @@ def getstate(self):
9494
with open(exitcode_file) as f:
9595
exit_code = int(f.read())
9696
elif os.path.exists(pid_file):
97-
with open(pid_file, "r") as pid:
97+
with open(pid_file) as pid:
9898
pid = int(pid.read())
9999
try:
100100
(_pid, exit_status) = os.waitpid(pid, os.WNOHANG)
@@ -122,16 +122,16 @@ def getstatus(self):
122122
def getlog(self):
123123
state, exit_code = self.getstate()
124124

125-
with open(os.path.join(self.workdir, "request.json"), "r") as f:
125+
with open(os.path.join(self.workdir, "request.json")) as f:
126126
request = json.load(f)
127127

128-
with open(os.path.join(self.workdir, "stderr"), "r") as f:
128+
with open(os.path.join(self.workdir, "stderr")) as f:
129129
stderr = f.read()
130130

131131
outputobj = {}
132132
if state == "COMPLETE":
133133
output_path = os.path.join(self.workdir, "cwl.output.json")
134-
with open(output_path, "r") as outputtemp:
134+
with open(output_path) as outputtemp:
135135
outputobj = json.load(outputtemp)
136136

137137
return {

wes_service/toil_wes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
logging.basicConfig(level=logging.INFO)
1313

1414

15-
class ToilWorkflow(object):
15+
class ToilWorkflow:
1616
def __init__(self, run_id):
1717
"""
1818
Represents a toil workflow.
1919
2020
:param str run_id: A uuid string. Used to name the folder that contains
2121
all of the files containing this particular workflow instance's information.
2222
"""
23-
super(ToilWorkflow, self).__init__()
23+
super().__init__()
2424
self.run_id = run_id
2525

2626
self.workdir = os.path.join(os.getcwd(), "workflows", self.run_id)
@@ -135,17 +135,17 @@ def cancel(self):
135135

136136
def fetch(self, filename):
137137
if os.path.exists(filename):
138-
with open(filename, "r") as f:
138+
with open(filename) as f:
139139
return f.read()
140140
return ""
141141

142142
def getlog(self):
143143
state, exit_code = self.getstate()
144144

145-
with open(self.request_json, "r") as f:
145+
with open(self.request_json) as f:
146146
request = json.load(f)
147147

148-
with open(self.jobstorefile, "r") as f:
148+
with open(self.jobstorefile) as f:
149149
self.jobstore = f.read()
150150

151151
stderr = self.fetch(self.errfile)
@@ -269,7 +269,7 @@ def getstate(self):
269269

270270
# TODO: Query with "toil status"
271271
completed = False
272-
with open(self.errfile, "r") as f:
272+
with open(self.errfile) as f:
273273
for line in f:
274274
if "Traceback (most recent call last)" in line:
275275
logging.info("Workflow " + self.run_id + ": EXECUTOR_ERROR")

wes_service/util.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def visit(d, op):
1818
visit(i, op)
1919

2020

21-
class WESBackend(object):
21+
class WESBackend:
2222
"""Stores and retrieves options. Intended to be inherited."""
2323

2424
def __init__(self, opts):
@@ -64,7 +64,7 @@ def collect_attachments(self, run_id=None):
6464
os.makedirs(os.path.dirname(dest))
6565
self.log_for_run(
6666
run_id,
67-
"Staging attachment '%s' to '%s'" % (v.filename, dest),
67+
f"Staging attachment '{v.filename}' to '{dest}'",
6868
)
6969
v.save(dest)
7070
has_attachments = True
@@ -77,7 +77,7 @@ def collect_attachments(self, run_id=None):
7777
else:
7878
body[k] = v.read().decode()
7979
except Exception as e:
80-
raise ValueError("Error reading parameter '%s': %s" % (k, e))
80+
raise ValueError(f"Error reading parameter '{k}': {e}")
8181
for k, ls in connexion.request.form.lists():
8282
try:
8383
for v in ls:
@@ -88,7 +88,7 @@ def collect_attachments(self, run_id=None):
8888
else:
8989
body[k] = v
9090
except Exception as e:
91-
raise ValueError("Error reading parameter '%s': %s" % (k, e))
91+
raise ValueError(f"Error reading parameter '{k}': {e}")
9292

9393
if "workflow_url" in body:
9494
if ":" not in body["workflow_url"]:

wes_service/wes_service_main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def setup(args=None):
1919
configfile = "config.yml"
2020
if os.path.isfile(configfile):
2121
logging.info("Loading %s", configfile)
22-
with open(configfile, "r") as f:
22+
with open(configfile) as f:
2323
config = ruamel.yaml.safe_load(f)
2424
for c in config:
2525
setattr(args, c, config[c])
@@ -69,7 +69,7 @@ def main(argv=sys.argv[1:]):
6969

7070
if args.version:
7171
pkg = pkg_resources.require("wes_service")
72-
print(u"%s %s" % (sys.argv[0], pkg[0].version))
72+
print(f"{sys.argv[0]} {pkg[0].version}")
7373
exit(0)
7474

7575
app = setup(args)

0 commit comments

Comments
 (0)