Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
INDIRECT_INPUTS_LIST = os.path.join(RENKU_FILELIST_PATH, 'inputs.txt')
INDIRECT_OUTPUTS_LIST = os.path.join(RENKU_FILELIST_PATH, 'outputs.txt')
def convert_arguments(value):
"""Convert arguments from various input formats."""
if isinstance(value, (list, tuple)):
return [
CommandLineBinding(**item) if isinstance(item, dict) else item
for item in value
]
return shlex.split(value)
@attr.s
class CommandLineTool(Process, CWLClass):
"""Represent a command line tool."""
STD_STREAMS_REPR = {
'stdin': '<',
'stdout': '>',
'stderr': '2>',
}
"""Format streams for a shell command representation."""
# specialize inputs and outputs with Command{Input,Output}Parameter
baseCommand = attr.ib(
default='',
validator=lambda self, attr, cmd: bool(cmd),
) # str or list(str) -> shutil.split()
arguments = attr.ib(
from pathlib import Path
import attr
from ..datastructures import DirectoryTree
from .ascwl import CWLClass
from .types import DIRECTORY_EXPRESSION, PATH_OBJECTS, Dirent
class ProcessRequirement(object):
"""Declare a prerequisite that may or must be fulfilled."""
@attr.s
class InlineJavascriptRequirement(CWLClass):
"""Indicate that runner must support inline Javascript expressions."""
@attr.s
class InitialWorkDirRequirement(ProcessRequirement, CWLClass):
"""Define a list of files and subdirectories that must be created."""
listing = attr.ib(default=attr.Factory(list)) # File, Directory
@classmethod
def from_tool(cls, tool, existing_directories=None, working_dir=''):
"""Create a directory structure based on tool inputs and outputs."""
directories = DirectoryTree()
inputs = {input_.id: input_ for input_ in tool.inputs}
converters = {
kk,
dict_factory=df,
basedir=basedir,
) if has(kk.__class__) else convert_value(kk),
ascwl(
vv,
dict_factory=df,
basedir=basedir,
) if has(vv.__class__) else vv
) for kk, vv in iteritems(v))
else:
rv[a_name] = convert_value(v)
else:
rv[a_name] = convert_value(v)
if isinstance(inst, CWLClass):
rv['class'] = inst.__class__.__name__
return rv
if reference:
return str(os.path.normpath(str(reference.parent / self.path)))
return os.path.relpath(
os.path.realpath(str(self.path)), os.path.realpath(os.getcwd())
)
@attr.s
class File(CWLClass, PathFormatterMixin):
"""Represent a file."""
path = attr.ib(converter=Path)
@attr.s
class Directory(CWLClass, PathFormatterMixin):
"""Represent a directory."""
# TODO add validation to allow only directories
path = attr.ib(default=None)
listing = attr.ib(default=attr.Factory(list))
DIRECTORY_EXPRESSION = '$({0})'.format(
json.dumps(ascwl(Directory(), filter=lambda _, x: x is not None))
)
PATH_OBJECTS = {'File', 'Directory'}
PATH_TYPES = (File, Directory)
@attr.s
class Dirent(object):
def _load(step):
"""Load step definition."""
if isinstance(step.run, WORKFLOW_STEP_RUN_TYPES):
return step.run
if self.commit:
import yaml
data = (self.commit.tree / basedir /
step.run).data_stream.read()
return CWLClass.from_cwl(yaml.safe_load(data))
return CWLClass.from_yaml(step.run)