From nobody Mon Feb 9 18:19:40 2026 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=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1683777569; cv=none; d=zohomail.com; s=zohoarc; b=EwH+Lh2Yya3TE2ELIr+18M/1tKJk/knfwe2lzZ8wqTIpXuQP4gW18f/5YOhqf7Q4G8o09b6qB+JWwBiYuFvs/XlMkiBQEZNkRdHvTM988ELfTwOkAFGIlpb3/VFjc7mPj0GF24KJrJfmCuwfyKaBOMxqVeS+dV4RnQv9S7hsV+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1683777569; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FrpNLMmUH8QQBGE3hmT2dVSEwPqpJk/j6a6V49WnrLk=; b=i+D5n17Jbw/QIZoSVJg0SEfI895yhOeMbX5QVQzWx32dR9CpyXXxPXcAZNYykf9YmfZveJ395Dn14YAmG7DvSZ0OTIldN1vND2OvDaWX3VMgUKkbudv54FojMmCkY4nQakYfT/vy4ipIuoqOCwtEYtXvrKK3jjgeQ9nGE/trYWc= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1683777569131989.1949157638591; Wed, 10 May 2023 20:59:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pwxOK-0007bS-3w; Wed, 10 May 2023 23:54:56 -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 1pwxOH-0007aI-JO for qemu-devel@nongnu.org; Wed, 10 May 2023 23:54:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pwxOC-0005KO-7B for qemu-devel@nongnu.org; Wed, 10 May 2023 23:54:53 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-cz3_5ASKO0iwqiCPlHRx5w-1; Wed, 10 May 2023 23:54:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9970587DC01; Thu, 11 May 2023 03:54:43 +0000 (UTC) Received: from scv.redhat.com (unknown [10.22.34.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id E104940C2076; Thu, 11 May 2023 03:54:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683777287; 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: in-reply-to:in-reply-to:references:references; bh=FrpNLMmUH8QQBGE3hmT2dVSEwPqpJk/j6a6V49WnrLk=; b=Geuz0/d2kHWdoUadagDawg5G3fiofYguhHDWnsR1hpIh7WtFoyFUd34BfQHpwOJM2KCPSB A5jbCPv+N4pCpjYRuv11x/VE6ZHoKeRqAOOt349FoeSkhufQaKrVPYbaPAy5ro2KHPE64j K34BMQ82aCHbzLjkWCSLp/MIOZ4YMec= X-MC-Unique: cz3_5ASKO0iwqiCPlHRx5w-1 From: John Snow To: qemu-devel@nongnu.org Cc: Warner Losh , Peter Maydell , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Ani Sinha , Beraldo Leal , Markus Armbruster , Ryo ONODERA , Paolo Bonzini , Kyle Evans , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Michael Roth , Reinoud Zandijk , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Cleber Rosa , Thomas Huth , "Michael S. Tsirkin" , John Snow , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta Subject: [PATCH 09/27] mkvenv: create pip binary in virtual environment Date: Wed, 10 May 2023 23:54:17 -0400 Message-Id: <20230511035435.734312-10-jsnow@redhat.com> In-Reply-To: <20230511035435.734312-1-jsnow@redhat.com> References: <20230511035435.734312-1-jsnow@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 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.129.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: 1683777569844100001 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini While pip can be invoked as "python -m pip", it is more standard to have it as a binary in the virtual environment. Instead of using ensurepip, which is slow, use the console shim generation that was just added for "mkvenv ensure". Signed-off-by: John Snow Signed-off-by: Paolo Bonzini --- python/scripts/mkvenv.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/python/scripts/mkvenv.py b/python/scripts/mkvenv.py index 9c99122603..7a9a14124d 100644 --- a/python/scripts/mkvenv.py +++ b/python/scripts/mkvenv.py @@ -11,6 +11,8 @@ Commands: command Description create create a venv + post_init + post-venv initialization ensure Ensure that the specified package is installed. =20 -------------------------------------------------- @@ -25,6 +27,13 @@ =20 -------------------------------------------------- =20 +usage: mkvenv post_init [-h] + +options: + -h, --help show this help message and exit + +-------------------------------------------------- + usage: mkvenv ensure [-h] [--online] [--dir DIR] dep_spec... =20 positional arguments: @@ -189,6 +198,13 @@ def post_post_setup(self, context: SimpleNamespace) ->= None: with open(pth_file, "w", encoding=3D"UTF-8") as file: file.write(parent_libpath + os.linesep) =20 + args =3D [ + context.env_exe, + __file__, + "post_init", + ] + subprocess.run(args, check=3DTrue) + def get_value(self, field: str) -> str: """ Get a string value from the context namespace after a call to buil= d. @@ -727,6 +743,17 @@ def ensure( raise Ouch(diagnose(dep_specs[0], online, wheels_dir, prog)) from = exc =20 =20 +def post_venv_setup() -> None: + """ + This is intended to be run *inside the venv* after it is created. + """ + logger.debug("post_venv_setup()") + # Generate a 'pip' script so the venv is usable in a normal + # way from the CLI. This only happens when we inherited pip from a + # parent/system-site and haven't run ensurepip in some way. + generate_console_scripts(["pip"]) + + def _add_create_subcommand(subparsers: Any) -> None: subparser =3D subparsers.add_parser("create", help=3D"create a venv") subparser.add_argument( @@ -737,6 +764,10 @@ def _add_create_subcommand(subparsers: Any) -> None: ) =20 =20 +def _add_post_init_subcommand(subparsers: Any) -> None: + subparsers.add_parser("post_init", help=3D"post-venv initialization") + + def _add_ensure_subcommand(subparsers: Any) -> None: subparser =3D subparsers.add_parser( "ensure", help=3D"Ensure that the specified package is installed." @@ -790,6 +821,7 @@ def main() -> int: ) =20 _add_create_subcommand(subparsers) + _add_post_init_subcommand(subparsers) _add_ensure_subcommand(subparsers) =20 args =3D parser.parse_args() @@ -800,6 +832,8 @@ def main() -> int: system_site_packages=3DTrue, clear=3DTrue, ) + if args.command =3D=3D "post_init": + post_venv_setup() if args.command =3D=3D "ensure": ensure( dep_specs=3Dargs.dep_specs, --=20 2.40.0