diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 9d3e0bc5..c6c8d06f 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -3,6 +3,7 @@ import argparse, os, subprocess, sys, textwrap, shlex import cibuildwheel import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos +from cibuildwheel.environment import parse_environment, EnvironmentParseError from cibuildwheel.util import BuildSkipper def get_option_from_environment(option_name, platform=None): @@ -74,14 +75,13 @@ def main(): skip_config = os.environ.get('CIBW_SKIP', '') environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform) or '' - environment = {} - for key_value in shlex.split(environment_config): - try: - key, value = key_value.split('=') - environment[key] = value - except: - print('cibuildwheel: Malformed environment option "%s"' % key_value, file=sys.stderr) - exit(2) + try: + environment = parse_environment(environment_config) + except (EnvironmentParseError, ValueError) as e: + print('cibuildwheel: Malformed environment option "%s"' % key_value, file=sys.stderr) + import traceback + traceback.print_exc(None, sys.stderr) + exit(2) skip = BuildSkipper(skip_config) diff --git a/cibuildwheel/environment.py b/cibuildwheel/environment.py index 6d6ed71f..5b5f45e1 100644 --- a/cibuildwheel/environment.py +++ b/cibuildwheel/environment.py @@ -55,6 +55,9 @@ class EnvironmentAssignment(object): def as_shell_assignment(self): return 'export %s=%s' % (self.name, self.value) + def __repr__(self): + return '%s=%s' % (self.name, self.value) + class ParsedEnvironment(object): def __init__(self, assignments): @@ -71,3 +74,6 @@ class ParsedEnvironment(object): def as_shell_commands(self): return [a.as_shell_assignment() for a in self.assignments] + + def __repr__(self): + return 'ParsedEnvironment(%r)' % [repr(a) for a in self.assignments] diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 7e28208a..b49c4a11 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -108,9 +108,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be before_build=shlex_quote( prepare_command(before_build, python='python', pip='pip') if before_build else '' ), - environment_exports=' '.join( - ('export %s=%s\n' % (key, shlex_quote(value)) for key, value in environment.items()) - ), + environment_exports='\n'.join(environment.as_shell_commands()), ) docker_process = subprocess.Popen([ diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index e6ff34f1..5bc9ed02 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -39,6 +39,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be '/Library/Frameworks/Python.framework/Versions/%s/bin' % config.version, env['PATH'], ]) + env = environment.as_dictionary(prev_environment=env) python = 'python3' if config.version[0] == '3' else 'python2' pip = 'pip3' if config.version[0] == '3' else 'pip2' diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 1486c91b..1c7afe38 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -60,6 +60,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be os.path.join(config.path, 'Scripts'), env['PATH'] ]) + env = environment.as_dictionary(prev_environment=env) # for the logs - check we're running the right version of python shell(['python', '--version'], env=env)