nptyping icon indicating copy to clipboard operation
nptyping copied to clipboard

Allow use of system packages in venv

Open mcepl opened this issue 2 years ago • 2 comments

When packaging nptyping for openSUSE we build packages (as every other Linux distribution does) in the environment completely isolated from the network. We pre-install all packages in the build environment, but we need to able to use it:

---
 tests/test_wheel.py |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

--- a/tests/test_wheel.py
+++ b/tests/test_wheel.py
@@ -93,10 +93,9 @@ class WheelTest(TestCase):

     def test_wheel_can_be_installed(self):
         with working_dir(Path(self.temp_dir.name)):
-            venv.create(_VENV_NAME, with_pip=False)
-            # For some reason, with_pip=True fails, so we do it separately.
-            subprocess.check_output(
-                f"{self.py} -m ensurepip --upgrade --default-pip", shell=True
+            venv.create(_VENV_NAME, system_site_packages=True, with_pip=True)
+            print(
+                f"{self.pip} install {_ROOT / 'dist' / _WHEEL_NAME}"
             )
             subprocess.check_output(
                 f"{self.pip} install {_ROOT / 'dist' / _WHEEL_NAME}", shell=True

I am not sure whether with_pip is relevant, but using it seems to make the code slightly simple.

mcepl avatar May 05 '22 08:05 mcepl

Hi @mcepl. The argument with_pip=True should create a virtual environment with pip. This is relevant, because later in this test, it is checked whether nptyping and all its dependencies can be installed with it.

But as the comment states, for some reason that command failed for me with with_pip=True. That's the reason for the line that follows with ensurepip; to still make pip available after the virtual environment creation.

What exactly is your question/suggestion?

ramonhagenaars avatar May 05 '22 19:05 ramonhagenaars

That for running the test suite inside of the environments without the Internet access, it is necessary to add system_site_packages=True, so that previously installed system packages can be used.

That with_pip=True is probably irrelevant.

mcepl avatar May 05 '22 20:05 mcepl