Skip to content

Commit a4f7508

Browse files
q0wpradyunsg
andauthored
Drop the doctype check (#10906)
Co-authored-by: Pradyun Gedam <[email protected]>
1 parent 82aebdb commit a4f7508

File tree

5 files changed

+18
-88
lines changed

5 files changed

+18
-88
lines changed

news/10903.removal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Drop the doctype check, that presented a warning for index pages that use non-compliant HTML 5.

src/pip/_internal/exceptions.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -181,30 +181,6 @@ class UninstallationError(PipError):
181181
"""General exception during uninstallation"""
182182

183183

184-
class BadHTMLDoctypeDeclaration(DiagnosticPipError):
185-
reference = "bad-index-doctype"
186-
187-
def __init__(self, *, url: str) -> None:
188-
super().__init__(
189-
kind="warning",
190-
message=(
191-
"The package index page being used does not have a proper HTML "
192-
"doctype declaration."
193-
),
194-
context=f"Problematic URL: {escape(url)}",
195-
note_stmt="This is an issue with the page at the URL mentioned above.",
196-
hint_stmt=(
197-
"You might need to reach out to the owner of that package index, "
198-
"to get this fixed. "
199-
"See https://github.com/pypa/pip/issues/10825 for context."
200-
),
201-
)
202-
203-
204-
class MissingHTMLDoctypeDeclaration(BadHTMLDoctypeDeclaration):
205-
reference = "missing-index-doctype"
206-
207-
208184
class MissingPyProjectBuildRequires(DiagnosticPipError):
209185
"""Raised when pyproject.toml has `build-system`, but no `build-system.requires`."""
210186

src/pip/_internal/index/collector.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232
from pip._vendor.requests import Response
3333
from pip._vendor.requests.exceptions import RetryError, SSLError
3434

35-
from pip._internal.exceptions import (
36-
BadHTMLDoctypeDeclaration,
37-
MissingHTMLDoctypeDeclaration,
38-
NetworkConnectionError,
39-
)
35+
from pip._internal.exceptions import NetworkConnectionError
4036
from pip._internal.models.link import Link
4137
from pip._internal.models.search_scope import SearchScope
4238
from pip._internal.network.session import PipSession
@@ -401,33 +397,12 @@ class HTMLLinkParser(HTMLParser):
401397

402398
def __init__(self, url: str) -> None:
403399
super().__init__(convert_charrefs=True)
404-
self._dealt_with_doctype_issues = False
405400

406401
self.url: str = url
407402
self.base_url: Optional[str] = None
408403
self.anchors: List[Dict[str, Optional[str]]] = []
409404

410-
def handle_decl(self, decl: str) -> None:
411-
self._dealt_with_doctype_issues = True
412-
match = re.match(
413-
r"""doctype\s+html\s*(?:SYSTEM\s+(["'])about:legacy-compat\1)?\s*$""",
414-
decl,
415-
re.IGNORECASE,
416-
)
417-
if match is None:
418-
logger.warning(
419-
"[present-diagnostic] %s",
420-
BadHTMLDoctypeDeclaration(url=self.url),
421-
)
422-
423405
def handle_starttag(self, tag: str, attrs: List[Tuple[str, Optional[str]]]) -> None:
424-
if not self._dealt_with_doctype_issues:
425-
logger.warning(
426-
"[present-diagnostic] %s",
427-
MissingHTMLDoctypeDeclaration(url=self.url),
428-
)
429-
self._dealt_with_doctype_issues = True
430-
431406
if tag == "base" and self.base_url is None:
432407
href = self.get_href(attrs)
433408
if href is not None:

tests/functional/test_install_index.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import textwrap
34
import urllib.parse
45

@@ -24,6 +25,21 @@ def test_find_links_relative_path(script: PipTestEnvironment, data: TestData) ->
2425
result.did_create(initools_folder)
2526

2627

28+
def test_find_links_no_doctype(script: PipTestEnvironment, data: TestData) -> None:
29+
shutil.copy(data.packages / "simple-1.0.tar.gz", script.scratch_path)
30+
html = script.scratch_path.joinpath("index.html")
31+
html.write_text('<a href="simple-1.0.tar.gz"></a>')
32+
result = script.pip(
33+
"install",
34+
"simple==1.0",
35+
"--no-index",
36+
"--find-links",
37+
script.scratch_path,
38+
expect_stderr=True,
39+
)
40+
assert not result.stderr
41+
42+
2743
@pytest.mark.usefixtures("with_wheel")
2844
def test_find_links_requirements_file_relative_path(
2945
script: PipTestEnvironment, data: TestData

tests/unit/test_collector.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -551,44 +551,6 @@ def test_parse_link_handles_deprecated_usage_properly() -> None:
551551
assert "pkg1-2.0" in parsed_links[1].url
552552

553553

554-
def test_parse_links_presents_warning_on_missing_doctype(
555-
caplog: pytest.LogCaptureFixture,
556-
) -> None:
557-
html = b'<a href="/pkg1-1.0.tar.gz"></a><a href="/pkg1-2.0.tar.gz"></a>'
558-
url = "https://example.com/simple/"
559-
page = HTMLPage(html, encoding=None, url=url, cache_link_parsing=False)
560-
561-
with caplog.at_level(logging.WARN):
562-
parsed_links = list(parse_links(page, use_deprecated_html5lib=False))
563-
564-
assert len(parsed_links) == 2, parsed_links
565-
assert "pkg1-1.0" in parsed_links[0].url
566-
assert "pkg1-2.0" in parsed_links[1].url
567-
568-
assert len(caplog.records) == 1
569-
570-
571-
def test_parse_links_presents_warning_on_html4_doctype(
572-
caplog: pytest.LogCaptureFixture,
573-
) -> None:
574-
html = (
575-
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" '
576-
b'"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'
577-
b'<a href="/pkg1-1.0.tar.gz"></a><a href="/pkg1-2.0.tar.gz"></a>'
578-
)
579-
url = "https://example.com/simple/"
580-
page = HTMLPage(html, encoding=None, url=url, cache_link_parsing=False)
581-
582-
with caplog.at_level(logging.WARN):
583-
parsed_links = list(parse_links(page, use_deprecated_html5lib=False))
584-
585-
assert len(parsed_links) == 2, parsed_links
586-
assert "pkg1-1.0" in parsed_links[0].url
587-
assert "pkg1-2.0" in parsed_links[1].url
588-
589-
assert len(caplog.records) == 1
590-
591-
592554
@mock.patch("pip._internal.index.collector.raise_for_status")
593555
def test_request_http_error(
594556
mock_raise_for_status: mock.Mock, caplog: pytest.LogCaptureFixture

0 commit comments

Comments
 (0)