Skip to content

Commit 93848ac

Browse files
committed
Doc fixes
1 parent b5c8d2e commit 93848ac

File tree

10 files changed

+88
-14
lines changed

10 files changed

+88
-14
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ remove_unused_imports: $(PYSOURCES)
8888

8989
pep257: pydocstyle
9090
## pydocstyle : check Python docstring style
91-
pydocstyle: $(PYSOURCES)
91+
pydocstyle: $(PYSOURCES) FORCE
9292
pydocstyle --add-ignore=D100,D101,D102,D103 $^ || true
9393

94-
pydocstyle_report.txt: $(PYSOURCES)
94+
pydocstyle_report.txt: $(PYSOURCES) FORCE
9595
pydocstyle $^ > $@ 2>&1 || true
9696

9797
## diff_pydocstyle_report : check Python docstring style for changed files only

cwl_flask.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Simple webapp for running cwl-runner."""
2+
13
import copy
24
import json
35
import shutil
@@ -19,7 +21,10 @@
1921

2022

2123
class Job(threading.Thread):
24+
"""cwl-runner webapp."""
25+
2226
def __init__(self, jobid: int, path: str, inputobj: bytes) -> None:
27+
"""Initialize the execution Job."""
2328
super().__init__()
2429
self.jobid = jobid
2530
self.path = path
@@ -28,6 +33,7 @@ def __init__(self, jobid: int, path: str, inputobj: bytes) -> None:
2833
self.begin()
2934

3035
def begin(self) -> None:
36+
"""Star executing using cwl-runner."""
3137
loghandle, self.logname = tempfile.mkstemp()
3238
with self.updatelock:
3339
self.outdir = tempfile.mkdtemp()
@@ -49,6 +55,7 @@ def begin(self) -> None:
4955
}
5056

5157
def run(self) -> None:
58+
"""Wait for execution to finish and report the result."""
5259
self.stdoutdata, self.stderrdata = self.proc.communicate(self.inputobj)
5360
if self.proc.returncode == 0:
5461
outobj = yaml.load(self.stdoutdata, Loader=yaml.FullLoader)
@@ -60,22 +67,26 @@ def run(self) -> None:
6067
self.status["state"] = "Failed"
6168

6269
def getstatus(self) -> Dict[str, Any]:
70+
"""Report the current status."""
6371
with self.updatelock:
6472
return self.status.copy()
6573

6674
def cancel(self) -> None:
75+
"""Cancel the excution thread, if any."""
6776
if self.status["state"] == "Running":
6877
self.proc.send_signal(signal.SIGQUIT)
6978
with self.updatelock:
7079
self.status["state"] = "Canceled"
7180

7281
def pause(self) -> None:
82+
"""Pause the execution thread, if any."""
7383
if self.status["state"] == "Running":
7484
self.proc.send_signal(signal.SIGTSTP)
7585
with self.updatelock:
7686
self.status["state"] = "Paused"
7787

7888
def resume(self) -> None:
89+
"""If paused, then resume the execution thread."""
7990
if self.status["state"] == "Paused":
8091
self.proc.send_signal(signal.SIGCONT)
8192
with self.updatelock:
@@ -84,6 +95,7 @@ def resume(self) -> None:
8495

8596
@app.route("/run", methods=["POST"])
8697
def runworkflow() -> werkzeug.wrappers.response.Response:
98+
"""Accept a workflow exection request and run it."""
8799
path = request.args["wf"]
88100
with jobs_lock:
89101
jobid = len(jobs)
@@ -95,6 +107,7 @@ def runworkflow() -> werkzeug.wrappers.response.Response:
95107

96108
@app.route("/jobs/<int:jobid>", methods=["GET", "POST"])
97109
def jobcontrol(jobid: int) -> Tuple[str, int]:
110+
"""Accept a job related action and report the result."""
98111
with jobs_lock:
99112
job = jobs[jobid]
100113
if request.method == "POST":
@@ -112,6 +125,7 @@ def jobcontrol(jobid: int) -> Tuple[str, int]:
112125

113126

114127
def logspooler(job: Job) -> Generator[str, None, None]:
128+
"""Yield 4 kilobytes of log text at a time."""
115129
with open(job.logname) as f:
116130
while True:
117131
r = f.read(4096)
@@ -126,13 +140,15 @@ def logspooler(job: Job) -> Generator[str, None, None]:
126140

127141
@app.route("/jobs/<int:jobid>/log", methods=["GET"])
128142
def getlog(jobid: int) -> Response:
143+
"""Dump the log."""
129144
with jobs_lock:
130145
job = jobs[jobid]
131146
return Response(logspooler(job))
132147

133148

134149
@app.route("/jobs", methods=["GET"])
135150
def getjobs() -> Response:
151+
"""Report all known jobs."""
136152
with jobs_lock:
137153
jobscopy = copy.copy(jobs)
138154

cwltool_stream.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
def main(args: List[str] = sys.argv[1:]) -> int:
17+
"""Streaming execution of cwltool."""
1718
if len(args) == 0:
1819
print("Workflow must be on command line")
1920
return 1

wes_client/util.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717

1818

1919
def py3_compatible(filePath: str) -> bool:
20-
"""Determines if a python file is 3.x compatible by seeing if it compiles in a subprocess"""
20+
"""
21+
Check file for Python 3.x compatibity.
22+
23+
(By seeing if it compiles in a subprocess)
24+
"""
2125
try:
2226
check_call(
2327
[sys.executable, "-m", "py_compile", os.path.normpath(filePath)],
@@ -29,7 +33,7 @@ def py3_compatible(filePath: str) -> bool:
2933

3034

3135
def get_version(extension: str, workflow_file: str) -> str:
32-
"""Determines the version of a .py, .wdl, or .cwl file."""
36+
"""Determine the version of a .py, .wdl, or .cwl file."""
3337
if extension == "py" and py3_compatible(workflow_file):
3438
return "3"
3539
elif extension == "cwl":
@@ -49,14 +53,13 @@ def get_version(extension: str, workflow_file: str) -> str:
4953

5054
def wf_info(workflow_path: str) -> Tuple[str, str]:
5155
"""
52-
Returns the version of the file and the file extension.
56+
Return the version of the file and the file extension.
5357
5458
Assumes that the file path is to the file directly ie, ends with a valid
5559
file extension. Supports checking local files as well as files at http://
5660
and https:// locations. Files at these remote locations are recreated locally to
5761
enable our approach to version checking, then removed after version is extracted.
5862
"""
59-
6063
supported_formats = ["py", "wdl", "cwl"]
6164
file_type = workflow_path.lower().split(".")[-1] # Grab the file extension
6265
workflow_path = workflow_path if ":" in workflow_path else "file://" + workflow_path
@@ -185,6 +188,7 @@ def build_wes_request(
185188

186189

187190
def expand_globs(attachments: Optional[Union[List[str], str]]) -> Set[str]:
191+
"""Expand any globs present in the attachment list."""
188192
expanded_list = []
189193
if attachments is None:
190194
attachments = []
@@ -200,7 +204,8 @@ def expand_globs(attachments: Optional[Union[List[str], str]]) -> Set[str]:
200204
return set(expanded_list)
201205

202206

203-
def wes_reponse(postresult: requests.Response) -> Dict[str, Any]:
207+
def wes_response(postresult: requests.Response) -> Dict[str, Any]:
208+
"""Convert a Response object to JSON text."""
204209
if postresult.status_code != 200:
205210
error = str(json.loads(postresult.text))
206211
logging.error(error)
@@ -210,7 +215,10 @@ def wes_reponse(postresult: requests.Response) -> Dict[str, Any]:
210215

211216

212217
class WESClient:
218+
"""WES client."""
219+
213220
def __init__(self, service: Dict[str, Any]):
221+
"""Initialize the cliet with the provided credentials and endpoint."""
214222
self.auth = service["auth"]
215223
self.proto = service["proto"]
216224
self.host = service["host"]
@@ -232,7 +240,7 @@ def get_service_info(self) -> Dict[str, Any]:
232240
f"{self.proto}://{self.host}/ga4gh/wes/v1/service-info",
233241
headers=self.auth,
234242
)
235-
return wes_reponse(postresult)
243+
return wes_response(postresult)
236244

237245
def list_runs(self) -> Dict[str, Any]:
238246
"""
@@ -249,7 +257,7 @@ def list_runs(self) -> Dict[str, Any]:
249257
postresult = requests.get( # nosec B113
250258
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs", headers=self.auth
251259
)
252-
return wes_reponse(postresult)
260+
return wes_response(postresult)
253261

254262
def run(
255263
self, wf: str, jsonyaml: str, attachments: Optional[List[str]]
@@ -273,7 +281,7 @@ def run(
273281
files=parts,
274282
headers=self.auth,
275283
)
276-
return wes_reponse(postresult)
284+
return wes_response(postresult)
277285

278286
def cancel(self, run_id: str) -> Dict[str, Any]:
279287
"""
@@ -289,7 +297,7 @@ def cancel(self, run_id: str) -> Dict[str, Any]:
289297
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}/cancel",
290298
headers=self.auth,
291299
)
292-
return wes_reponse(postresult)
300+
return wes_response(postresult)
293301

294302
def get_run_log(self, run_id: str) -> Dict[str, Any]:
295303
"""
@@ -305,7 +313,7 @@ def get_run_log(self, run_id: str) -> Dict[str, Any]:
305313
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}",
306314
headers=self.auth,
307315
)
308-
return wes_reponse(postresult)
316+
return wes_response(postresult)
309317

310318
def get_run_status(self, run_id: str) -> Dict[str, Any]:
311319
"""
@@ -321,4 +329,4 @@ def get_run_status(self, run_id: str) -> Dict[str, Any]:
321329
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}/status",
322330
headers=self.auth,
323331
)
324-
return wes_reponse(postresult)
332+
return wes_response(postresult)

wes_client/wes_client_main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
def main(argv: List[str] = sys.argv[1:]) -> int:
18+
"""Run the WES service."""
1819
parser = argparse.ArgumentParser(description="Workflow Execution Service")
1920
parser.add_argument(
2021
"--host",

wes_service/arvados_wes.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Arvados backed for the WES service."""
2+
13
import functools
24
import json
35
import logging
@@ -21,7 +23,8 @@ class MissingAuthorization(Exception):
2123
pass
2224

2325

24-
def get_api(authtoken: Optional[str] = None) -> Any:
26+
def get_api(authtoken: Optional[str] = None) -> arvados.api.api:
27+
"""Retrieve an Arvados API object."""
2528
if authtoken is None:
2629
if not connexion.request.headers.get("Authorization"):
2730
raise MissingAuthorization()
@@ -82,7 +85,10 @@ def catch_exceptions_wrapper(self: Any, *args: str, **kwargs: str) -> Any:
8285

8386

8487
class ArvadosBackend(WESBackend):
88+
"""Arvados backend for the WES Service."""
89+
8590
def GetServiceInfo(self) -> Dict[str, Any]:
91+
"""Report metadata about this WES endpoint."""
8692
stdout, stderr = subprocess.Popen( # nosec B603
8793
[shutil.which("arvados-cwl-runner") or "arvados-cwl-runner", "--version"],
8894
stderr=subprocess.PIPE,
@@ -107,6 +113,7 @@ def ListRuns(
107113
page_token: Optional[str] = None,
108114
state_search: Any = None,
109115
) -> Dict[str, Any]:
116+
"""List the known workflow runs."""
110117
api = get_api()
111118

112119
paging = []
@@ -151,6 +158,7 @@ def ListRuns(
151158
def log_for_run(
152159
self, run_id: Optional[str], message: str, authtoken: Optional[str] = None
153160
) -> None:
161+
"""Report the log for a given run."""
154162
get_api(authtoken).logs().create(
155163
body={
156164
"log": {
@@ -170,6 +178,7 @@ def invoke_cwl_runner(
170178
project_uuid: str,
171179
tempdir: str,
172180
) -> None:
181+
"""Submit the workflow using `arvados-cwl-runner`."""
173182
api = arvados.api_from_config(
174183
version="v1",
175184
apiconfig={
@@ -253,6 +262,7 @@ def invoke_cwl_runner(
253262
def RunWorkflow(
254263
self, **args: str
255264
) -> Union[Tuple[Dict[str, Any], int], Dict[str, Any]]:
265+
"""Submit the workflow run request."""
256266
if not connexion.request.headers.get("Authorization"):
257267
raise MissingAuthorization()
258268

@@ -349,6 +359,7 @@ def RunWorkflow(
349359

350360
@catch_exceptions
351361
def GetRunLog(self, run_id: str) -> Dict[str, str]:
362+
"""Get the log for a particular workflow run."""
352363
api = get_api()
353364

354365
request = api.container_requests().get(uuid=run_id).execute()
@@ -450,6 +461,7 @@ def log_object(cr: Dict[str, Any]) -> Dict[str, Any]:
450461

451462
@catch_exceptions
452463
def CancelRun(self, run_id: str) -> Dict[str, Any]: # NOQA
464+
"""Cancel a submitted run."""
453465
api = get_api()
454466
request = (
455467
api.container_requests().update(uuid=run_id, body={"priority": 0}).execute()
@@ -458,6 +470,7 @@ def CancelRun(self, run_id: str) -> Dict[str, Any]: # NOQA
458470

459471
@catch_exceptions
460472
def GetRunStatus(self, run_id: str) -> Dict[str, Any]:
473+
"""Determine the status for a given run."""
461474
api = get_api()
462475
request = api.container_requests().get(uuid=run_id).execute()
463476
if request["container_uuid"]:
@@ -472,6 +485,7 @@ def GetRunStatus(self, run_id: str) -> Dict[str, Any]:
472485

473486

474487
def dynamic_logs(run_id: str, logstream: str) -> str:
488+
"""Retrienve logs, chasing down the container logs as well."""
475489
api = get_api()
476490
cr = api.container_requests().get(uuid=run_id).execute()
477491
l1 = [
@@ -504,6 +518,7 @@ def dynamic_logs(run_id: str, logstream: str) -> str:
504518

505519

506520
def create_backend(app: Any, opts: List[str]) -> ArvadosBackend:
521+
"""Instantiate an ArvadosBackend."""
507522
ab = ArvadosBackend(opts)
508523
app.app.route("/ga4gh/wes/v1/runs/<run_id>/x-dynamic-logs/<logstream>")(
509524
dynamic_logs

0 commit comments

Comments
 (0)