diff --git a/pyproject.toml b/pyproject.toml index d7e4ff04b3..b13b12fb2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,7 +20,7 @@ [tool.poetry] name = "renku" -version = "1.2.4.dev17+geb9386e8" # placeholder, see poetry-dynamic-versioning +version = "0.0.0" # placeholder, see poetry-dynamic-versioning description = "Python SDK and CLI for the Renku platform." license = "Apache License 2.0" keywords = ["Renku", "CLI"] diff --git a/renku/infrastructure/repository.py b/renku/infrastructure/repository.py index 02e0e2903e..fa5f984a1a 100644 --- a/renku/infrastructure/repository.py +++ b/renku/infrastructure/repository.py @@ -689,17 +689,11 @@ def close(self) -> None: Cleans up dangling processes. """ - if self._repository: - self._repository.close() + if getattr(self, "_repository", None) is not None: + self._repository.close() # type:ignore del self._repository self._repository = None - def refresh_repository(self): - """Refreshes the underlying repository.""" - self.close() - - self._repository = git.Repo(self.path, search_parent_directories=False) - @staticmethod def get_global_user() -> "Actor": """Return the global git user.""" @@ -890,7 +884,7 @@ def __init__(self, parent: git.Repo, name: str, path: Union[Path, str], url: str self._name: str = name self._url: str = url try: - self._repository: git.Repo = _create_repository(path, search_parent_directories=False) + self._repository: Optional[git.Repo] = _create_repository(path, search_parent_directories=False) except errors.GitError: # NOTE: Submodule directory doesn't exist yet, so, we ignore the error pass @@ -908,7 +902,10 @@ def __repr__(self) -> str: return f"" def __del__(self) -> None: - self._repository.close() + if getattr(self, "_repository", None) is not None: + self._repository.close() # type:ignore + del self._repository + self._repository = None @property def name(self) -> str: @@ -930,8 +927,8 @@ class SubmoduleManager: """Manage submodules of a Repository.""" def __init__(self, repository: git.Repo): - self._repository = repository - self._submodule_cache: Dict[git.Submodule, Submodule] = {} # type: ignore + self._repository: Optional[git.Repo] = repository + self._submodule_cache: Dict[str, Submodule] = {} # type: ignore try: self.update() except errors.GitError: @@ -940,12 +937,18 @@ def __init__(self, repository: git.Repo): def _get_submodule(self, submodule: git.Submodule) -> Submodule: # type: ignore """Get a submodule from local cache.""" - if submodule not in self._submodule_cache: + if self._repository is None: + raise errors.ParameterError("Repository not set.") + + if submodule.name not in self._submodule_cache: submodule_result = Submodule.from_submodule(self._repository, submodule) - self._submodule_cache[submodule] = submodule_result - return self._submodule_cache[submodule] + self._submodule_cache[submodule.name] = submodule_result + return self._submodule_cache[submodule.name] def __getitem__(self, name: str) -> Submodule: + if self._repository is None: + raise errors.ParameterError("Repository not set.") + try: submodule = self._repository.submodules[name] except IndexError: @@ -954,11 +957,17 @@ def __getitem__(self, name: str) -> Submodule: return self._get_submodule(submodule) def __iter__(self): + if self._repository is None: + raise errors.ParameterError("Repository not set.") + for s in self._repository.submodules: yield self._get_submodule(s) def __len__(self) -> int: + if self._repository is None: + raise errors.ParameterError("Repository not set.") + return len(self._repository.submodules) def __repr__(self) -> str: @@ -966,16 +975,27 @@ def __repr__(self) -> str: def remove(self, submodule: Union[Submodule, str], force: bool = False): """Remove an existing submodule.""" + if self._repository is None: + raise errors.ParameterError("Repository not set.") + name = submodule if isinstance(submodule, str) else submodule.name try: - submodule = self._repository.submodules[name] - submodule.remove(force=force) + git_submodule = self._repository.submodules[name] + git_submodule.remove(force=force) + + if name in self._submodule_cache: + submodule = self._submodule_cache[name] + del self._submodule_cache[name] + submodule.close() except git.GitError as e: raise errors.GitError(f"Cannot delete submodule '{submodule}'") from e def update(self, initialize: bool = True): """Update all submodule.""" + if self._repository is None: + raise errors.ParameterError("Repository not set.") + # NOTE: Git complains if ``--init`` comes before ``update`` args = ("update", "--init") if initialize else ("update",) _run_git_command(self._repository, "submodule", *args) diff --git a/renku/version.py b/renku/version.py index a603d328d2..5190e7c179 100644 --- a/renku/version.py +++ b/renku/version.py @@ -24,7 +24,7 @@ except ImportError: from importlib_metadata import distribution -__version__ = "1.2.4.dev17+geb9386e8" +__version__ = "0.0.0" __template_version__ = "0.3.1" __minimum_project_version__ = "1.2.0"