From nobody Sat Nov 15 05:23:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1754945429; cv=none; d=zohomail.com; s=zohoarc; b=M0sl9oR3r7gFDphSo9mGXO78XRkjDn5M4r/E1F6mq7/z00NFJlx3gu9tF7Z7iG+UV+36/ChwvS2dx+cork3oGPbC2GBJuMq4QDjbhgkTBud7tUNqddEalgcfw1yIZeXtRPnWDgB1ZscP1LpEXlKkhcKXMtzgxuUSPpGjTGU+XIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1754945429; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CQbe91S3uYByF6cPyraY71e5cBELSRKSscwlqRZokVA=; b=HhevKFYKhepd4ytAAvm0cTF8tTVTZjQtaUa6BetRy+iVziWPzDYQ79TSxTlhO5sw/zvT4mYkVlcbDC/TOj6Jd14F+gVgCR+TfLZkVap2ScCN129K0rnET18vNd+hzZ6R9KlGnNE2HKsK9EqkTIOr9h8MDWpyrfT0xG/0Xk8E4F8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1754945429488556.425122675354; Mon, 11 Aug 2025 13:50:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ulZSf-00026N-3l; Mon, 11 Aug 2025 16:49:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ulZSd-00025m-Ab for qemu-devel@nongnu.org; Mon, 11 Aug 2025 16:49:39 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ulZSX-0008V2-Jr for qemu-devel@nongnu.org; Mon, 11 Aug 2025 16:49:39 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-7EhFESGmMC-2UMNpAXX3-w-1; Mon, 11 Aug 2025 16:49:24 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3EA76180044F; Mon, 11 Aug 2025 20:49:22 +0000 (UTC) Received: from jsnow-thinkpadp16vgen1.westford.csb (unknown [10.22.64.164]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 49F051955F16; Mon, 11 Aug 2025 20:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754945366; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CQbe91S3uYByF6cPyraY71e5cBELSRKSscwlqRZokVA=; b=hsdyRLhCCi3Mr3Pr9MaYkyEfjSK2MpiIKHf07JNIqnCC/vHF7zUguzHjPa2nt5rGtSmGm9 l2eELZNaE0PmKmG4yDn+t3Tcx1SD9VU6ClWsnC8dMg16VMYT4e87AypnN8huX0YX3Icofq KDbCi9dyuh6h0ANyftipeuSIB4HY4bM= X-MC-Unique: 7EhFESGmMC-2UMNpAXX3-w-1 X-Mimecast-MFC-AGG-ID: 7EhFESGmMC-2UMNpAXX3-w_1754945363 From: John Snow To: qemu-devel@nongnu.org Cc: Cleber Rosa , Michael Tokarev , John Snow Subject: [PATCH] mkvenv: support pip 25.2; prefer packaging over distlib Date: Mon, 11 Aug 2025 16:49:18 -0400 Message-ID: <20250811204918.260524-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=jsnow@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1754945431432116600 Content-Type: text/plain; charset="utf-8" Stop using distlib LegacyVersion parsing and begin using `packaging` version parsing instead. Signed-off-by: John Snow Tested-by: Michael Tokarev --- python/scripts/mkvenv.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py index 8ac5b0b2a05..1aa9fc7badb 100644 --- a/python/scripts/mkvenv.py +++ b/python/scripts/mkvenv.py @@ -94,17 +94,32 @@ HAVE_DISTLIB =3D True try: import distlib.scripts - import distlib.version except ImportError: try: # Reach into pip's cookie jar. pylint and flake8 don't understand # that these imports will be used via distlib.xxx. from pip._vendor import distlib import pip._vendor.distlib.scripts # noqa, pylint: disable=3Dunus= ed-import - import pip._vendor.distlib.version # noqa, pylint: disable=3Dunus= ed-import except ImportError: HAVE_DISTLIB =3D False =20 + +HAVE_PACKAGING =3D True +try: + import packaging.requirements # type: ignore + import packaging.version # type: ignore +except ImportError: + try: + # Reach into pip's cookie jar yet again. + # Shush all the tools rightly telling us this is a bad idea. + # pylint: disable=3Dungrouped-imports, unused-import + from pip._vendor import packaging # type: ignore + import pip._vendor.packaging.requirements + import pip._vendor.packaging.version # noqa + except ImportError: + HAVE_PACKAGING =3D False + + # Try to load tomllib, with a fallback to tomli. # HAVE_TOMLLIB is checked below, just-in-time, so that mkvenv does not fail # outside the venv or before a potential call to ensurepip in checkpip(). @@ -669,12 +684,22 @@ def _do_ensure( canary =3D None for name, info in group.items(): constraint =3D _make_version_constraint(info, False) - matcher =3D distlib.version.LegacyMatcher(name + constraint) - print(f"mkvenv: checking for {matcher}", file=3Dsys.stderr) + req =3D packaging.requirements.Requirement(name + constraint) + + def _match( + req: 'packaging.requirements.Requirement', + version_str: str + ) -> bool: + return bool(req.specifier.contains( + packaging.version.Version(version_str), + prereleases=3DTrue + )) + + print(f"mkvenv: checking for {req}", file=3Dsys.stderr) =20 dist: Optional[Distribution] =3D None try: - dist =3D distribution(matcher.name) + dist =3D distribution(req.name) except PackageNotFoundError: pass =20 @@ -683,7 +708,7 @@ def _do_ensure( # Always pass installed package to pip, so that they can be # updated if the requested version changes or not _is_system_package(dist) - or not matcher.match(distlib.version.LegacyVersion(dist.versio= n)) + or not _match(req, dist.version) ): absent.append(name + _make_version_constraint(info, True)) if len(absent) =3D=3D 1: @@ -753,6 +778,8 @@ def ensure_group( =20 if not HAVE_DISTLIB: raise Ouch("found no usable distlib, please install it") + if not HAVE_PACKAGING: + raise Ouch("found no usable packaging lib, please install it") =20 parsed_deps =3D _parse_groups(file) =20 --=20 2.50.1