def create_project_config_path( path, mode=0o777, parents=False, exist_ok=False ): """Create new project configuration folder.""" # FIXME check default directory mode project_path = Path(path).absolute().joinpath(RENKU_HOME) project_path.mkdir(mode=mode, parents=parents, exist_ok=exist_ok) return str(project_path)
def _cache(cls, app_name): """Return cache file.""" from renku._compat import Path from appdirs import user_cache_dir cache_dir = Path(user_cache_dir(app_name, None)) cache_dir.mkdir(parents=True, exist_ok=True) return cache_dir / cls.STATE_NAME
def worktree( self, path=None, branch_name=None, commit=None, merge_args=('--ff-only', ), ): """Create new worktree.""" from git import GitCommandError, NULL_TREE from renku._contexts import Isolation delete = path is None path = path or tempfile.mkdtemp() branch_name = branch_name or 'renku/run/isolation/' + uuid.uuid4().hex # TODO sys.argv if commit is NULL_TREE: args = ['add', '--detach', path] self.repo.git.worktree(*args) client = attr.evolve(self, path=path) client.repo.git.checkout('--orphan', branch_name) client.repo.git.rm('-rf', '*') else: args = ['add', '-b', branch_name, path] if commit: args.append(commit) self.repo.git.worktree(*args) client = attr.evolve(self, path=path) client.repo.config_reader = self.repo.config_reader # Keep current directory relative to repository root. relative = Path('.').resolve().relative_to(self.path) # Reroute standard streams original_mapped_std = _mapped_std_streams(self.candidate_paths) mapped_std = {} for name, stream in original_mapped_std.items(): stream_path = Path(path) / (Path(stream).relative_to(self.path)) stream_path = stream_path.absolute() if not stream_path.exists(): stream_path.parent.mkdir(parents=True, exist_ok=True) stream_path.touch() mapped_std[name] = stream_path _clean_streams(self.repo, original_mapped_std) new_cwd = Path(path) / relative new_cwd.mkdir(parents=True, exist_ok=True) with Isolation(cwd=str(new_cwd), **mapped_std): yield client try: self.repo.git.merge(branch_name, *merge_args) except GitCommandError: raise errors.FailedMerge(self.repo) if delete: shutil.rmtree(path) self.repo.git.worktree('prune') self.checkout_paths_from_storage()