Skip to content

Commit

Permalink
Added rm command to repmanager (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
altvod authored Nov 15, 2023
1 parent e5d555d commit 067be29
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion terrarium/dl_repmanager/dl_repmanager/fs_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 14 additions & 1 deletion terrarium/dl_repmanager/dl_repmanager/management_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions terrarium/dl_repmanager/dl_repmanager/scripts/repmanager_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit 067be29

Please sign in to comment.