Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

17054 custom name #1477

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cwltool/extensions-v1.1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,22 @@ $graph:
The number of MPI processes to start. If you give a string,
this will be evaluated as a CWL Expression and it must
evaluate to an integer.

- name: JobName
type: record
inVocab: false
extends: cwl:ProcessRequirement
doc: |
Provide a string or expression for naming the runtime workflow step in logs or user interface.
fields:
- name: class
type: string
doc: "Always 'JobName'"
jsonldPredicate:
"_id": "@type"
"_type": "@vocab"
- name: jobname
type: [string, cwl:Expression]
doc: |
A string or expression returning a string with the preferred name for the job.
If it is an expression, it is evaluated after the input object has been completely determined.
2 changes: 2 additions & 0 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,12 +664,14 @@ def setup_schema(
use_custom_schema("v1.2.0-dev1", "http://commonwl.org/cwltool", ext11)
use_custom_schema("v1.2.0-dev2", "http://commonwl.org/cwltool", ext11)
use_custom_schema("v1.2.0-dev3", "http://commonwl.org/cwltool", ext11)
use_custom_schema("v1.2", "http://commonwl.org/cwltool", ext11)
else:
use_standard_schema("v1.0")
use_standard_schema("v1.1")
use_standard_schema("v1.2.0-dev1")
use_standard_schema("v1.2.0-dev2")
use_standard_schema("v1.2.0-dev3")
use_standard_schema("v1.2")


class ProvLogFormatter(logging.Formatter):
Expand Down
1 change: 1 addition & 0 deletions cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def filter(self, record: logging.LogRecord) -> bool:
"http://commonwl.org/cwltool#NetworkAccess",
"http://commonwl.org/cwltool#LoadListingRequirement",
"http://commonwl.org/cwltool#InplaceUpdateRequirement",
"http://commonwl.org/cwltool#StepName",
]

cwl_files = (
Expand Down
12 changes: 11 additions & 1 deletion cwltool/workflow_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ def job(
) -> JobsGeneratorType:
runtimeContext = runtimeContext.copy()
runtimeContext.part_of = self.name
runtimeContext.name = shortname(self.id)

jobnameReq, is_required = self.step.get_requirement(
"http://commonwl.org/cwltool#JobName"
)
if jobnameReq is not None:
vfinputs = {shortname(k): v for k, v in joborder.items()}
runtimeContext.name = expression.do_eval(
jobnameReq["jobname"], vfinputs, self.step.requirements, None, None, {}
)
else:
runtimeContext.name = shortname(self.id)

_logger.info("[%s] start", self.name)

Expand Down
9 changes: 9 additions & 0 deletions tests/echo_no_output.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env cwl-runner
cwlVersion: v1.1
class: CommandLineTool
inputs:
text:
type: string
inputBinding: {}
outputs: []
baseCommand: echo
26 changes: 26 additions & 0 deletions tests/scatter-echo-wf.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env cwl-runner
$namespaces:
cwltool: "http://commonwl.org/cwltool#"
cwlVersion: v1.1
class: Workflow
requirements:
ScatterFeatureRequirement: {}
InlineJavascriptRequirement: {}
StepInputExpressionRequirement: {}

inputs:
texts:
type: string[]

outputs: []

steps:
echo:
run: echo_no_output.cwl
scatter: text
hints:
cwltool:JobName:
jobname: $("test_" + inputs.text.split('.')[0])
in:
text: texts
out: []
1 change: 1 addition & 0 deletions tests/scatter-echo-wf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
texts: ["a.vcf", "b.vcf", "c.vcf"]
20 changes: 20 additions & 0 deletions tests/test_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,23 @@ def test_warn_large_inputs() -> None:
)
finally:
cwltool.process.FILE_COUNT_WARNING = was


def test_jobname() -> None:
"""Test JobName requirement."""
stream = StringIO()

main(
[
"--enable-ext",
get_data("tests/scatter-echo-wf.cwl"),
get_data("tests/scatter-echo-wf.yml"),
],
stderr=stream,
)

assert (
"test_a" in stream.getvalue()
and "test_b" in stream.getvalue()
and "test_c" in stream.getvalue()
)