Пример #1
0
    def subclients(self, parent_commit):
        """Return mapping from submodule to client."""
        if parent_commit in self._subclients:
            return self._subclients[parent_commit]

        try:
            from git import Submodule

            submodules = [
                submodule for submodule in Submodule.iter_items(
                    self.repo, parent_commit=parent_commit)
            ]
        except (RuntimeError, ValueError):
            # There are no submodules associated with the given commit.
            submodules = []

        subclients = {}
        for submodule in submodules:
            subpath = (self.path / submodule.path).resolve()
            is_renku = subpath / Path(self.renku_home)

            if subpath.exists() and is_renku.exists():
                subclients[submodule] = self.__class__(
                    path=subpath,
                    parent=(self, submodule),
                )

        return subclients
Пример #2
0
    def add_file(self, path, revision='HEAD'):
        """Add a file node to the graph."""
        file_commits = list(self.client.git.iter_commits(revision, paths=path))

        if not file_commits:
            raise KeyError('Could not find a file {0} in range {1}'.format(
                path, revision))

        commit = file_commits[0]

        cwl = self.find_cwl(commit)
        if cwl is not None:
            file_key = self.add_node(commit, path)
            self.add_tool(commit, cwl, file_key=file_key)
            return file_key
        else:
            #: Does not have a parent CWL.
            root_node = self.add_node(commit, path)
            parent_commit, parent_path = root_node

            #: Capture information about the submodule in a submodule.
            root_submodule = self.G.nodes[root_node].get('submodule', [])

            #: Resolve Renku based submodules.
            original_path = Path(parent_path)
            if original_path.is_symlink() or str(original_path).startswith(
                    '.renku/vendors'):
                original_path = original_path.resolve()

                for submodule in Submodule.iter_items(
                        self.client.git, parent_commit=parent_commit):
                    try:
                        subpath = original_path.relative_to(
                            Path(submodule.path).resolve())
                        subgraph = Graph(client=LocalClient(
                            path=submodule.path))
                        subnode = subgraph.add_file(str(subpath),
                                                    revision=submodule.hexsha)

                        #: Extend node metadata.
                        for _, data in subgraph.G.nodes(data=True):
                            data['submodule'] = root_submodule + [
                                submodule.name
                            ]

                        #: Merge file node with it's symlinked version.
                        self.G = nx.contracted_nodes(
                            nx.compose(self.G, subgraph.G),
                            root_node,
                            subnode,
                        )  # TODO optionally it can be changed to an edge.
                        break
                    except ValueError:
                        continue

            return root_node
Пример #3
0
    def subclients(self, parent_commit):
        """Return mapping from submodule to client."""
        if parent_commit in self._subclients:
            return self._subclients[parent_commit]

        try:
            from git import Submodule

            submodules = [
                submodule for submodule in Submodule.iter_items(
                    self.repo, parent_commit=parent_commit)
            ]
        except (RuntimeError, ValueError):
            # There are no submodules assiciated with the given commit.
            submodules = []

        return self._subclients.setdefault(
            parent_commit, {
                submodule: self.__class__(
                    path=(self.path / submodule.path).resolve(),
                    parent=(self, submodule),
                )
                for submodule in submodules
            })
Пример #4
0
    def default_inputs(self):
        """Guess default inputs from a process."""
        basedir = os.path.dirname(self.path)
        commit = self.commit
        client = self.client
        process = self.process
        hierarchy = self.submodules

        inputs = {}
        revision = '{0}^'.format(commit)

        try:
            from git import Submodule

            submodules = [
                submodule
                for submodule in Submodule.iter_items(client.git,
                                                      parent_commit=commit)
            ]
        except (RuntimeError, ValueError):
            # There are no submodules assiciated with the given commit.
            submodules = []

        subclients = {
            submodule: LocalClient(
                path=(client.path / submodule.path).resolve(),
                parent=client,
            )
            for submodule in submodules
        }

        def resolve_submodules(file_, **kwargs):
            original_path = client.path / file_
            if original_path.is_symlink() or file_.startswith(
                    '.renku/vendors'):
                original_path = original_path.resolve()
                for submodule, subclient in subclients.items():
                    try:
                        subpath = original_path.relative_to(subclient.path)
                        return Usage.from_revision(client=subclient,
                                                   path=str(subpath),
                                                   revision=submodule.hexsha,
                                                   submodules=hierarchy +
                                                   [submodule.name],
                                                   **kwargs)
                    except ValueError:
                        pass

        for input_id, input_path in process.iter_input_files(basedir):
            try:
                usage_id = self._id + '/inputs/' + input_id
                dependency = resolve_submodules(
                    input_path,
                    role=input_id,
                    id=usage_id,
                )
                if dependency is None:
                    dependency = Usage.from_revision(
                        client=client,
                        path=input_path,
                        role=input_id,
                        revision=revision,
                        id=usage_id,
                    )
                inputs[input_path] = dependency
            except KeyError:
                continue

        return inputs