Ejemplo n.º 1
0
 def __init__(self, tool_requirements=None):
     if tool_requirements:
         if not isinstance(tool_requirements, list):
             raise ToolRequirementsException('ToolRequirements Constructor expects a list')
         self.tool_requirements = OrderedSet([r if isinstance(r, ToolRequirement) else ToolRequirement.from_dict(r) for r in tool_requirements])
     else:
         self.tool_requirements = OrderedSet()
Ejemplo n.º 2
0
 def __init__(self, tool_requirements=None):
     if tool_requirements:
         if not isinstance(tool_requirements, list):
             raise ToolRequirementsException('ToolRequirements Constructor expects a list')
         self.tool_requirements = OrderedSet([r if isinstance(r, ToolRequirement) else ToolRequirement.from_dict(r) for r in tool_requirements])
     else:
         self.tool_requirements = OrderedSet()
Ejemplo n.º 3
0
class ToolRequirements(object):
    """
    Represents all requirements (packages, env vars) needed to run a tool.
    """
    def __init__(self, tool_requirements=None):
        if tool_requirements:
            if not isinstance(tool_requirements, list):
                raise ToolRequirementsException(
                    'ToolRequirements Constructor expects a list')
            self.tool_requirements = OrderedSet([
                r if isinstance(r, ToolRequirement) else
                ToolRequirement.from_dict(r) for r in tool_requirements
            ])
        else:
            self.tool_requirements = OrderedSet()

    @staticmethod
    def from_list(requirements):
        return ToolRequirements(requirements)

    @property
    def resolvable(self):
        return ToolRequirements([
            r for r in self.tool_requirements
            if r.type in {'package', 'set_environment'}
        ])

    @property
    def packages(self):
        return ToolRequirements(
            [r for r in self.tool_requirements if r.type == 'package'])

    def to_list(self):
        return [r.to_dict() for r in self.tool_requirements]

    def append(self, requirement):
        if not isinstance(requirement, ToolRequirement):
            requirement = ToolRequirement.from_dict(requirement)
        self.tool_requirements.add(requirement)

    def __eq__(self, other):
        return len(self.tool_requirements & other.tool_requirements) == len(
            self.tool_requirements) == len(other.tool_requirements)

    def __ne__(self, other):
        return not self.__eq__(other)

    def __iter__(self):
        for r in self.tool_requirements:
            yield r

    def __getitem__(self, ii):
        return list(self.tool_requirements)[ii]

    def __len__(self):
        return len(self.tool_requirements)

    def __hash__(self):
        return sum([r.__hash__() for r in self.tool_requirements])
Ejemplo n.º 4
0
class ToolRequirements(object):
    """
    Represents all requirements (packages, env vars) needed to run a tool.
    """

    def __init__(self, tool_requirements=None):
        if tool_requirements:
            if not isinstance(tool_requirements, list):
                raise ToolRequirementsException('ToolRequirements Constructor expects a list')
            self.tool_requirements = OrderedSet([r if isinstance(r, ToolRequirement) else ToolRequirement.from_dict(r) for r in tool_requirements])
        else:
            self.tool_requirements = OrderedSet()

    @staticmethod
    def from_list(requirements):
        return ToolRequirements(requirements)

    @property
    def resolvable(self):
        return ToolRequirements([r for r in self.tool_requirements if r.type in {'package', 'set_environment'}])

    @property
    def packages(self):
        return ToolRequirements([r for r in self.tool_requirements if r.type == 'package'])

    def to_list(self):
        return [r.to_dict() for r in self.tool_requirements]

    def append(self, requirement):
        if not isinstance(requirement, ToolRequirement):
            requirement = ToolRequirement.from_dict(requirement)
        self.tool_requirements.add(requirement)

    def __eq__(self, other):
        return len(self.tool_requirements & other.tool_requirements) == len(self.tool_requirements) == len(other.tool_requirements)

    def __ne__(self, other):
        return not self.__eq__(other)

    def __iter__(self):
        for r in self.tool_requirements:
            yield r

    def __getitem__(self, ii):
        return list(self.tool_requirements)[ii]

    def __len__(self):
        return len(self.tool_requirements)

    def __hash__(self):
        return sum([r.__hash__() for r in self.tool_requirements])
Ejemplo n.º 5
0
 def dependency_shell_commands(self, requirements, **kwds):
     requirements_to_dependencies = self.requirements_to_dependencies(
         requirements, **kwds)
     ordered_dependencies = OrderedSet(
         requirements_to_dependencies.values())
     return [
         dependency.shell_commands() for dependency in ordered_dependencies
     ]
Ejemplo n.º 6
0
 def dependency_shell_commands(self, requirements, **kwds):
     requirements_to_dependencies = self.requirements_to_dependencies(
         requirements, **kwds)
     ordered_dependencies = OrderedSet(
         requirements_to_dependencies.values())
     return [
         dependency.shell_commands() for dependency in ordered_dependencies
         if not isinstance(dependency, ContainerDependency)
     ]
Ejemplo n.º 7
0
def set_collection_elements(dataset_collection, type, dataset_instances,
                            associated_identifiers):
    new_element_keys = OrderedSet(
        dataset_instances.keys()) - associated_identifiers
    new_dataset_instances = {k: dataset_instances[k] for k in new_element_keys}
    dataset_collection.element_count = dataset_collection.element_count or 0
    element_index = dataset_collection.element_count
    elements = []
    for element in type.generate_elements(new_dataset_instances):
        element.element_index = element_index
        element.collection = dataset_collection
        elements.append(element)

        element_index += 1
        associated_identifiers.add(element.element_identifier)

    dataset_collection.element_count = element_index
    return dataset_collection