def set_reference(self, reference): """Set ourselves to the given reference path.""" reference_path = Path(reference).resolve().absolute() reference_path.relative_to(self.client.path) self.path.parent.mkdir(parents=True, exist_ok=True) os.symlink( os.path.relpath(str(reference_path), start=str(self.path.parent)), str(self.path))
def __attrs_post_init__(self): """Initialize computed attributes.""" #: Configure Renku path. path = Path(self.renku_home) if not path.is_absolute(): path = self.path / path path.relative_to(path) self.renku_path = path #: Create an instance of a Git repository for the given path. try: self.git = GitRepo(str(self.path)) except InvalidGitRepositoryError: self.git = None
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
def __attrs_post_init__(self): """Initialize computed attributes.""" #: Configure Renku path. path = Path(self.renku_home) if not path.is_absolute(): path = self.path / path path.relative_to(path) self.renku_path = path self._subclients = {} super().__attrs_post_init__() # initialize submodules if self.repo: check_output( ['git', 'submodule', 'update', '--init', '--recursive'], cwd=str(self.path))