~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix(build): refresh pip bundled MessagePack and inventory (#8060)
LearningCircuitd094dae7e499
diff --git a/Dockerfile b/Dockerfileindex bd14f3f71c..36355609c9 100644--- a/Dockerfile+++ b/Dockerfile@@ -97,8 +97,8 @@ RUN pip3 install --no-cache-dir --require-hashes --only-binary=:all: \-r /tmp/bootstrap-builder.txt \&& rm /tmp/bootstrap-builder.txt-# pip 26.2.2 still vendors urllib3 2.7.0. Refresh it from reviewed wheels,-# including ensurepip's seed wheel, until pip ships urllib3 >=2.8.0 (#7094).+# Refresh pip 26.2.2's bundled urllib3 and MessagePack from reviewed wheels,+# including ensurepip's seed, until pip ships urllib3 >=2.8.0 and msgpack >=1.2.3.COPY requirements/pip-vendor-refresh.txt /tmp/pip-vendor-refresh.txtCOPY scripts/refresh_pip_urllib3.py /tmp/refresh_pip_urllib3.pyCOPY tests/ci/standalone/verify_pip_vendor.py /tmp/verify_pip_vendor.py@@ -368,7 +368,7 @@ RUN pip3 install --no-cache-dir --require-hashes --only-binary=:all: \-r /tmp/bootstrap-runtime.txt \&& rm /tmp/bootstrap-runtime.txt-# This independent root stage needs the same pip and ensurepip refresh.+# This independent root stage needs the same bundled-library and seed refresh.COPY requirements/pip-vendor-refresh.txt /tmp/pip-vendor-refresh.txtCOPY scripts/refresh_pip_urllib3.py /tmp/refresh_pip_urllib3.pyCOPY tests/ci/standalone/verify_pip_vendor.py /tmp/verify_pip_vendor.pydiff --git a/requirements/pip-vendor-refresh.txt b/requirements/pip-vendor-refresh.txtindex 4b1adc71b7..f19a259115 100644--- a/requirements/pip-vendor-refresh.txt+++ b/requirements/pip-vendor-refresh.txt@@ -1,7 +1,12 @@# Inputs for scripts/refresh_pip_urllib3.py. Download wheels only; the script-# rebuilds pip with upstream urllib3 2.8.0 and retains pip's vendoring changes.-# Remove this refresh when the bootstrap pip release vendors urllib3 >=2.8.0.+# rebuilds pip with upstream urllib3 2.8.0 and MessagePack 1.2.3, retaining+# pip's namespace changes and pure-Python MessagePack implementation.+# MessagePack wheel hashes cover the CPython 3.14 amd64 and arm64 images.+# Remove when pip vendors urllib3 >=2.8.0 and msgpack >=1.2.3.pip==26.2.2 \--hash=sha256:fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70urllib3==2.8.0 \--hash=sha256:0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3+msgpack==1.2.3 \+ --hash=sha256:d8ef3a66e4b52d2d7fdd90df2984670124b2ff7546d76bb25dcf68ef47f7df58 \+ --hash=sha256:9324c54995641c3d1f92a9d55093c8cde0ffa2fbc87a467a688ef60428393220diff --git a/scripts/refresh_pip_urllib3.py b/scripts/refresh_pip_urllib3.pyindex 43922961a9..d6298ca29b 100644--- a/scripts/refresh_pip_urllib3.py+++ b/scripts/refresh_pip_urllib3.py@@ -1,7 +1,8 @@-"""Refresh pip's bundled urllib3 until pip releases its upstream update.+"""Refresh pip's reviewed bundled urllib3 and MessagePack releases.Inputs are the unmodified, hash-verified PyPI wheels for pip 26.2.2 and-urllib3 2.8.0. Preserve pip's namespace rewrites and disabled Brotli support,+urllib3 2.8.0 and msgpack 1.2.3. Preserve pip's namespace rewrites,+disabled Brotli support, and pure-Python MessagePack implementation,update its vendor manifest and CycloneDX SBOM, and regenerate wheel RECORD.The Docker build installs this wheel and also replaces ensurepip's copy socreating a venv cannot restore the vulnerable vendored urllib3 2.7.0.@@ -9,7 +10,8 @@ creating a venv cannot restore the vulnerable vendored urllib3 2.7.0.Upstream fixes: https://github.com/urllib3/urllib3/releases/tag/2.8.0Vendoring baseline: https://github.com/pypa/pip/tree/26.2.2/src/pip/_vendorDelete this helper and its Docker wiring when a pinned pip release carries-urllib3 >=2.8.0. A changed input or ensurepip layout requires a new review.+urllib3 >=2.8.0 and msgpack >=1.2.3. A changed input or ensurepip layout+requires a new review."""from __future__ import annotations@@ -31,11 +33,23 @@ from zipfile import ZIP_DEFLATED, ZipFile, ZipInfoPIP_VERSION = "26.2.2"URLLIB3_VERSION = "2.8.0"+MSGPACK_VERSION = "1.2.3"PIP_WHEEL = f"pip-{PIP_VERSION}-py3-none-any.whl"URLLIB3_WHEEL = f"urllib3-{URLLIB3_VERSION}-py3-none-any.whl"+MSGPACK_INPUT_HASHES = {+ (+ f"msgpack-{MSGPACK_VERSION}-cp314-cp314-manylinux2014_aarch64."+ "manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl"+ ): "9324c54995641c3d1f92a9d55093c8cde0ffa2fbc87a467a688ef60428393220", # DevSkim: ignore DS173237 - public integrity checksum, not a secret+ (+ f"msgpack-{MSGPACK_VERSION}-cp314-cp314-manylinux2014_x86_64."+ "manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl"+ ): "d8ef3a66e4b52d2d7fdd90df2984670124b2ff7546d76bb25dcf68ef47f7df58", # DevSkim: ignore DS173237 - public integrity checksum, not a secret+}INPUT_HASHES = {PIP_WHEEL: "fd7f4dfa8190e014013b9f08f3e973f4e4c26ffd179a204895533a7254813a70", # DevSkim: ignore DS173237 - public integrity checksum, not a secretURLLIB3_WHEEL: "0cf3cae568d36aa9576b28dfb35f11328f1cb974ca7647d9475ebb86c75ac6e3", # DevSkim: ignore DS173237 - public integrity checksum, not a secret+ **MSGPACK_INPUT_HASHES,}VENDOR = "pip/_vendor/"DIST_INFO = f"pip-{PIP_VERSION}.dist-info/"@@ -119,42 +133,50 @@ def vendored_sources(upstream: dict[str, bytes]) -> dict[str, bytes]:return files-def refreshed_contents(- pip: dict[str, bytes], urllib3: dict[str, bytes]-) -> dict[str, bytes]:+def vendored_msgpack_sources(upstream: dict[str, bytes]) -> dict[str, bytes]:+ """Retain pip's pure-Python MessagePack layout on both image architectures."""files = {- name: content- for name, content in pip.items()- if not name.startswith(VENDOR + "urllib3/")+ VENDOR + name: content+ for name, content in upstream.items()+ if name.startswith("msgpack/") and name.endswith(".py")}- files.update(vendored_sources(urllib3))- files[DIST_INFO + "licenses/src/pip/_vendor/urllib3/LICENSE.txt"] = files[- VENDOR + "urllib3/LICENSE.txt"+ required = {"__init__.py", "exceptions.py", "ext.py", "fallback.py"}+ if {name.removeprefix(VENDOR + "msgpack/") for name in files} != required:+ raise ValueError("upstream msgpack Python layout changed")+ files[VENDOR + "msgpack/COPYING"] = upstream[+ f"msgpack-{MSGPACK_VERSION}.dist-info/licenses/COPYING"]+ return files+++def refresh_inventory(+ files: dict[str, bytes], name: str, previous: str, version: str+) -> None:+ """Keep the manifest, component and dependency references consistent."""manifest, count = re.subn(- r"(?m)^(\s*)urllib3==2\.7\.0$",- rf"\g<1>urllib3=={URLLIB3_VERSION}",+ rf"(?m)^(\s*){re.escape(name)}=={re.escape(previous)}$",+ rf"\g<1>{name}=={version}",files[VENDOR + "vendor.txt"].decode(),)if count != 1:raise ValueError(- "pip's urllib3 vendor pin changed; review or remove the refresh"+ f"pip's {name} vendor pin changed; review or remove the refresh")files[VENDOR + "vendor.txt"] = manifest.encode()sbom = json.loads(files[VENDOR + "bom.cdx.json"])components = [componentfor component in sbom["components"]- if component["name"] == "urllib3"+ if component["name"] == name]- if len(components) != 1 or components[0]["version"] != "2.7.0":- raise ValueError("pip's urllib3 SBOM component changed")- old_ref = "pkg:pypi/[email protected]"- new_ref = f"pkg:pypi/urllib3@{URLLIB3_VERSION}"+ if len(components) != 1 or components[0]["version"] != previous:+ raise ValueError(f"pip's {name} SBOM component changed")+ old_ref = f"pkg:pypi/{name}@{previous}"+ new_ref = f"pkg:pypi/{name}@{version}"component = components[0]if component["bom-ref"] != old_ref or component["purl"] != old_ref:- raise ValueError("pip's urllib3 SBOM reference changed")- component.update(version=URLLIB3_VERSION, purl=new_ref)+ raise ValueError(f"pip's {name} SBOM reference changed")+ component.update(version=version, purl=new_ref)component["bom-ref"] = new_reffor dependency in sbom["dependencies"]:if dependency["ref"] == old_ref:@@ -167,6 +189,26 @@ def refreshed_contents(files[VENDOR + "bom.cdx.json"] = (json.dumps(sbom, indent=2) + "\n").encode()+++def refreshed_contents(+ pip: dict[str, bytes],+ urllib3: dict[str, bytes],+ msgpack: dict[str, bytes],+) -> dict[str, bytes]:+ files = {+ name: content+ for name, content in pip.items()+ if not name.startswith((VENDOR + "urllib3/", VENDOR + "msgpack/"))+ }+ files.update(vendored_sources(urllib3))+ files.update(vendored_msgpack_sources(msgpack))+ for path in ("urllib3/LICENSE.txt", "msgpack/COPYING"):+ files[DIST_INFO + "licenses/src/pip/_vendor/" + path] = files[+ VENDOR + path+ ]+ refresh_inventory(files, "urllib3", "2.7.0", URLLIB3_VERSION)+ refresh_inventory(files, "msgpack", "1.1.2", MSGPACK_VERSION)record = DIST_INFO + "RECORD"rows = io.StringIO(newline="")writer = csv.writer(rows, lineterminator="\n")@@ -185,9 +227,13 @@ def refreshed_contents(def build_wheel(inputs: Path, output: Path) -> Path:+ msgpack_wheels = list(inputs.glob(f"msgpack-{MSGPACK_VERSION}-*.whl"))+ if len(msgpack_wheels) != 1:+ raise ValueError("expected exactly one reviewed msgpack wheel")files = refreshed_contents(verified_wheel(inputs / PIP_WHEEL),verified_wheel(inputs / URLLIB3_WHEEL),+ verified_wheel(msgpack_wheels[0]),)output.mkdir(parents=True, exist_ok=True)destination = output / PIP_WHEEL@@ -240,7 +286,7 @@ def install(wheel: Path, verifier: Path) -> None:)shutil.copyfile(wheel, bundle)# Fresh interpreters avoid trusting modules cached before reinstalling pip.- check = ["-I", str(verifier), URLLIB3_VERSION]+ check = ["-I", str(verifier), URLLIB3_VERSION, MSGPACK_VERSION]subprocess.run([sys.executable, *check], check=True)subprocess.run([sys.executable, "-I", "-m", "pip", "debug", "--verbose"], check=Truediff --git a/tests/ci/standalone/test_pip_vendor_refresh.py b/tests/ci/standalone/test_pip_vendor_refresh.pyindex 27591cbc2d..e41bf699de 100644--- a/tests/ci/standalone/test_pip_vendor_refresh.py+++ b/tests/ci/standalone/test_pip_vendor_refresh.py@@ -3,6 +3,7 @@from contextlib import contextmanagerimport hashlibimport importlib.util+import jsonfrom pathlib import Pathimport sysimport tempfile@@ -71,7 +72,12 @@ class RefreshInstallationChecks(unittest.TestCase):)for option in ("--no-index", "--no-deps", "--force-reinstall"):self.assertIn(option, commands[0])- expected = ["-I", str(self.verifier), refresh.URLLIB3_VERSION]+ expected = [+ "-I",+ str(self.verifier),+ refresh.URLLIB3_VERSION,+ refresh.MSGPACK_VERSION,+ ]self.assertEqual(commands[1], [sys.executable, *expected])self.assertEqual(commands[-1][1:], expected)self.assertEqual(commands[-2][:4], [sys.executable, "-I", "-m", "venv"])@@ -162,5 +168,110 @@ class RefreshConfigurationChecks(unittest.TestCase):)+class RefreshInventoryChecks(unittest.TestCase):+ def inventory(self):+ references = {+ "urllib3": "pkg:pypi/[email protected]",+ "msgpack": "pkg:pypi/[email protected]",+ }+ components = [+ {+ "name": name,+ "version": reference.split("@")[-1],+ "purl": reference,+ "bom-ref": reference,+ }+ for name, reference in references.items()+ ]+ sbom = {+ "components": components,+ "dependencies": [+ {"ref": "pip", "dependsOn": list(references.values())},+ *({"ref": ref} for ref in references.values()),+ ],+ }+ return {+ refresh.VENDOR+ + "vendor.txt": b" urllib3==2.7.0\nmsgpack==1.1.2\n",+ refresh.VENDOR + "bom.cdx.json": json.dumps(sbom).encode(),+ }++ def test_code_manifest_and_all_dependency_references_agree(self):+ files = self.inventory()+ for name, previous, version in (+ ("urllib3", "2.7.0", refresh.URLLIB3_VERSION),+ ("msgpack", "1.1.2", refresh.MSGPACK_VERSION),+ ):+ refresh.refresh_inventory(files, name, previous, version)+ manifest = files[refresh.VENDOR + "vendor.txt"].decode()+ self.assertIn(f"{name}=={version}\n", manifest)+ self.assertNotIn(f"{name}=={previous}\n", manifest)+ sbom = files[refresh.VENDOR + "bom.cdx.json"].decode()+ self.assertNotIn(f"pkg:pypi/{name}@{previous}", sbom)+ self.assertEqual(sbom.count(f"pkg:pypi/{name}@{version}"), 4)++ def test_changed_vendor_pin_is_refused(self):+ files = self.inventory()+ path = refresh.VENDOR + "vendor.txt"+ files[path] = files[path].replace(b"msgpack==1.1.2", b"msgpack==0.0")+ with self.assertRaisesRegex(ValueError, "vendor pin changed"):+ refresh.refresh_inventory(files, "msgpack", "1.1.2", "1.2.3")++ def test_changed_component_is_refused(self):+ for field in ("version", "purl", "bom-ref"):+ with self.subTest(field=field):+ files = self.inventory()+ path = refresh.VENDOR + "bom.cdx.json"+ sbom = json.loads(files[path])+ sbom["components"][1][field] = "unexpected"+ files[path] = json.dumps(sbom).encode()+ with self.assertRaisesRegex(ValueError, "SBOM"):+ refresh.refresh_inventory(+ files, "msgpack", "1.1.2", "1.2.3"+ )++ def test_msgpack_keeps_only_upstream_python_files_and_license(self):+ upstream = {+ "msgpack/" + name: f"# {name}\n".encode()+ for name in (+ "__init__.py",+ "exceptions.py",+ "ext.py",+ "fallback.py",+ )+ }+ upstream["msgpack/_cmsgpack.so"] = b"not a vendored file"+ license_path = (+ f"msgpack-{refresh.MSGPACK_VERSION}.dist-info/licenses/COPYING"+ )+ upstream[license_path] = b"upstream license text"+ files = refresh.vendored_msgpack_sources(upstream)+ self.assertEqual(len(files), 5)+ self.assertNotIn(refresh.VENDOR + "msgpack/_cmsgpack.so", files)+ for path, content in upstream.items():+ if path.endswith(".py"):+ self.assertEqual(files[refresh.VENDOR + path], content)+ self.assertEqual(+ files[refresh.VENDOR + "msgpack/COPYING"],+ upstream[license_path],+ )++ def test_msgpack_source_layout_drift_is_refused(self):+ with self.assertRaisesRegex(ValueError, "Python layout changed"):+ refresh.vendored_msgpack_sources({"msgpack/new.py": b""})++ def test_missing_or_ambiguous_msgpack_input_is_refused(self):+ with tempfile.TemporaryDirectory() as directory:+ root = Path(directory)+ for present in (False, True):+ with self.subTest(two_inputs=present):+ if present:+ for name in refresh.MSGPACK_INPUT_HASHES:+ (root / name).touch()+ with self.assertRaisesRegex(ValueError, "exactly one"):+ refresh.build_wheel(root, root / "output")+ self.assertFalse((root / "output").exists())++if __name__ == "__main__":unittest.main()diff --git a/tests/ci/standalone/verify_pip_vendor.py b/tests/ci/standalone/verify_pip_vendor.pyindex 9db6587b3b..2cb65b9c03 100644--- a/tests/ci/standalone/verify_pip_vendor.py+++ b/tests/ci/standalone/verify_pip_vendor.py@@ -117,32 +117,68 @@ def verify_proxy_policy() -> None:raise RuntimeError("origin TLS configuration overrode the proxy policy")-def verify_runtime(expected_version: str) -> None:+def verify_msgpack() -> None:+ """Exercise the pure-Python serializer used by pip's cache transport."""+ from pip._vendor import msgpack++ if msgpack.Packer.__module__ != "pip._vendor.msgpack.fallback":+ raise RuntimeError("pip did not retain pure-Python MessagePack")+ value = {"body": b"cached content", "metadata": [1, True, None]}+ packed = msgpack.packb(value, use_bin_type=True)+ if msgpack.unpackb(packed, raw=False) != value:+ raise RuntimeError("vendored MessagePack round-trip changed")+ unpacker = msgpack.Unpacker(raw=False)+ unpacker.feed(packed)+ if list(unpacker) != [value]:+ raise RuntimeError("vendored MessagePack streaming round-trip changed")+++def verify_runtime(expected_version: str, expected_msgpack: str) -> None:import pip- from pip._vendor import urllib3+ from pip._vendor import msgpack, urllib3from pip._vendor.urllib3.util.url import parse_urlif urllib3.__version__ != expected_version:raise RuntimeError("installed pip did not load the refreshed urllib3")+ if msgpack.__version__ != expected_msgpack:+ raise RuntimeError("installed pip did not load the refreshed msgpack")if parse_url("https://bücher.example").host != "xn--bcher-kva.example":raise RuntimeError("vendored IDNA import failed")sbom = json.loads((Path(pip.__file__).parent / "_vendor/bom.cdx.json").read_text())- components = [- item for item in sbom["components"] if item["name"] == "urllib3"+ manifest = [+ line.strip()+ for line in (Path(pip.__file__).parent / "_vendor/vendor.txt")+ .read_text(encoding="utf-8")+ .splitlines()]- if len(components) != 1 or components[0]["version"] != urllib3.__version__:- raise RuntimeError(- "installed pip's SBOM disagrees with its urllib3 code"- )+ for name, version in (+ ("urllib3", urllib3.__version__),+ ("msgpack", msgpack.__version__),+ ):+ components = [+ item for item in sbom["components"] if item["name"] == name+ ]+ reference = f"pkg:pypi/{name}@{version}"+ if (+ len(components) != 1+ or components[0]["version"] != version+ or components[0]["purl"] != reference+ or components[0]["bom-ref"] != reference+ or manifest.count(f"{name}=={version}") != 1+ ):+ raise RuntimeError(+ f"installed pip's inventory disagrees with its {name} code"+ )verify_chunk_lines()verify_deflate_eof()verify_proxy_policy()+ verify_msgpack()print(- "pip's urllib3 code, inventory and transport regression checks passed"+ "pip's bundled code, inventory, transport and serialization checks passed")if __name__ == "__main__":- verify_runtime(sys.argv[1])+ verify_runtime(sys.argv[1], sys.argv[2])