cf5be1f
From 57ddc4814e921021ed95e9f21cc3f8f9bf06a1f2 Mon Sep 17 00:00:00 2001
9aaabea
From: Lumir Balhar <lbalhar@redhat.com>
693ab6f
Date: Thu, 9 Feb 2023 15:13:36 +0100
b7713a7
Subject: [PATCH] RPM wheels
cf5be1f
MIME-Version: 1.0
cf5be1f
Content-Type: text/plain; charset=UTF-8
cf5be1f
Content-Transfer-Encoding: 8bit
9aaabea
cf5be1f
Co-Authored-By: Miro HronĨok <miro@hroncok.cz>
9aaabea
---
1de75fd
 src/virtualenv/run/__init__.py                |  5 +++--
b7713a7
 src/virtualenv/seed/embed/base_embed.py       | 16 +++++++++++++-
1de75fd
 src/virtualenv/seed/embed/pip_invoke.py       |  1 +
1de75fd
 .../seed/embed/via_app_data/via_app_data.py   |  1 +
cf5be1f
 src/virtualenv/seed/wheels/acquire.py         |  3 ++-
693ab6f
 src/virtualenv/seed/wheels/embed/__init__.py  |  4 ++++
88f20d5
 src/virtualenv/util/path/_system_wheels.py    | 22 +++++++++++++++++++
cf5be1f
 7 files changed, 48 insertions(+), 4 deletions(-)
9aaabea
 create mode 100644 src/virtualenv/util/path/_system_wheels.py
9aaabea
1de75fd
diff --git a/src/virtualenv/run/__init__.py b/src/virtualenv/run/__init__.py
370bb9c
index 6d22b71..19d1791 100644
1de75fd
--- a/src/virtualenv/run/__init__.py
1de75fd
+++ b/src/virtualenv/run/__init__.py
370bb9c
@@ -87,8 +87,9 @@ def build_parser_only(args=None):
1de75fd
 
1de75fd
 def handle_extra_commands(options):
1de75fd
     if options.upgrade_embed_wheels:
5d085ee
-        result = manual_upgrade(options.app_data, options.env)
1de75fd
-        raise SystemExit(result)
5d085ee
+        # result = manual_upgrade(options.app_data, options.env)
1de75fd
+        logging.warning("virtualenv installed from the RPM package uses wheels from RPM packages as well. Updating them via virtualenv is not possible. The RPM packaged wheels are updated together with other RPM packages of the system.")
1de75fd
+        raise SystemExit(1)
1de75fd
 
1de75fd
 
1de75fd
 def load_app_data(args, parser, options):
9aaabea
diff --git a/src/virtualenv/seed/embed/base_embed.py b/src/virtualenv/seed/embed/base_embed.py
88f20d5
index f29110b..07649c2 100644
9aaabea
--- a/src/virtualenv/seed/embed/base_embed.py
9aaabea
+++ b/src/virtualenv/seed/embed/base_embed.py
370bb9c
@@ -3,8 +3,9 @@ from pathlib import Path
9aaabea
 
9aaabea
 from ..seeder import Seeder
1de75fd
 from ..wheels import Version
370bb9c
+from virtualenv.util.path._system_wheels import get_system_wheels_paths
1de75fd
 
1de75fd
-PERIODIC_UPDATE_ON_BY_DEFAULT = True
1de75fd
+PERIODIC_UPDATE_ON_BY_DEFAULT = False
9aaabea
 
1de75fd
 
370bb9c
 class BaseEmbed(Seeder, metaclass=ABCMeta):
370bb9c
@@ -27,6 +28,15 @@ class BaseEmbed(Seeder, metaclass=ABCMeta):
b7713a7
         if not self.distribution_to_versions():
b7713a7
             self.enabled = False
b7713a7
 
b7713a7
+        if "embed" in (self.pip_version, self.setuptools_version, self.wheel_version):
b7713a7
+            raise RuntimeError(
b7713a7
+                "Embedded wheels are not available if virtualenv "
b7713a7
+                "is installed from the RPM package.\nEither install "
b7713a7
+                "virtualenv from PyPI (via pip) or use 'bundle' "
b7713a7
+                "version which uses the system-wide pip, setuptools "
b7713a7
+                "and wheel wheels provided also by RPM packages."
b7713a7
+            )
b7713a7
+
b7713a7
     @classmethod
b7713a7
     def distributions(cls):
b7713a7
         return {
370bb9c
@@ -105,6 +115,10 @@ class BaseEmbed(Seeder, metaclass=ABCMeta):
370bb9c
             result += f" {distribution}{ver},"
370bb9c
         return result[:-1] + ")"
9aaabea
 
9aaabea
+    def insert_system_wheels_paths(self, creator):
88f20d5
+        system_wheels_paths = get_system_wheels_paths(creator.interpreter)
9aaabea
+        self.extra_search_dir = list(system_wheels_paths) + self.extra_search_dir
370bb9c
+
370bb9c
 
370bb9c
 __all__ = [
370bb9c
     "BaseEmbed",
9aaabea
diff --git a/src/virtualenv/seed/embed/pip_invoke.py b/src/virtualenv/seed/embed/pip_invoke.py
370bb9c
index 2ca9438..339295f 100644
9aaabea
--- a/src/virtualenv/seed/embed/pip_invoke.py
9aaabea
+++ b/src/virtualenv/seed/embed/pip_invoke.py
370bb9c
@@ -15,6 +15,7 @@ class PipInvoke(BaseEmbed):
9aaabea
     def run(self, creator):
9aaabea
         if not self.enabled:
9aaabea
             return
9aaabea
+        self.insert_system_wheels_paths(creator)
1de75fd
         for_py_version = creator.interpreter.version_release_str
1de75fd
         with self.get_pip_install_cmd(creator.exe, for_py_version) as cmd:
5d085ee
             env = pip_wheel_env_run(self.extra_search_dir, self.app_data, self.env)
1de75fd
diff --git a/src/virtualenv/seed/embed/via_app_data/via_app_data.py b/src/virtualenv/seed/embed/via_app_data/via_app_data.py
370bb9c
index f31ecf6..d7a0f5a 100644
1de75fd
--- a/src/virtualenv/seed/embed/via_app_data/via_app_data.py
1de75fd
+++ b/src/virtualenv/seed/embed/via_app_data/via_app_data.py
370bb9c
@@ -37,6 +37,7 @@ class FromAppData(BaseEmbed):
1de75fd
     def run(self, creator):
1de75fd
         if not self.enabled:
1de75fd
             return
1de75fd
+        self.insert_system_wheels_paths(creator)
1de75fd
         with self._get_seed_wheels(creator) as name_to_whl:
1de75fd
             pip_version = name_to_whl["pip"].version_tuple if "pip" in name_to_whl else None
1de75fd
             installer_class = self.installer_class(pip_version)
cf5be1f
diff --git a/src/virtualenv/seed/wheels/acquire.py b/src/virtualenv/seed/wheels/acquire.py
cf5be1f
index 21fde34..d6ae171 100644
cf5be1f
--- a/src/virtualenv/seed/wheels/acquire.py
cf5be1f
+++ b/src/virtualenv/seed/wheels/acquire.py
cf5be1f
@@ -97,13 +97,14 @@ def find_compatible_in_house(distribution, version_spec, for_py_version, in_fold
cf5be1f
 
cf5be1f
 
cf5be1f
 def pip_wheel_env_run(search_dirs, app_data, env):
cf5be1f
+    from virtualenv.util.path._system_wheels import get_system_wheels_paths
cf5be1f
     env = env.copy()
cf5be1f
     env.update({"PIP_USE_WHEEL": "1", "PIP_USER": "0", "PIP_NO_INPUT": "1"})
cf5be1f
     wheel = get_wheel(
cf5be1f
         distribution="pip",
cf5be1f
         version=None,
cf5be1f
         for_py_version=f"{sys.version_info.major}.{sys.version_info.minor}",
cf5be1f
-        search_dirs=search_dirs,
cf5be1f
+        search_dirs=get_system_wheels_paths(sys),
cf5be1f
         download=False,
cf5be1f
         app_data=app_data,
cf5be1f
         do_periodic_update=False,
1de75fd
diff --git a/src/virtualenv/seed/wheels/embed/__init__.py b/src/virtualenv/seed/wheels/embed/__init__.py
cf5be1f
index 782051a..38dece9 100644
1de75fd
--- a/src/virtualenv/seed/wheels/embed/__init__.py
1de75fd
+++ b/src/virtualenv/seed/wheels/embed/__init__.py
693ab6f
@@ -53,7 +53,11 @@ BUNDLE_SUPPORT = {
693ab6f
 MAX = "3.12"
693ab6f
 
1de75fd
 
9aaabea
+# Redefined here because bundled wheels are removed in RPM build
9aaabea
+BUNDLE_SUPPORT = None
693ab6f
+
1de75fd
 def get_embed_wheel(distribution, for_py_version):
1de75fd
+    return None  # BUNDLE_SUPPORT == None anyway
1de75fd
     path = BUNDLE_FOLDER / (BUNDLE_SUPPORT.get(for_py_version, {}) or BUNDLE_SUPPORT[MAX]).get(distribution)
1de75fd
     return Wheel.from_path(path)
9aaabea
 
9aaabea
diff --git a/src/virtualenv/util/path/_system_wheels.py b/src/virtualenv/util/path/_system_wheels.py
9aaabea
new file mode 100644
88f20d5
index 0000000..f3fd9b1
9aaabea
--- /dev/null
9aaabea
+++ b/src/virtualenv/util/path/_system_wheels.py
88f20d5
@@ -0,0 +1,22 @@
370bb9c
+from pathlib import Path
9aaabea
+from subprocess import check_output, CalledProcessError
9aaabea
+
9aaabea
+
88f20d5
+def get_system_wheels_paths(interpreter):
9aaabea
+    # ensurepip wheels
9aaabea
+    # We need subprocess here to check ensurepip with the Python we are creating
9aaabea
+    # a new virtual environment for
88f20d5
+    executable = interpreter.executable
9aaabea
+    try:
9aaabea
+        ensurepip_path = check_output((executable, "-u", "-c", 'import ensurepip; print(ensurepip.__path__[0])'), universal_newlines=True)
9aaabea
+        ensurepip_path = Path(ensurepip_path.strip()) / "_bundled"
9aaabea
+    except CalledProcessError:
9aaabea
+        pass
9aaabea
+    else:
9aaabea
+        if ensurepip_path.is_dir():
9aaabea
+            yield ensurepip_path
9aaabea
+
9aaabea
+    # Standard wheels path
9aaabea
+    wheels_dir = Path("/usr/share/python-wheels")
9aaabea
+    if wheels_dir.exists():
9aaabea
+        yield wheels_dir
9aaabea
-- 
cf5be1f
2.44.0
9aaabea