Skip to content

"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/

Python

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

陈家名d1eca95a4731
diff --git a/.github/scripts/tests/test_update_registry_dates.py b/.github/scripts/tests/test_update_registry_dates.py
index 5c9abd23b..a061544f3 100644
--- a/.github/scripts/tests/test_update_registry_dates.py
+++ b/.github/scripts/tests/test_update_registry_dates.py
@@ -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"
diff --git a/.github/scripts/update_registry_dates.py b/.github/scripts/update_registry_dates.py
index 61e36435b..827c958ed 100644
--- a/.github/scripts/update_registry_dates.py
+++ b/.github/scripts/update_registry_dates.py
@@ -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