mirror of
https://github.com/HKUDS/CLI-Anything.git
synced 2026-08-28 23:27:04 +08:00
fix: normalize PyPI requirements in registry date updater (#446)
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user