Skip to content

Commit 0ff2d65

Browse files
committed
Doc fixes
1 parent b4ee4c8 commit 0ff2d65

File tree

10 files changed

+84
-14
lines changed

10 files changed

+84
-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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
class Job(threading.Thread):
2222
def __init__(self, jobid: int, path: str, inputobj: bytes) -> None:
23+
"""Initialize the execution Job."""
2324
super().__init__()
2425
self.jobid = jobid
2526
self.path = path
@@ -28,6 +29,7 @@ def __init__(self, jobid: int, path: str, inputobj: bytes) -> None:
2829
self.begin()
2930

3031
def begin(self) -> None:
32+
"""Star executing using cwl-runner."""
3133
loghandle, self.logname = tempfile.mkstemp()
3234
with self.updatelock:
3335
self.outdir = tempfile.mkdtemp()
@@ -49,6 +51,7 @@ def begin(self) -> None:
4951
}
5052

5153
def run(self) -> None:
54+
"""Wait for execution to finish and report the result."""
5255
self.stdoutdata, self.stderrdata = self.proc.communicate(self.inputobj)
5356
if self.proc.returncode == 0:
5457
outobj = yaml.load(self.stdoutdata, Loader=yaml.FullLoader)
@@ -60,22 +63,26 @@ def run(self) -> None:
6063
self.status["state"] = "Failed"
6164

6265
def getstatus(self) -> Dict[str, Any]:
66+
"""Report the current status."""
6367
with self.updatelock:
6468
return self.status.copy()
6569

6670
def cancel(self) -> None:
71+
"""Cancel the excution thread, if any."""
6772
if self.status["state"] == "Running":
6873
self.proc.send_signal(signal.SIGQUIT)
6974
with self.updatelock:
7075
self.status["state"] = "Canceled"
7176

7277
def pause(self) -> None:
78+
"""Pause the execution thread, if any."""
7379
if self.status["state"] == "Running":
7480
self.proc.send_signal(signal.SIGTSTP)
7581
with self.updatelock:
7682
self.status["state"] = "Paused"
7783

7884
def resume(self) -> None:
85+
"""If paused, then resume the execution thread."""
7986
if self.status["state"] == "Paused":
8087
self.proc.send_signal(signal.SIGCONT)
8188
with self.updatelock:
@@ -84,6 +91,7 @@ def resume(self) -> None:
8491

8592
@app.route("/run", methods=["POST"])
8693
def runworkflow() -> werkzeug.wrappers.response.Response:
94+
"""Accept a workflow exection request and run it."""
8795
path = request.args["wf"]
8896
with jobs_lock:
8997
jobid = len(jobs)
@@ -95,6 +103,7 @@ def runworkflow() -> werkzeug.wrappers.response.Response:
95103

96104
@app.route("/jobs/<int:jobid>", methods=["GET", "POST"])
97105
def jobcontrol(jobid: int) -> Tuple[str, int]:
106+
"""Accept a job related action and report the result."""
98107
with jobs_lock:
99108
job = jobs[jobid]
100109
if request.method == "POST":
@@ -112,6 +121,7 @@ def jobcontrol(jobid: int) -> Tuple[str, int]:
112121

113122

114123
def logspooler(job: Job) -> Generator[str, None, None]:
124+
"""Yield 4 kilobytes of log text at a time."""
115125
with open(job.logname) as f:
116126
while True:
117127
r = f.read(4096)
@@ -126,13 +136,15 @@ def logspooler(job: Job) -> Generator[str, None, None]:
126136

127137
@app.route("/jobs/<int:jobid>/log", methods=["GET"])
128138
def getlog(jobid: int) -> Response:
139+
"""Dump the log."""
129140
with jobs_lock:
130141
job = jobs[jobid]
131142
return Response(logspooler(job))
132143

133144

134145
@app.route("/jobs", methods=["GET"])
135146
def getjobs() -> Response:
147+
"""Report all known jobs."""
136148
with jobs_lock:
137149
jobscopy = copy.copy(jobs)
138150

cwltool_stream.py

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

1414

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

wes_client/util.py

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

1616

1717
def py3_compatible(filePath: str) -> bool:
18-
"""Determines if a python file is 3.x compatible by seeing if it compiles in a subprocess"""
18+
"""
19+
Check file for Python 3.x compatibity.
20+
21+
(By seeing if it compiles in a subprocess)
22+
"""
1923
try:
2024
check_call(
2125
[sys.executable, "-m", "py_compile", os.path.normpath(filePath)],
@@ -27,7 +31,7 @@ def py3_compatible(filePath: str) -> bool:
2731

2832

2933
def get_version(extension: str, workflow_file: str) -> str:
30-
"""Determines the version of a .py, .wdl, or .cwl file."""
34+
"""Determine the version of a .py, .wdl, or .cwl file."""
3135
if extension == "py" and py3_compatible(workflow_file):
3236
return "3"
3337
elif extension == "cwl":
@@ -47,14 +51,13 @@ def get_version(extension: str, workflow_file: str) -> str:
4751

4852
def wf_info(workflow_path: str) -> Tuple[str, str]:
4953
"""
50-
Returns the version of the file and the file extension.
54+
Return the version of the file and the file extension.
5155
5256
Assumes that the file path is to the file directly ie, ends with a valid
5357
file extension. Supports checking local files as well as files at http://
5458
and https:// locations. Files at these remote locations are recreated locally to
5559
enable our approach to version checking, then removed after version is extracted.
5660
"""
57-
5861
supported_formats = ["py", "wdl", "cwl"]
5962
file_type = workflow_path.lower().split(".")[-1] # Grab the file extension
6063
workflow_path = workflow_path if ":" in workflow_path else "file://" + workflow_path
@@ -183,6 +186,7 @@ def build_wes_request(
183186

184187

185188
def expand_globs(attachments: Optional[Union[List[str], str]]) -> Set[str]:
189+
"""Expand any globs present in the attachment list."""
186190
expanded_list = []
187191
if attachments is None:
188192
attachments = []
@@ -198,7 +202,8 @@ def expand_globs(attachments: Optional[Union[List[str], str]]) -> Set[str]:
198202
return set(expanded_list)
199203

200204

201-
def wes_reponse(postresult: requests.Response) -> Dict[str, Any]:
205+
def wes_response(postresult: requests.Response) -> Dict[str, Any]:
206+
"""Convert a Response object to JSON text."""
202207
if postresult.status_code != 200:
203208
error = str(json.loads(postresult.text))
204209
logging.error(error)
@@ -208,7 +213,10 @@ def wes_reponse(postresult: requests.Response) -> Dict[str, Any]:
208213

209214

210215
class WESClient:
216+
"""WES client."""
217+
211218
def __init__(self, service: Dict[str, Any]):
219+
"""Initialize the cliet with the provided credentials and endpoint."""
212220
self.auth = service["auth"]
213221
self.proto = service["proto"]
214222
self.host = service["host"]
@@ -230,7 +238,7 @@ def get_service_info(self) -> Dict[str, Any]:
230238
f"{self.proto}://{self.host}/ga4gh/wes/v1/service-info",
231239
headers=self.auth,
232240
)
233-
return wes_reponse(postresult)
241+
return wes_response(postresult)
234242

235243
def list_runs(self) -> Dict[str, Any]:
236244
"""
@@ -247,7 +255,7 @@ def list_runs(self) -> Dict[str, Any]:
247255
postresult = requests.get( # nosec B113
248256
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs", headers=self.auth
249257
)
250-
return wes_reponse(postresult)
258+
return wes_response(postresult)
251259

252260
def run(
253261
self, wf: str, jsonyaml: str, attachments: Optional[List[str]]
@@ -271,7 +279,7 @@ def run(
271279
files=parts,
272280
headers=self.auth,
273281
)
274-
return wes_reponse(postresult)
282+
return wes_response(postresult)
275283

276284
def cancel(self, run_id: str) -> Dict[str, Any]:
277285
"""
@@ -287,7 +295,7 @@ def cancel(self, run_id: str) -> Dict[str, Any]:
287295
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}/cancel",
288296
headers=self.auth,
289297
)
290-
return wes_reponse(postresult)
298+
return wes_response(postresult)
291299

292300
def get_run_log(self, run_id: str) -> Dict[str, Any]:
293301
"""
@@ -303,7 +311,7 @@ def get_run_log(self, run_id: str) -> Dict[str, Any]:
303311
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}",
304312
headers=self.auth,
305313
)
306-
return wes_reponse(postresult)
314+
return wes_response(postresult)
307315

308316
def get_run_status(self, run_id: str) -> Dict[str, Any]:
309317
"""
@@ -319,4 +327,4 @@ def get_run_status(self, run_id: str) -> Dict[str, Any]:
319327
f"{self.proto}://{self.host}/ga4gh/wes/v1/runs/{run_id}/status",
320328
headers=self.auth,
321329
)
322-
return wes_reponse(postresult)
330+
return wes_response(postresult)

wes_client/wes_client_main.py

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

1515

1616
def main(argv: List[str] = sys.argv[1:]) -> int:
17+
"""Run the WES service."""
1718
parser = argparse.ArgumentParser(description="Workflow Execution Service")
1819
parser.add_argument(
1920
"--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 arvados # type: ignore[import-untyped]
24
import arvados.util # type: ignore[import-untyped]
35
import arvados.collection # type: ignore[import-untyped]
@@ -20,7 +22,8 @@ class MissingAuthorization(Exception):
2022
pass
2123

2224

23-
def get_api(authtoken: Optional[str] = None) -> Any:
25+
def get_api(authtoken: Optional[str] = None) -> arvados.api.api:
26+
"""Retrieve an Arvados API object."""
2427
if authtoken is None:
2528
if not connexion.request.headers.get("Authorization"):
2629
raise MissingAuthorization()
@@ -81,7 +84,10 @@ def catch_exceptions_wrapper(self: Any, *args: str, **kwargs: str) -> Any:
8184

8285

8386
class ArvadosBackend(WESBackend):
87+
"""Arvados backend for the WES Service."""
88+
8489
def GetServiceInfo(self) -> Dict[str, Any]:
90+
"""Report metadata about this WES endpoint."""
8591
stdout, stderr = subprocess.Popen( # nosec B603
8692
[shutil.which("arvados-cwl-runner") or "arvados-cwl-runner", "--version"],
8793
stderr=subprocess.PIPE,
@@ -106,6 +112,7 @@ def ListRuns(
106112
page_token: Optional[str] = None,
107113
state_search: Any = None,
108114
) -> Dict[str, Any]:
115+
"""List the known workflow runs."""
109116
api = get_api()
110117

111118
paging = []
@@ -150,6 +157,7 @@ def ListRuns(
150157
def log_for_run(
151158
self, run_id: Optional[str], message: str, authtoken: Optional[str] = None
152159
) -> None:
160+
"""Report the log for a given run."""
153161
get_api(authtoken).logs().create(
154162
body={
155163
"log": {
@@ -169,6 +177,7 @@ def invoke_cwl_runner(
169177
project_uuid: str,
170178
tempdir: str,
171179
) -> None:
180+
"""Submit the workflow using `arvados-cwl-runner`."""
172181
api = arvados.api_from_config(
173182
version="v1",
174183
apiconfig={
@@ -252,6 +261,7 @@ def invoke_cwl_runner(
252261
def RunWorkflow(
253262
self, **args: str
254263
) -> Union[Tuple[Dict[str, Any], int], Dict[str, Any]]:
264+
"""Submit the workflow run request."""
255265
if not connexion.request.headers.get("Authorization"):
256266
raise MissingAuthorization()
257267

@@ -348,6 +358,7 @@ def RunWorkflow(
348358

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

353364
request = api.container_requests().get(uuid=run_id).execute()
@@ -449,6 +460,7 @@ def log_object(cr: Dict[str, Any]) -> Dict[str, Any]:
449460

450461
@catch_exceptions
451462
def CancelRun(self, run_id: str) -> Dict[str, Any]: # NOQA
463+
"""Cancel a submitted run."""
452464
api = get_api()
453465
request = (
454466
api.container_requests().update(uuid=run_id, body={"priority": 0}).execute()
@@ -457,6 +469,7 @@ def CancelRun(self, run_id: str) -> Dict[str, Any]: # NOQA
457469

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

472485

473486
def dynamic_logs(run_id: str, logstream: str) -> str:
487+
"""Retrienve logs, chasing down the container logs as well."""
474488
api = get_api()
475489
cr = api.container_requests().get(uuid=run_id).execute()
476490
l1 = [
@@ -503,6 +517,7 @@ def dynamic_logs(run_id: str, logstream: str) -> str:
503517

504518

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

0 commit comments

Comments
 (0)