Use parse_environment in the main code

This commit is contained in:
Joe Rickerby
2017-09-01 13:33:29 +01:00
parent 9091533fcc
commit fcb681d283
5 changed files with 17 additions and 11 deletions
+8 -8
View File
@@ -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)
+6
View File
@@ -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]
+1 -3
View File
@@ -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([
+1
View File
@@ -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'
+1
View File
@@ -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)