Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
or path.startswith(builder.outdir + os.sep)
or path.startswith(builder.outdir + "/")
):
f["location"] = builder.fs_access.join(
outdir, path[len(builder.outdir) + 1 :]
)
elif not os.path.isabs(path):
f["location"] = builder.fs_access.join(outdir, path)
else:
raise WorkflowException(
"Output file path %s must be within designated output directory (%s) or an input "
"file pass through." % (path, builder.outdir)
)
return f
raise WorkflowException(
"Output File object is missing both 'location' " "and 'path' fields: %s" % f
)
def get_from_requirements(self, r, req, pull_image, dry_run=False, force_pull=False):
# type: (Dict[Text, Text], bool, bool, bool, bool) -> Text
if r:
errmsg = None
try:
subprocess.check_output(["docker", "version"])
except subprocess.CalledProcessError as e:
errmsg = "Cannot communicate with docker daemon: " + Text(e)
except OSError as e:
errmsg = "'docker' executable not found: " + Text(e)
if errmsg:
if req:
raise WorkflowException(errmsg)
else:
return None
if self.get_image(r, pull_image, dry_run, force_pull=force_pull):
return r["dockerImageId"]
else:
if req:
raise WorkflowException(u"Docker image %s not found" % r["dockerImageId"])
return None
"can set the cwlVersion to v1.1"
)
job_reqs = cast(
List[CWLObjectType],
job_order_object["https://w3id.org/cwl/cwl#requirements"],
)
elif (
"cwl:defaults" in process.metadata
and "https://w3id.org/cwl/cwl#requirements"
in cast(CWLObjectType, process.metadata["cwl:defaults"])
):
if (
process.metadata.get("http://commonwl.org/cwltool#original_cwlVersion")
== "v1.0"
):
raise WorkflowException(
"`cwl:requirements` in the input object is not part of CWL "
"v1.0. You can adjust to use `cwltool:overrides` instead; or you "
"can set the cwlVersion to v1.1"
)
job_reqs = cast(
Optional[List[CWLObjectType]],
cast(CWLObjectType, process.metadata["cwl:defaults"])[
"https://w3id.org/cwl/cwl#requirements"
],
)
if job_reqs is not None:
for req in job_reqs:
process.requirements.append(req)
self.run_jobs(process, job_order_object, logger, runtime_context)
def fill_in_defaults(
inputs: List[CWLObjectType], job: CWLObjectType, fsaccess: StdFsAccess,
) -> None:
for e, inp in enumerate(inputs):
with SourceLine(
inputs, e, WorkflowException, _logger.isEnabledFor(logging.DEBUG)
):
fieldname = shortname(cast(str, inp["id"]))
if job.get(fieldname) is not None:
pass
elif job.get(fieldname) is None and "default" in inp:
job[fieldname] = copy.deepcopy(inp["default"])
elif job.get(fieldname) is None and "null" in aslist(inp["type"]):
job[fieldname] = None
else:
raise WorkflowException(
"Missing required input parameter '%s'"
% shortname(cast(str, inp["id"]))
)
js_console: bool = False,
) -> Optional[CWLOutputType]:
match = param_re.match(ex)
expression_parse_exception = None
expression_parse_succeeded = False
if match is not None:
first_symbol = match.group(1)
first_symbol_end = match.end(1)
if first_symbol_end + 1 == len(ex) and first_symbol == "null":
return None
try:
if obj.get(first_symbol) is None:
raise WorkflowException("%s is not defined" % first_symbol)
return next_seg(
first_symbol,
ex[first_symbol_end:-1],
cast(CWLOutputType, obj[first_symbol]),
)
except WorkflowException as werr:
expression_parse_exception = werr
else:
expression_parse_succeeded = True
if fullJS and not expression_parse_succeeded:
return execjs(
ex,
jslib,
timeout,
def register_reader(self, stepname, obj):
# type: (str, Dict[str, Any]) -> None
loc = obj["location"]
current = self.generations.get(loc, MutationState(0, [], ""))
obj_generation = obj.get(_generation, 0)
if obj_generation != current.generation:
raise WorkflowException(
"[job {}] wants to read {} from generation {} but current "
"generation is {}(last updated by {})".format(
stepname, loc, obj_generation, current.generation, current.stepname
)
)
current.readers.append(stepname)
self.generations[loc] = current
def eval_resource(
builder: Builder, resource_req: Union[str, int, float]
) -> Optional[Union[str, int, float]]:
if isinstance(resource_req, str) and expression.needs_parsing(resource_req):
result = builder.do_eval(resource_req)
if isinstance(result, (str, int)) or result is None:
return result
raise WorkflowException(
"Got incorrect return type {} from resource expression evaluation of {}.".format(
type(result), resource_req
)
)
return resource_req
def fill_in_defaults(
inputs: List[CWLObjectType], job: CWLObjectType, fsaccess: StdFsAccess,
) -> None:
for e, inp in enumerate(inputs):
with SourceLine(
inputs, e, WorkflowException, _logger.isEnabledFor(logging.DEBUG)
):
fieldname = shortname(cast(str, inp["id"]))
if job.get(fieldname) is not None:
pass
elif job.get(fieldname) is None and "default" in inp:
job[fieldname] = copy.deepcopy(inp["default"])
elif job.get(fieldname) is None and "null" in aslist(inp["type"]):
job[fieldname] = None
else:
raise WorkflowException(
"Missing required input parameter '%s'"
% shortname(cast(str, inp["id"]))
)
single = True
elif schema["type"] == "File" or schema["type"] == "Directory":
single = True
if "outputEval" in binding:
with SourceLine(binding, "outputEval", WorkflowException, debug):
result = builder.do_eval(
cast(CWLOutputType, binding["outputEval"]), context=r
)
else:
result = cast(CWLOutputType, r)
if single:
if not result and not optional:
with SourceLine(binding, "glob", WorkflowException, debug):
raise WorkflowException(
"Did not find output file with glob pattern: '{}'".format(
globpatterns
)
)
elif not result and optional:
pass
elif isinstance(result, MutableSequence):
if len(result) > 1:
raise WorkflowException(
"Multiple matches for output item that is a single file."
)
else:
result = cast(CWLOutputType, result[0])
if "secondaryFiles" in schema:
with SourceLine(schema, "secondaryFiles", WorkflowException, debug):
# img_entity = document.entity("nih:sha-256;%s" % img_id,
# {"prov:label": "Container image %s" % img_id} )
# The image is the plan for this activity-agent association
# document.wasAssociatedWith(process_run_ID, container_agent, img_entity)
self.prov_obj.document.wasAssociatedWith(
runtimeContext.process_run_id, container_agent
)
except Exception as err:
container = "Singularity" if runtimeContext.singularity else "Docker"
_logger.debug("%s error", container, exc_info=True)
if docker_is_req:
raise UnsupportedRequirement(
"%s is required to run this tool: %s" % (container, str(err))
) from err
else:
raise WorkflowException(
"{0} is not available for this tool, try "
"--no-container to disable {0}, or install "
"a user space Docker replacement like uDocker with "
"--user-space-docker-cmd.: {1}".format(container, err)
)
self._setup(runtimeContext)
(runtime, cidfile) = self.create_runtime(env, runtimeContext)
runtime.append(str(img_id))
monitor_function = None
if cidfile:
monitor_function = functools.partial(
self.docker_monitor,
cidfile,
runtimeContext.tmpdir_prefix,
not bool(runtimeContext.cidfile_dir),