refactor(self-mgmt): centralize manual file list for install/uninstall
This commit is contained in:
@@ -2,6 +2,9 @@ ROOT_DIR := $(shell pwd)
|
|||||||
COMP_DIR := $(HOME)/.local/bin/completions
|
COMP_DIR := $(HOME)/.local/bin/completions
|
||||||
PYTHON ?= python3
|
PYTHON ?= python3
|
||||||
|
|
||||||
|
# 手动安装的文件清单(与 bin/commands/self_mgmt.py 中的 _MANUAL_FILES 保持同步)
|
||||||
|
MANUAL_FILES := $(COMP_DIR)/_mytoolkit $(COMP_DIR)/mytoolkit.bash
|
||||||
|
|
||||||
.PHONY: help install uninstall
|
.PHONY: help install uninstall
|
||||||
|
|
||||||
help:
|
help:
|
||||||
@@ -27,5 +30,10 @@ install:
|
|||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
$(PYTHON) -m pip uninstall mytoolkit -y
|
$(PYTHON) -m pip uninstall mytoolkit -y
|
||||||
rm -f "$(COMP_DIR)/_mytoolkit" "$(COMP_DIR)/mytoolkit.bash"
|
@for f in $(MANUAL_FILES); do \
|
||||||
@echo "Uninstalled mytoolkit and removed completions"
|
if [ -e "$$f" ] || [ -L "$$f" ]; then \
|
||||||
|
rm -f "$$f"; \
|
||||||
|
echo "Removed $$f"; \
|
||||||
|
fi; \
|
||||||
|
done
|
||||||
|
@echo "Uninstalled mytoolkit and cleaned up manual files"
|
||||||
|
|||||||
@@ -9,6 +9,15 @@ from pathlib import Path
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
|
|
||||||
|
# 手动安装的文件清单(pip 管理范围外,uninstall 时需要额外清理)
|
||||||
|
_MANUAL_FILES: dict[str, list[Path]] = {
|
||||||
|
"completions": [
|
||||||
|
Path.home() / ".local" / "bin" / "completions" / "_mytoolkit",
|
||||||
|
Path.home() / ".local" / "bin" / "completions" / "mytoolkit.bash",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _get_project_root() -> Path:
|
def _get_project_root() -> Path:
|
||||||
"""Get mytoolkit project root from source tree."""
|
"""Get mytoolkit project root from source tree."""
|
||||||
return Path(__file__).parent.parent.parent
|
return Path(__file__).parent.parent.parent
|
||||||
@@ -78,11 +87,15 @@ def _uninstall() -> None:
|
|||||||
check=False,
|
check=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
comp_dir = Path.home() / ".local" / "bin" / "completions"
|
removed = 0
|
||||||
for f in (comp_dir / "_mytoolkit", comp_dir / "mytoolkit.bash"):
|
for paths in _MANUAL_FILES.values():
|
||||||
if f.exists() or f.is_symlink():
|
for f in paths:
|
||||||
f.unlink()
|
if f.exists() or f.is_symlink():
|
||||||
click.secho(f"Removed {f}", fg="green")
|
f.unlink()
|
||||||
|
click.secho(f"Removed {f}", fg="green")
|
||||||
|
removed += 1
|
||||||
|
if removed == 0:
|
||||||
|
click.secho("No manual files to clean up.", fg="cyan")
|
||||||
|
|
||||||
|
|
||||||
@click.command(name="update")
|
@click.command(name="update")
|
||||||
|
|||||||
Reference in New Issue
Block a user