From 01dd18bbf85cc5d108780f78b43638f9a62d0f04 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Sun, 1 Mar 2020 01:50:45 +0100 Subject: [PATCH 1/7] change 02_test to check if virtualenv is properly used --- cibuildwheel/linux.py | 2 ++ cibuildwheel/macos.py | 1 + cibuildwheel/windows.py | 1 + test/02_test/test/spam_test.py | 17 +++++++++++++++++ 4 files changed, 21 insertions(+) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index dc7238a6..20dae7e6 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -145,6 +145,8 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef venv_dir=`mktemp -d`/venv python -m virtualenv "$venv_dir" + export __CIBW_VIRTUALENV_PATH__=$venv_dir + # run the tests in a subshell to keep that `activate` # script from polluting the env ( diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index dd2a412b..3b3edcba 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -209,6 +209,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef os.path.join(venv_dir, 'bin'), virtualenv_env['PATH'], ]) + virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir # check that we are using the Python from the virtual environment call(['which', 'python'], env=virtualenv_env) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index bd93e1db..f179be94 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -197,6 +197,7 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef os.path.join(venv_dir, 'Scripts'), virtualenv_env['PATH'], ]) + virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir # check that we are using the Python from the virtual environment shell(['which', 'python'], env=virtualenv_env) diff --git a/test/02_test/test/spam_test.py b/test/02_test/test/spam_test.py index faf7e6bc..58ce05d0 100644 --- a/test/02_test/test/spam_test.py +++ b/test/02_test/test/spam_test.py @@ -1,9 +1,26 @@ +from __future__ import print_function +import os +import sys from unittest import TestCase import spam +def normalize_path(path_str): + """because of windows short path""" + return os.path.normcase(path_str).replace("vssadm~1", "vssadministrator") + + class TestSpam(TestCase): def test_system(self): self.assertEqual(0, spam.system('python -c "exit(0)"')) self.assertNotEqual(0, spam.system('python -c "exit(1)"')) + + def test_virtualenv(self): + virtualenv_path = normalize_path(os.environ.get("__CIBW_VIRTUALENV_PATH__")) + print("=[executable]", sys.executable) + print("=[spam location]", spam.__file__) + print("=[virtualenv path]", virtualenv_path) + self.assertTrue(virtualenv_path in normalize_path(sys.executable)) + self.assertTrue(virtualenv_path in normalize_path(spam.__file__)) + From e0c456604d10ed13fd4b715547650da5ae5714f4 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Sun, 1 Mar 2020 19:48:11 +0100 Subject: [PATCH 2/7] verify if __CIBW_VIRTUALENV_PATH__ is set --- test/02_test/test/spam_test.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/02_test/test/spam_test.py b/test/02_test/test/spam_test.py index 58ce05d0..0271b672 100644 --- a/test/02_test/test/spam_test.py +++ b/test/02_test/test/spam_test.py @@ -18,9 +18,11 @@ class TestSpam(TestCase): def test_virtualenv(self): virtualenv_path = normalize_path(os.environ.get("__CIBW_VIRTUALENV_PATH__")) + if not virtualenv_path: + self.fail("No virtualenv path defined in environment variable __CIBW_VIRTUALENV_PATH__") + print("=[executable]", sys.executable) print("=[spam location]", spam.__file__) print("=[virtualenv path]", virtualenv_path) self.assertTrue(virtualenv_path in normalize_path(sys.executable)) self.assertTrue(virtualenv_path in normalize_path(spam.__file__)) - From 6e41e729fe2b261ef3b0e0ef45f2a81ac5df24c0 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Mon, 2 Mar 2020 14:34:39 +0100 Subject: [PATCH 3/7] pin virtualenv to <20 on windows list dir in test use bin directory in pypy --- cibuildwheel/windows.py | 20 +++++++++++++++----- test/02_test/test/spam_test.py | 5 +++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index f179be94..63565018 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -188,15 +188,25 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef if test_command: # set up a virtual environment to install and test from, to make sure # there are no dependencies that were pulled in at build time. - shell(['pip', 'install', 'virtualenv'], env=env) + shell(['pip', 'install', '"virtualenv<20"'], env=env) venv_dir = tempfile.mkdtemp() shell(['python', '-m', 'virtualenv', venv_dir], env=env) virtualenv_env = env.copy() - virtualenv_env['PATH'] = os.pathsep.join([ - os.path.join(venv_dir, 'Scripts'), - virtualenv_env['PATH'], - ]) + if os.path.exists(os.path.join(venv_dir, 'Scripts')): + virtualenv_env['PATH'] = os.pathsep.join([ + os.path.join(venv_dir, 'Scripts'), + virtualenv_env['PATH'], + ]) + elif os.path.exists(os.path.join(venv_dir, 'bin')): + # pypy2.7 bugfix + virtualenv_env['PATH'] = os.pathsep.join([ + os.path.join(venv_dir, 'bin'), + virtualenv_env['PATH'], + ]) + else: + print("Fail to create virtualenv", file=sys.stderr) + sys.exit(2) virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir # check that we are using the Python from the virtual environment diff --git a/test/02_test/test/spam_test.py b/test/02_test/test/spam_test.py index 0271b672..f5a33ad8 100644 --- a/test/02_test/test/spam_test.py +++ b/test/02_test/test/spam_test.py @@ -24,5 +24,10 @@ class TestSpam(TestCase): print("=[executable]", sys.executable) print("=[spam location]", spam.__file__) print("=[virtualenv path]", virtualenv_path) + print("=[listdir]", os.listdir(virtualenv_path)) + if os.path.exists(os.path.join(virtualenv_path, 'Scripts')): + print("=[listdir]2", os.listdir(os.path.join(virtualenv_path, 'Scripts'))) + if os.path.exists(os.path.join(virtualenv_path, 'bin')): + print("=[listdir]2", os.listdir(os.path.join(virtualenv_path, 'bin'))) self.assertTrue(virtualenv_path in normalize_path(sys.executable)) self.assertTrue(virtualenv_path in normalize_path(spam.__file__)) From 281caf3d2e00ce24799dca99d437751e60b8ebaa Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Mon, 2 Mar 2020 14:54:48 +0100 Subject: [PATCH 4/7] bugfix for pypy --- cibuildwheel/windows.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 63565018..0877a603 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -188,25 +188,20 @@ def build(project_dir, output_dir, test_command, test_requires, test_extras, bef if test_command: # set up a virtual environment to install and test from, to make sure # there are no dependencies that were pulled in at build time. - shell(['pip', 'install', '"virtualenv<20"'], env=env) + shell(['pip', 'install', 'virtualenv'], env=env) venv_dir = tempfile.mkdtemp() shell(['python', '-m', 'virtualenv', venv_dir], env=env) virtualenv_env = env.copy() - if os.path.exists(os.path.join(venv_dir, 'Scripts')): - virtualenv_env['PATH'] = os.pathsep.join([ - os.path.join(venv_dir, 'Scripts'), - virtualenv_env['PATH'], - ]) - elif os.path.exists(os.path.join(venv_dir, 'bin')): + + venv_script_path = os.path.join(venv_dir, 'Scripts') + if os.path.exists(os.path.join(venv_dir, 'bin')): # pypy2.7 bugfix - virtualenv_env['PATH'] = os.pathsep.join([ - os.path.join(venv_dir, 'bin'), - virtualenv_env['PATH'], - ]) - else: - print("Fail to create virtualenv", file=sys.stderr) - sys.exit(2) + venv_script_path = os.pathsep.join([venv_script_path, os.path.join(venv_dir, 'bin')]) + virtualenv_env['PATH'] = os.pathsep.join([ + venv_script_path, + virtualenv_env['PATH'], + ]) virtualenv_env["__CIBW_VIRTUALENV_PATH__"] = venv_dir # check that we are using the Python from the virtual environment From be9eae6828018d45dbf229eb6acd6bc1396fa3d4 Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Tue, 3 Mar 2020 22:40:13 +0100 Subject: [PATCH 5/7] test path_contains --- test/02_test/test/spam_test.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/test/02_test/test/spam_test.py b/test/02_test/test/spam_test.py index f5a33ad8..4eb8ca1f 100644 --- a/test/02_test/test/spam_test.py +++ b/test/02_test/test/spam_test.py @@ -6,9 +6,15 @@ from unittest import TestCase import spam -def normalize_path(path_str): - """because of windows short path""" - return os.path.normcase(path_str).replace("vssadm~1", "vssadministrator") +def path_contains(parent, child): + parent = os.path.abspath(parent) + child = os.path.abspath(child) + + while child != os.path.dirname(child): + child = os.path.dirname(child) + if os.stat(parent) == os.stat(child): + return True + return False class TestSpam(TestCase): @@ -17,7 +23,7 @@ class TestSpam(TestCase): self.assertNotEqual(0, spam.system('python -c "exit(1)"')) def test_virtualenv(self): - virtualenv_path = normalize_path(os.environ.get("__CIBW_VIRTUALENV_PATH__")) + virtualenv_path = os.environ.get("__CIBW_VIRTUALENV_PATH__") if not virtualenv_path: self.fail("No virtualenv path defined in environment variable __CIBW_VIRTUALENV_PATH__") @@ -29,5 +35,5 @@ class TestSpam(TestCase): print("=[listdir]2", os.listdir(os.path.join(virtualenv_path, 'Scripts'))) if os.path.exists(os.path.join(virtualenv_path, 'bin')): print("=[listdir]2", os.listdir(os.path.join(virtualenv_path, 'bin'))) - self.assertTrue(virtualenv_path in normalize_path(sys.executable)) - self.assertTrue(virtualenv_path in normalize_path(spam.__file__)) + self.assertTrue(path_contains(virtualenv_path, sys.executable)) + self.assertTrue(path_contains(virtualenv_path, spam.__file__)) From 83452b75dd945d148c4a6c8c4b241a04b154339e Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Thu, 5 Mar 2020 18:28:16 +0000 Subject: [PATCH 6/7] Apply suggestions from code review --- test/02_test/test/spam_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/02_test/test/spam_test.py b/test/02_test/test/spam_test.py index 4eb8ca1f..d26535fa 100644 --- a/test/02_test/test/spam_test.py +++ b/test/02_test/test/spam_test.py @@ -7,12 +7,18 @@ import spam def path_contains(parent, child): + ''' returns True if `child` is inside `parent`. + + Works around path-comparison bugs caused by short-paths on Windows e.g. + vssadm~1 instead of vssadministrator + ''' parent = os.path.abspath(parent) child = os.path.abspath(child) while child != os.path.dirname(child): child = os.path.dirname(child) if os.stat(parent) == os.stat(child): + # parent and child refer to the same directory on the filesystem return True return False From 4e3cef81d7a10a1b57efc1ad443dfd51b6e486cf Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Fri, 6 Mar 2020 09:08:20 +0000 Subject: [PATCH 7/7] Fix style errors --- test/02_test/test/spam_test.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/02_test/test/spam_test.py b/test/02_test/test/spam_test.py index d26535fa..ba5f5e91 100644 --- a/test/02_test/test/spam_test.py +++ b/test/02_test/test/spam_test.py @@ -6,20 +6,20 @@ from unittest import TestCase import spam -def path_contains(parent, child): +def path_contains(parent, child): ''' returns True if `child` is inside `parent`. Works around path-comparison bugs caused by short-paths on Windows e.g. vssadm~1 instead of vssadministrator ''' - parent = os.path.abspath(parent) - child = os.path.abspath(child) + parent = os.path.abspath(parent) + child = os.path.abspath(child) - while child != os.path.dirname(child): - child = os.path.dirname(child) - if os.stat(parent) == os.stat(child): + while child != os.path.dirname(child): + child = os.path.dirname(child) + if os.stat(parent) == os.stat(child): # parent and child refer to the same directory on the filesystem - return True + return True return False