Blob Blame History Raw
From 174c2674c6bf3cad9fdcff1f17e931deefb7332e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
Date: Thu, 23 Mar 2023 13:14:22 +0100
Subject: [PATCH] Use --system-site-packages in virtual environments, don't
 pip-install

Mu 1.1+ creates a virtual environment when it starts and installs
a bunch of packages from PyPI to it.
See https://github.com/mu-editor/mu/commit/37a0e0df46

The downloaded wheels from PyPI are cached to %{python3_sitelib}, which fails without root/sudo.
See https://github.com/mu-editor/mu/issues/1634

Downloading software from the internet cannot be required for an official RPM package to function,
so we disable it here.

With this patch, the packages normally installed to the virtual environment
are required on runtime and the virtual environment is created with --system-site-packages.

This kinda goes against the entire idea of the virtualenv feature,
but it is the only reasonable way to have Mu packaged.
---
 mu/virtual_environment.py                           |  3 ++-
 mu/wheels/__init__.py                               | 13 ++-----------
 setup.py                                            |  6 ++++++
 .../virtual_environment/test_virtual_environment.py |  6 ++----
 4 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/mu/virtual_environment.py b/mu/virtual_environment.py
index c84613a..e9f3a3a 100644
--- a/mu/virtual_environment.py
+++ b/mu/virtual_environment.py
@@ -825,7 +825,7 @@ class VirtualEnvironment(object):
         before re-raising the error.
         """
         self.create_venv()
-        self.install_baseline_packages()
+        # self.install_baseline_packages() -- we cannot do this in packaged RPM
         self.register_baseline_packages()
         self.install_jupyter_kernel()
         self.settings["mu_version"] = mu_version
@@ -847,6 +847,7 @@ class VirtualEnvironment(object):
                 "virtualenv",
                 "-p",
                 safe_short_path(sys.executable),
+                "--system-site-packages",  # added in the RPM package
                 "-q",
                 "" if self._is_windows else "--symlinks",
                 self.path,
diff --git a/mu/wheels/__init__.py b/mu/wheels/__init__.py
index 40f32db..fab993f 100644
--- a/mu/wheels/__init__.py
+++ b/mu/wheels/__init__.py
@@ -40,17 +40,8 @@ mode_packages = [
     ("pgzero", "pgzero>=1.2.1"),
     # Flask v1 depends on Jinja v2, which doesn't have an upper bound limit in
     # MarkupSafe, and v2.1 is not compatible with Jinja v2
-    ("flask", "flask==2.0.3"),
-    # The version of ipykernel here should match to the version used by
-    # qtconsole at the version specified in setup.py
-    # FIXME: ipykernel max ver added for macOS 10.13 compatibility, min taken
-    # from qtconsole 4.7.7. This is mirrored in setup.py
-    ("ipykernel", "ipykernel>=4.1,<6"),
-    # FIXME: ipykernel<6 depends on ipython_genutils, but it isn't explicitly
-    # declared as a dependency. It also depends on traitlets, which
-    # incidentally brought ipython_genutils, but in v5.1 it was dropped, so as
-    # a workaround we need to manually specify it here
-    ("ipython_genutils", "ipython_genutils>=0.2.0"),
+    ("flask", "flask==2.*"),
+    ("ipykernel", "ipykernel>=4.1"),
 ]
 
 
diff --git a/setup.py b/setup.py
index 2a0e5dc..25955ed 100644
--- a/setup.py
+++ b/setup.py
@@ -75,6 +75,12 @@ install_requires = [
     # Needed to resolve an issue with paths in the user virtual environment
     #
     "pywin32; sys_platform=='win32'",
+    #
+    # Copied from mu/wheels/__init__.py
+    #
+    "pgzero>=1.2.1",
+    "flask==2.*",
+    # "ipykernel>=4.1" -- already above
 ]
 
 
diff --git a/tests/virtual_environment/test_virtual_environment.py b/tests/virtual_environment/test_virtual_environment.py
index e433850..345dbfb 100644
--- a/tests/virtual_environment/test_virtual_environment.py
+++ b/tests/virtual_environment/test_virtual_environment.py
@@ -218,11 +218,9 @@ def test_create_virtual_environment_on_disk(venv_dirpath, test_wheels):
     )
 
     #
-    # Check that our test wheel has been installed to a single module
+    # RPM: Check that no packages were actually installed
     #
-    expected_result = os.path.join(venv_site_packages, "arrr.py")
-    result = venv.run_python("-c", "import arrr; print(arrr.__file__)").strip()
-    assert os.path.samefile(result, expected_result)
+    assert not os.path.exists(os.path.join(venv_site_packages, "arrr.py"))
 
     #
     # Issue #1372 -- venv creation fails for paths with a space
-- 
2.39.2