Skip to content

Commit 1deb372

Browse files
committed
lint the code
1 parent 914372b commit 1deb372

File tree

11 files changed

+62
-44
lines changed

11 files changed

+62
-44
lines changed

.flake8

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[flake8]
2-
ignore = E203, E266, E501, W503, E211, E731
3-
max-line-length = 88
4-
select = B,C,E,F,W,T4,B9
2+
max-line-length = 100
3+
select = B,C,E,F,W,T4
4+
exclude = cwltool/schemas
5+
extend-ignore = E203,E501,E704,B905,W503
6+
# when Python 3.10 is the minimum version, re-enable check B905 for zip + strict
7+
extend-select = B9

dev-requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
build
2-
flake8
3-
pytest
4-
black

lint-requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
flake8
2-
black
1+
flake8-bugbear < 24.5
2+
black ~= 25.0
3+
codespell
4+
isort >= 5

test/test_client_util.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import logging
22
import os
33
import subprocess
4-
import sys
54
import unittest
65

76
from wes_client.util import expand_globs, wf_info
87

98
logging.basicConfig(level=logging.INFO)
109

10+
PRE = "https://raw.githubusercontent.com/common-workflow-language/workflow-service/main"
11+
1112

1213
class IntegrationTest(unittest.TestCase):
1314
def setUp(self):
@@ -21,10 +22,11 @@ def setUp(self):
2122
}
2223

2324
self.remote = {
24-
"cwl": "https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.cwl",
25-
"wdl": "https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/testdata/md5sum.wdl",
26-
"py": "https://raw.githubusercontent.com/common-workflow-language/workflow-service/master/test/test_integration.py",
27-
"unsupported": "gs://topmed_workflow_testing/topmed_aligner/small_test_files_sbg/example_human_known_snp.py",
25+
"cwl": f"{PRE}/testdata/md5sum.cwl",
26+
"wdl": f"{PRE}/testdata/md5sum.wdl",
27+
"py": f"{PRE}/test/test_integration.py",
28+
"unsupported": "gs://topmed_workflow_testing/topmed_aligner/"
29+
"small_test_files_sbg/example_human_known_snp.py",
2830
"unreachable": "https://fake.py",
2931
}
3032

@@ -63,7 +65,8 @@ def testSupportedFormatChecking(self):
6365

6466
for file_format, location in self.local.items():
6567
if file_format != "unsupported":
66-
# Tests the behavior after receiving supported file types with and without the 'file://' prefix
68+
# Tests the behavior after receiving supported file types with
69+
# and without the 'file://' prefix
6770
self.assertEqual(wf_info(location), self.expected[file_format])
6871
self.assertEqual(wf_info(location[7:]), self.expected[file_format])
6972

test/test_integration.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
import shutil
44
import signal
55
import subprocess
6-
import sys
76
import time
87
import unittest
98

109
import pytest
1110
import requests
1211

13-
pkg_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) # noqa
14-
sys.path.insert(0, pkg_root) # noqa
15-
1612
from wes_client.util import WESClient
1713

1814
logging.basicConfig(level=logging.INFO)
@@ -24,7 +20,11 @@ class IntegrationTest(unittest.TestCase):
2420
@classmethod
2521
def setUpClass(cls):
2622
# cwl
27-
cls.cwl_dockstore_url = "https://dockstore.org/api/ga4gh/trs/v2/tools/quay.io%2Fbriandoconnor%2Fdockstore-tool-md5sum/versions/1.0.4/plain-CWL/descriptor//Dockstore.cwl"
23+
cls.cwl_dockstore_url = (
24+
"https://dockstore.org/api/ga4gh/trs/v2/tools/"
25+
"github.com%2Fbrianoconnor%2Fdockstore-tool-md5sum/versions/"
26+
"master/PLAIN_CWL/descriptor//Dockstore.cwl"
27+
)
2828
cls.cwl_local_path = "file://" + os.path.abspath("testdata/md5sum.cwl")
2929
cls.cwl_json_input = "file://" + os.path.abspath("testdata/md5sum.json")
3030
cls.cwl_attachments = [
@@ -67,7 +67,7 @@ def test_dockstore_md5sum(self):
6767
json_input=self.cwl_json_input,
6868
workflow_attachment=self.cwl_attachments,
6969
)
70-
state = self.wait_for_finish(run_id)
70+
self.wait_for_finish(run_id)
7171
self.check_complete(run_id)
7272
self.assertTrue(
7373
self.check_for_file(outfile_path),
@@ -81,7 +81,7 @@ def test_local_md5sum(self):
8181
json_input=self.cwl_json_input,
8282
workflow_attachment=self.cwl_attachments,
8383
)
84-
state = self.wait_for_finish(run_id)
84+
self.wait_for_finish(run_id)
8585
self.check_complete(run_id)
8686
self.assertTrue(
8787
self.check_for_file(outfile_path),
@@ -100,7 +100,7 @@ def test_run_attachments(self):
100100
workflow_attachment=self.cwl_attachments,
101101
)
102102
get_response = self.client.get_run_log(run_id)["request"]
103-
state = self.wait_for_finish(run_id)
103+
self.wait_for_finish(run_id)
104104
self.check_complete(run_id)
105105
self.assertTrue(
106106
self.check_for_file(outfile_path),
@@ -151,7 +151,11 @@ def test_get_run_status(self):
151151
assert "run_id" in r
152152

153153
def run_md5sum(self, wf_input, json_input, workflow_attachment=None):
154-
"""Pass a local md5sum cwl to the wes-service server, and return the path of the output file that was created."""
154+
"""
155+
Pass a local md5sum cwl to the wes-service server.
156+
157+
:return: the path of the output file that was created.
158+
"""
155159
response = self.client.run(wf_input, json_input, workflow_attachment)
156160
assert "run_id" in response, str(response.json())
157161
output_dir = os.path.abspath(

wes_client/util.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Client WES utilities."""
2+
13
import glob
24
import json
35
import logging
@@ -16,8 +18,8 @@ def py3_compatible(filePath):
1618
"""Determines if a python file is 3.x compatible by seeing if it compiles in a subprocess"""
1719
try:
1820
check_call(["python3", "-m", "py_compile", filePath], stderr=DEVNULL)
19-
except CalledProcessError:
20-
raise RuntimeError("Python files must be 3.x compatible")
21+
except CalledProcessError as e:
22+
raise RuntimeError("Python files must be 3.x compatible") from e
2123
return True
2224

2325

@@ -28,7 +30,8 @@ def get_version(extension, workflow_file):
2830
elif extension == "cwl":
2931
return yaml.load(open(workflow_file), Loader=yaml.FullLoader)["cwlVersion"]
3032
else: # Must be a wdl file.
31-
# Borrowed from https://github.com/Sage-Bionetworks/synapse-orchestrator/blob/develop/synorchestrator/util.py#L142
33+
# Borrowed from https://github.com/Sage-Bionetworks/synapse-orchestrator/
34+
# blob/develop/synorchestrator/util.py#L142
3235
try:
3336
return [
3437
entry.lstrip("version")
@@ -43,8 +46,9 @@ def wf_info(workflow_path):
4346
"""
4447
Returns the version of the file and the file extension.
4548
46-
Assumes that the file path is to the file directly ie, ends with a valid file extension.Supports checking local
47-
files as well as files at http:// and https:// locations. Files at these remote locations are recreated locally to
49+
Assumes that the file path is to the file directly ie, ends with a valid
50+
file extension. Supports checking local files as well as files at http://
51+
and https:// locations. Files at these remote locations are recreated locally to
4852
enable our approach to version checking, then removed after version is extracted.
4953
"""
5054

wes_client/wes_client_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ def main(argv=sys.argv[1:]):
2525
"--auth",
2626
type=str,
2727
default=os.environ.get("WES_API_AUTH"),
28-
help="Format is 'Header: value' or just 'value'. If header name is not provided, value goes in the 'Authorization'. Defaults to WES_API_AUTH.",
28+
help="Format is 'Header: value' or just 'value'. If header name is not "
29+
"provided, value goes in the 'Authorization'. Defaults to WES_API_AUTH.",
2930
)
3031
parser.add_argument(
3132
"--proto",

wes_service/arvados_wes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def invoke_cwl_runner(
172172
inputtemp.flush()
173173

174174
msg = ""
175-
for dirpath, dirs, files in os.walk(tempdir):
175+
for dirpath, _dirs, files in os.walk(tempdir):
176176
for f in files:
177177
msg += " " + dirpath + "/" + f + "\n"
178178

wes_service/cwl_runner.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def run(self, request, tempdir, opts):
2626
CWL (url):
2727
request["workflow_url"] == a url to a cwl file
2828
or
29-
request["workflow_attachment"] == input cwl text (written to a file and a url constructed for that file)
29+
request["workflow_attachment"] == input cwl text
30+
(written to a file and a url constructed for that file)
3031
3132
JSON File:
3233
request["workflow_params"] == input json text (to be written to a file)
@@ -53,10 +54,11 @@ def run(self, request, tempdir, opts):
5354
extra = opts.getoptlist("extra")
5455

5556
# replace any locally specified outdir with the default
57+
extra2 = []
5658
for e in extra:
57-
if e.startswith("--outdir="):
58-
extra.remove(e)
59-
extra.append("--outdir=" + self.outdir)
59+
if not e.startswith("--outdir="):
60+
extra2.append(e)
61+
extra2.append("--outdir=" + self.outdir)
6062

6163
# link the cwl and json into the tempdir/cwd
6264
if workflow_url.startswith("file://"):
@@ -66,7 +68,7 @@ def run(self, request, tempdir, opts):
6668
jsonpath = os.path.join(tempdir, "cwl.input.json")
6769

6870
# build args and run
69-
command_args = [runner] + extra + [workflow_url, jsonpath]
71+
command_args = [runner] + extra2 + [workflow_url, jsonpath]
7072
proc = subprocess.Popen(
7173
command_args, stdout=output, stderr=stderr, close_fds=True, cwd=tempdir
7274
)

wes_service/toil_wes.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,25 @@ def __init__(self, run_id):
4545
def sort_toil_options(self, extra):
4646
# determine jobstore and set a new default if the user did not set one
4747
cloud = False
48+
extra2 = []
4849
for e in extra:
4950
if e.startswith("--jobStore="):
5051
self.jobstore = e[11:]
5152
if self.jobstore.startswith(("aws", "google", "azure")):
5253
cloud = True
53-
if e.startswith(("--outdir=", "-o=")):
54-
extra.remove(e)
54+
if not e.startswith(("--outdir=", "-o=")):
55+
extra2.append(e)
5556
if not cloud:
56-
extra.append("--outdir=" + self.outdir)
57+
extra2.append("--outdir=" + self.outdir)
5758
if not self.jobstore:
58-
extra.append("--jobStore=" + self.jobstore_default)
59+
extra2.append("--jobStore=" + self.jobstore_default)
5960
self.jobstore = self.jobstore_default
6061

6162
# store the jobstore location
6263
with open(self.jobstorefile, "w") as f:
6364
f.write(self.jobstore)
6465

65-
return extra
66+
return extra2
6667

6768
def write_workflow(self, request, opts, cwd, wftype="cwl"):
6869
"""Writes a cwl, wdl, or python file as appropriate from the request dictionary."""
@@ -199,7 +200,8 @@ def run(self, request, tempdir, opts):
199200
CWL (url):
200201
request["workflow_url"] == a url to a cwl file
201202
or
202-
request["workflow_attachment"] == input cwl text (written to a file and a url constructed for that file)
203+
request["workflow_attachment"] == input cwl text
204+
(written to a file and a url constructed for that file)
203205
204206
JSON File:
205207
request["workflow_params"] == input json text (to be written to a file)

0 commit comments

Comments
 (0)