diff --git a/terrarium/dl_repmanager/dl_repmanager/fs_editor.py b/terrarium/dl_repmanager/dl_repmanager/fs_editor.py index 5f2700f60..67407c206 100644 --- a/terrarium/dl_repmanager/dl_repmanager/fs_editor.py +++ b/terrarium/dl_repmanager/dl_repmanager/fs_editor.py @@ -241,7 +241,7 @@ def _move_path(self, old_path: Path, new_path: Path) -> None: subprocess.run(f'git add "{rel_old_path}" && git mv "{rel_old_path}" "{rel_new_path}"', shell=True) def _remove_path(self, path: Path) -> None: - result = subprocess.run(f'git rm "{path}"', shell=True) + result = subprocess.run(f'git rm -r "{path}"', shell=True) if result.returncode != 0: super()._remove_path(path) diff --git a/terrarium/dl_repmanager/dl_repmanager/management_plugins.py b/terrarium/dl_repmanager/dl_repmanager/management_plugins.py index 96e8d5f4b..8bb26f1fa 100644 --- a/terrarium/dl_repmanager/dl_repmanager/management_plugins.py +++ b/terrarium/dl_repmanager/dl_repmanager/management_plugins.py @@ -193,7 +193,20 @@ def register_package(self, package_info: PackageInfo) -> None: pass def unregister_package(self, package_info: PackageInfo) -> None: - pass # FIXME: Remove package from dependencies + package_meta_io_factory = PackageMetaIOFactory(fs_editor=self.fs_editor) + + # Scan other packages to see if they are dependent on this one and update these dependency entries + for other_package_info in self.package_index.list_package_infos(): + if other_package_info == package_info: + continue + + for section_name in other_package_info.requirement_lists: + if other_package_info.is_dependent_on(package_info, section_name=section_name): + with package_meta_io_factory.package_meta_writer(other_package_info.toml_path) as pkg_meta_writer: + pkg_meta_writer.remove_requirement_item( + section_name=section_name, + item_name=package_info.package_reg_name, + ) def re_register_package(self, old_package_info: PackageInfo, new_package_info: PackageInfo) -> None: package_meta_io_factory = PackageMetaIOFactory(fs_editor=self.fs_editor) diff --git a/terrarium/dl_repmanager/dl_repmanager/repository_manager.py b/terrarium/dl_repmanager/dl_repmanager/repository_manager.py index ea30226b1..3e085d470 100644 --- a/terrarium/dl_repmanager/dl_repmanager/repository_manager.py +++ b/terrarium/dl_repmanager/dl_repmanager/repository_manager.py @@ -111,7 +111,7 @@ def _register_package(self, package_info: PackageInfo) -> None: def _unregister_package(self, package_info: PackageInfo) -> None: for mng_plugin in self.repository_env.get_plugins(package_index=self.package_index): - mng_plugin.register_package(package_info=package_info) + mng_plugin.unregister_package(package_info=package_info) def _re_register_package(self, old_package_info: PackageInfo, new_package_info: PackageInfo) -> None: for mng_plugin in self.repository_env.get_plugins(package_index=self.package_index): diff --git a/terrarium/dl_repmanager/dl_repmanager/scripts/repmanager_cli.py b/terrarium/dl_repmanager/dl_repmanager/scripts/repmanager_cli.py index 84fe5d959..81bb8b725 100644 --- a/terrarium/dl_repmanager/dl_repmanager/scripts/repmanager_cli.py +++ b/terrarium/dl_repmanager/dl_repmanager/scripts/repmanager_cli.py @@ -120,6 +120,12 @@ def make_parser() -> argparse.ArgumentParser: help="New name of the package", ) + subparsers.add_parser( + "rm", + parents=[package_name_parser], + help="Remove package", + ) + move_code_parser = subparsers.add_parser( "rename-module", parents=[old_new_import_names_parser], @@ -269,6 +275,9 @@ def rename(self, package_name: str, new_package_name: str) -> None: def ch_package_type(self, package_name: str, package_type: str) -> None: self.repository_manager.change_package_type(package_module_name=package_name, new_package_type=package_type) + def rm(self, package_name: str) -> None: + self.repository_manager.remove_package(package_module_name=package_name) + def package_list(self, package_type: str, mask: str, base_path: Path) -> None: for package_info in self.package_index.list_package_infos(package_type=package_type): printable_values = dict( @@ -459,6 +468,8 @@ def run_parsed_args(cls, args: argparse.Namespace) -> None: tool.rename(package_name=args.package_name, new_package_name=args.new_package_name) case "ch-package-type": tool.ch_package_type(package_name=args.package_name, package_type=args.package_type) + case "rm": + tool.rm(package_name=args.package_name) case "package-list": tool.package_list(package_type=args.package_type, mask=args.mask, base_path=Path(args.base_path)) case "rename-module":