[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/27] mkvenv: create pip binary in virtual environment
|
From: |
John Snow |
|
Subject: |
[PATCH 09/27] mkvenv: create pip binary in virtual environment |
|
Date: |
Wed, 10 May 2023 23:54:17 -0400 |
From: Paolo Bonzini <pbonzini@redhat.com>
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 <jsnow@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
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.
--------------------------------------------------
@@ -25,6 +27,13 @@
--------------------------------------------------
+usage: mkvenv post_init [-h]
+
+options:
+ -h, --help show this help message and exit
+
+--------------------------------------------------
+
usage: mkvenv ensure [-h] [--online] [--dir DIR] dep_spec...
positional arguments:
@@ -189,6 +198,13 @@ def post_post_setup(self, context: SimpleNamespace) ->
None:
with open(pth_file, "w", encoding="UTF-8") as file:
file.write(parent_libpath + os.linesep)
+ args = [
+ context.env_exe,
+ __file__,
+ "post_init",
+ ]
+ subprocess.run(args, check=True)
+
def get_value(self, field: str) -> str:
"""
Get a string value from the context namespace after a call to build.
@@ -727,6 +743,17 @@ def ensure(
raise Ouch(diagnose(dep_specs[0], online, wheels_dir, prog)) from exc
+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 = subparsers.add_parser("create", help="create a venv")
subparser.add_argument(
@@ -737,6 +764,10 @@ def _add_create_subcommand(subparsers: Any) -> None:
)
+def _add_post_init_subcommand(subparsers: Any) -> None:
+ subparsers.add_parser("post_init", help="post-venv initialization")
+
+
def _add_ensure_subcommand(subparsers: Any) -> None:
subparser = subparsers.add_parser(
"ensure", help="Ensure that the specified package is installed."
@@ -790,6 +821,7 @@ def main() -> int:
)
_add_create_subcommand(subparsers)
+ _add_post_init_subcommand(subparsers)
_add_ensure_subcommand(subparsers)
args = parser.parse_args()
@@ -800,6 +832,8 @@ def main() -> int:
system_site_packages=True,
clear=True,
)
+ if args.command == "post_init":
+ post_venv_setup()
if args.command == "ensure":
ensure(
dep_specs=args.dep_specs,
--
2.40.0
- [PATCH 05/27] mkvenv: add nested venv workaround, (continued)
[PATCH 13/27] tests/vm: add py310-expat to NetBSD, John Snow, 2023/05/10
[PATCH 12/27] tests/vm: Configure netbsd to use Python 3.10, John Snow, 2023/05/10
[PATCH 09/27] mkvenv: create pip binary in virtual environment,
John Snow <=
[PATCH 11/27] tests/docker: add python3-venv dependency, John Snow, 2023/05/10
[PATCH 14/27] python: add vendor.py utility, John Snow, 2023/05/10
[PATCH 15/27] configure: create a python venv unconditionally, John Snow, 2023/05/10
[PATCH 17/27] configure: use 'mkvenv ensure meson' to bootstrap meson, John Snow, 2023/05/10
[PATCH 19/27] tests: Use configure-provided pyvenv for tests, John Snow, 2023/05/10
[PATCH 20/27] configure: move --enable-docs and --disable-docs back to configure, John Snow, 2023/05/10
[PATCH 10/27] mkvenv: work around broken pip installations on Debian 10, John Snow, 2023/05/10
[PATCH 18/27] qemu.git: drop meson git submodule, John Snow, 2023/05/10
[PATCH 21/27] configure: bootstrap sphinx with mkvenv, John Snow, 2023/05/10
[PATCH 23/27] Python: Drop support for Python 3.6, John Snow, 2023/05/10