fix: normalize PyPI requirements in registry date updater (#446)

This commit is contained in:
陈家名
2026-08-21 15:25:30 +08:00
committed by GitHub
parent 429f399150
commit d1eca95a47
2 changed files with 14 additions and 1 deletions
@@ -81,3 +81,9 @@ def test_extract_pypi_package_returns_none_for_editable_only_install():
install_cmd = "pip install -e ."
assert MODULE._extract_pypi_package(install_cmd) is None
def test_extract_pypi_package_strips_extras_and_version_specifier():
install_cmd = "pip install 'requests[socks]>=2.32'"
assert MODULE._extract_pypi_package(install_cmd) == "requests"
+8 -1
View File
@@ -19,6 +19,12 @@ USER_AGENT = "CLI-Anything registry date updater"
GITHUB_REPO_RE = re.compile(r"https://github\.com/([^/]+/[^/#?]+?)(?:\.git)?(?:[/?#].*)?$")
GIT_URL_RE = re.compile(r"https://github\.com/[^\s#]+")
SUBDIRECTORY_RE = re.compile(r"#subdirectory=([^\s]+)")
PYPI_REQUIREMENT_RE = re.compile(
r"^(?P<name>[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?)"
r"(?:\[[A-Za-z0-9._,-]+\])?"
r"(?:[<>=!~].*)?"
r"(?:;.*)?$"
)
PIP_OPTIONS_WITH_VALUES = {
"-c",
"--constraint",
@@ -165,7 +171,8 @@ def _extract_pypi_package(install_cmd: str) -> str | None:
continue
if "://" in token or token.startswith("git+"):
return None
return token
requirement = PYPI_REQUIREMENT_RE.fullmatch(token)
return requirement.group("name") if requirement else None
return None