From 0a7a1b8fb3e38f4e8ca43d1fe6f104e6f207382a Mon Sep 17 00:00:00 2001 From: mayeut Date: Tue, 22 Aug 2017 21:41:13 +0200 Subject: [PATCH] Set CIBUILDWHEEL environment variable to 1 during build --- README.md | 11 +++++++++++ cibuildwheel/__main__.py | 4 ++++ cibuildwheel/linux.py | 2 ++ test/01_basic/setup.py | 5 +++++ 4 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 5e6eb012..223277d0 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,17 @@ Usage `cibuildwheel` is not intended to run on your development machine. It will try to install packages globally; this is no good. Travis CI and Appveyor run their builds in isolated environments, so are ideal for this kind of script. +`cibuildwheel` defines the environment variable `CIBUILDWHEEL` to the value `1` allowing projects for which the C extension is optional to make it mandatory when building wheels. +An easy way to do it in Python 3 is through the `optional` named argument of `Extension` constructor in your `setup.py`: +```python +myextension = Extension( + "myextension", + ["myextension.c"], + optional=os.environ.get('CIBUILDWHEEL', '0') != '1', +) +``` + + ### Minimal setup - Create a `.travis.yml` file in your repo. diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index cf15f57c..c17b273e 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -75,6 +75,10 @@ def main(): skip = BuildSkipper(skip_config) + # Add CIBUILDWHEEL environment variable + # 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'], diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index af6415aa..b973089d 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -111,6 +111,8 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be docker_process = subprocess.Popen([ 'docker', 'run', + '--env', + 'CIBUILDWHEEL', '--rm', '-i', '-v', '%s:/project' % os.path.abspath(project_dir), diff --git a/test/01_basic/setup.py b/test/01_basic/setup.py index 866fa22c..48d7c00b 100644 --- a/test/01_basic/setup.py +++ b/test/01_basic/setup.py @@ -1,5 +1,10 @@ +import os + from setuptools import setup, Extension +if os.environ.get('CIBUILDWHEEL', '0') != '1': + raise Exception('CIBUILDWHEEL environment variable is not set to 1') + setup( name="spam", ext_modules=[Extension('spam', sources=['spam.c'])],