From 1209a0b3faf945d90edf9e58889c331218bc71d2 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Sun, 4 Jun 2023 18:07:43 +0800 Subject: [PATCH] fix: add python prefix to the self update command on Windows (#1972) --- news/1972.feature.md | 1 + src/pdm/cli/actions.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 news/1972.feature.md diff --git a/news/1972.feature.md b/news/1972.feature.md new file mode 100644 index 0000000000..3d55994b10 --- /dev/null +++ b/news/1972.feature.md @@ -0,0 +1 @@ +Show the specific install commands for different installations when checking update. This was removed before. diff --git a/src/pdm/cli/actions.py b/src/pdm/cli/actions.py index cd104332db..8735ef39e4 100644 --- a/src/pdm/cli/actions.py +++ b/src/pdm/cli/actions.py @@ -734,13 +734,29 @@ def check_update(project: Project) -> None: """Check if there is a new version of PDM available""" from packaging.version import Version + from pdm.cli.utils import is_homebrew_installation, is_pipx_installation, is_scoop_installation + this_version = project.core.version latest_version = get_latest_version(project) if latest_version is None or Version(this_version) >= Version(latest_version): return - install_command = "pdm self update" + (" --pre" if Version(latest_version).is_prerelease else "") disable_command = "pdm config check_update false" + is_prerelease = Version(latest_version).is_prerelease + + if is_pipx_installation(): + install_command = f"pipx upgrade {'--pip-args=--pre ' if is_prerelease else ''}pdm" + elif is_homebrew_installation(): + install_command = "brew upgrade pdm" + elif is_scoop_installation(): + install_command = "scoop update pdm" + else: + install_command = "pdm self update" + (" --pre" if is_prerelease else "") + if os.name == "nt": + # On Windows, the executable can't replace itself, we add the python prefix to the command + # A bit ugly but it works + install_command = f"{sys.executable} -m {install_command}" + message = [ f"\nPDM [primary]{this_version}[/]", f" is installed, while [primary]{latest_version}[/]",