diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 34cde558..84372395 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -105,6 +105,26 @@ def main(): # This needs to be passed on to the docker container in linux.py os.environ['CIBUILDWHEEL'] = '1' + try: + project_setup_py = os.path.join(project_dir, 'setup.py') + name_output = subprocess.check_output([sys.executable, project_setup_py, '--name'], + universal_newlines=True) + # the last line of output is the name + package_name = name_output.strip().splitlines()[-1] + except subprocess.CalledProcessError as err: + if not os.path.exists(project_setup_py): + print('cibuildwheel: Could not find setup.py at root of project', file=sys.stderr) + exit(2) + else: + print(err.output) + print('cibuildwheel: Failed to get name of the package. Command was %s' % err.cmd, + file=sys.stderr) + exit(err.returncode) + if package_name == '' or package_name == 'UNKNOWN': + print('cibuildwheel: Invalid package name "%s". Check your setup.py' % package_name, + file=sys.stderr) + exit(2) + build_options = dict( project_dir=project_dir, output_dir=output_dir, diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index c127ece7..c907c6b6 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -135,6 +135,7 @@ def build(project_dir, output_dir, test_command, test_requires, before_build, bu try: run_docker(['create', '--env', 'CIBUILDWHEEL', + '--name', container_name, '-i', '-v', '/:/host', # ignored on Circle docker_image, '/bin/bash']) diff --git a/test/03_before_build/setup.py b/test/03_before_build/setup.py index 6f12313a..aea796af 100644 --- a/test/03_before_build/setup.py +++ b/test/03_before_build/setup.py @@ -1,6 +1,23 @@ from setuptools import setup, Extension import sys, os +# assert that the Python version as written to pythonversion.txt in the CIBW_BEFORE_BUILD step +# is the same one as is currently running. +version_file = 'c:\\pythonversion.txt' if sys.platform == 'win32' else '/tmp/pythonversion.txt' +with open(version_file) as f: + stored_version = f.read() +print('stored_version', stored_version) +print('sys.version', sys.version) +assert stored_version == sys.version +# check that the executable also was written +executable_file = 'c:\\pythonexecutable.txt' if sys.platform == 'win32' else '/tmp/pythonexecutable.txt' +with open(executable_file) as f: + stored_executable = f.read() +print('stored_executable', stored_executable) +print('sys.executable', sys.executable) +# windows/mac are case insensitive +assert os.path.realpath(stored_executable).lower() == os.path.realpath(sys.executable).lower() + setup( name="spam", ext_modules=[Extension('spam', sources=['spam.c'])], diff --git a/test/04_build_skip/setup.py b/test/04_build_skip/setup.py index 0a1ac29b..94f3eb13 100644 --- a/test/04_build_skip/setup.py +++ b/test/04_build_skip/setup.py @@ -1,6 +1,12 @@ from setuptools import setup, Extension import sys +# explode if run on Python 2.7 or Python 3.4 (these should be skipped) +if sys.version_info[0:2] == (2, 7): + raise Exception('Python 2.7 should not be built') +if sys.version_info[0:2] == (3, 4): + raise Exception('Python 3.4 should be skipped') + setup( name="spam", ext_modules=[Extension('spam', sources=['spam.c'])], diff --git a/test/05_environment/setup.py b/test/05_environment/setup.py index 6f12313a..40b2c197 100644 --- a/test/05_environment/setup.py +++ b/test/05_environment/setup.py @@ -1,6 +1,19 @@ from setuptools import setup, Extension import sys, os +# explode if environment isn't correct, as set in CIBW_ENVIRONMENT +CIBW_TEST_VAR = os.environ.get('CIBW_TEST_VAR') +CIBW_TEST_VAR_2 = os.environ.get('CIBW_TEST_VAR_2') +PATH = os.environ.get('PATH') +if CIBW_TEST_VAR != 'a b c': + raise Exception('CIBW_TEST_VAR should equal "a b c". It was "%s"' % CIBW_TEST_VAR) +if CIBW_TEST_VAR_2 != '1': + raise Exception('CIBW_TEST_VAR_2 should equal "1". It was "%s"' % CIBW_TEST_VAR_2) +if '/opt/cibw_test_path' not in PATH: + raise Exception('PATH should contain "/opt/cibw_test_path". It was "%s"' % PATH) +if '$PATH' in PATH: + raise Exception('$PATH should be expanded in PATH. It was "%s"' % PATH) + setup( name="spam", ext_modules=[Extension('spam', sources=['spam.c'])], diff --git a/test/06_docker_images/setup.py b/test/06_docker_images/setup.py index 5b3e09ec..8084d9fe 100644 --- a/test/06_docker_images/setup.py +++ b/test/06_docker_images/setup.py @@ -2,6 +2,11 @@ import os, sys from setuptools import setup, Extension +# check that we're running in the correct docker image as specified in the +# environment options CIBW_MANYLINUX1_*_IMAGE +if 'linux' in sys.platform and not os.path.exists('/dockcross'): + raise Exception('/dockcross directory not found. Is this test running in the correct docker image?') + setup( name="spam", ext_modules=[Extension('spam', sources=['spam.c'])],