From e3642300b30f249c7a281f3d7f45107fa5eba148 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Fri, 8 Jul 2022 17:28:47 +0800 Subject: [PATCH] fix: respect `--prerelease` in the install script --- README.md | 2 +- README_zh.md | 2 +- docs/docs/index.md | 2 +- install-pdm.py | 20 ++++++++++++++------ 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 39ee5990..ee327d0d 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py ``` For security reasons, you should verify the checksum of `install-pdm.py`. -The sha256 checksum is: `5efebd44f477521d0d8ef0e118b7e5765ff20f80d3d4dd9394f1b8ff1094fb4d` +The sha256 checksum is: `f09accb8a530315be312cf9ce7af987ccb608aa90d3972968d73e7ef7d8c547b` The installer will install PDM into the user site and the location depends on the system: diff --git a/README_zh.md b/README_zh.md index d10fa4de..81df36c1 100644 --- a/README_zh.md +++ b/README_zh.md @@ -87,7 +87,7 @@ curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py ``` 为安全起见,你应该检查 `install-pdm.py` 文件的正确性。 -SHA256 校验和: `5efebd44f477521d0d8ef0e118b7e5765ff20f80d3d4dd9394f1b8ff1094fb4d` +SHA256 校验和: `f09accb8a530315be312cf9ce7af987ccb608aa90d3972968d73e7ef7d8c547b` 默认情况下,此脚本会将 PDM 安装在 Python 的用户目录下,具体位置取决于当前系统: diff --git a/docs/docs/index.md b/docs/docs/index.md index cb09004d..3254ac01 100644 --- a/docs/docs/index.md +++ b/docs/docs/index.md @@ -50,7 +50,7 @@ Like Pip, PDM provides an installation script that will install PDM into an isol ``` For security reasons, you should verify the checksum of `install-pdm.py`. -The sha256 checksum is: `5efebd44f477521d0d8ef0e118b7e5765ff20f80d3d4dd9394f1b8ff1094fb4d` +The sha256 checksum is: `f09accb8a530315be312cf9ce7af987ccb608aa90d3972968d73e7ef7d8c547b` The installer will install PDM into the user site and the location depends on the system: diff --git a/install-pdm.py b/install-pdm.py index 4a78ac74..2d4e9d47 100644 --- a/install-pdm.py +++ b/install-pdm.py @@ -6,6 +6,7 @@ import io import json import os import platform +import re import shutil import site import subprocess @@ -207,14 +208,23 @@ class Installer: resp = urllib.request.urlopen(JSON_URL) metadata = json.load(resp) - def is_stable(v: str) -> bool: - return all(p.isdigit() for p in v.split(".")) + def version_okay(v: str) -> bool: + return self.prerelease or all(p.isdigit() for p in v.split(".")) def sort_version(v: str) -> tuple: - return tuple(int(p) for p in v.split(".")) + parts = [] + for part in v.split("."): + if part.isdigit(): + parts.append(int(part)) + else: + digit, rest = re.match(r"^(\d*)(.*)", part).groups() + if digit: + parts.append(int(digit)) + parts.append(rest) + return tuple(parts) releases = sorted( - filter(is_stable, metadata["releases"]), key=sort_version, reverse=True + filter(version_okay, metadata["releases"]), key=sort_version, reverse=True ) return releases[0] @@ -300,8 +310,6 @@ class Installer: else: req = "pdm" args = [req] + [d for d in self.additional_deps if d] - if self.prerelease: - args.insert(0, "--pre") pip_cmd = [str(venv_python), "-m", "pip", "install"] + args _call_subprocess(pip_cmd) -- GitLab