Use parse_environment in the main code
This commit is contained in:
@@ -3,6 +3,7 @@ import argparse, os, subprocess, sys, textwrap, shlex
|
|||||||
|
|
||||||
import cibuildwheel
|
import cibuildwheel
|
||||||
import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos
|
import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos
|
||||||
|
from cibuildwheel.environment import parse_environment, EnvironmentParseError
|
||||||
from cibuildwheel.util import BuildSkipper
|
from cibuildwheel.util import BuildSkipper
|
||||||
|
|
||||||
def get_option_from_environment(option_name, platform=None):
|
def get_option_from_environment(option_name, platform=None):
|
||||||
@@ -74,14 +75,13 @@ def main():
|
|||||||
skip_config = os.environ.get('CIBW_SKIP', '')
|
skip_config = os.environ.get('CIBW_SKIP', '')
|
||||||
environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform) or ''
|
environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform) or ''
|
||||||
|
|
||||||
environment = {}
|
try:
|
||||||
for key_value in shlex.split(environment_config):
|
environment = parse_environment(environment_config)
|
||||||
try:
|
except (EnvironmentParseError, ValueError) as e:
|
||||||
key, value = key_value.split('=')
|
print('cibuildwheel: Malformed environment option "%s"' % key_value, file=sys.stderr)
|
||||||
environment[key] = value
|
import traceback
|
||||||
except:
|
traceback.print_exc(None, sys.stderr)
|
||||||
print('cibuildwheel: Malformed environment option "%s"' % key_value, file=sys.stderr)
|
exit(2)
|
||||||
exit(2)
|
|
||||||
|
|
||||||
skip = BuildSkipper(skip_config)
|
skip = BuildSkipper(skip_config)
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ class EnvironmentAssignment(object):
|
|||||||
def as_shell_assignment(self):
|
def as_shell_assignment(self):
|
||||||
return 'export %s=%s' % (self.name, self.value)
|
return 'export %s=%s' % (self.name, self.value)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '%s=%s' % (self.name, self.value)
|
||||||
|
|
||||||
|
|
||||||
class ParsedEnvironment(object):
|
class ParsedEnvironment(object):
|
||||||
def __init__(self, assignments):
|
def __init__(self, assignments):
|
||||||
@@ -71,3 +74,6 @@ class ParsedEnvironment(object):
|
|||||||
|
|
||||||
def as_shell_commands(self):
|
def as_shell_commands(self):
|
||||||
return [a.as_shell_assignment() for a in self.assignments]
|
return [a.as_shell_assignment() for a in self.assignments]
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return 'ParsedEnvironment(%r)' % [repr(a) for a in self.assignments]
|
||||||
|
|||||||
@@ -108,9 +108,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be
|
|||||||
before_build=shlex_quote(
|
before_build=shlex_quote(
|
||||||
prepare_command(before_build, python='python', pip='pip') if before_build else ''
|
prepare_command(before_build, python='python', pip='pip') if before_build else ''
|
||||||
),
|
),
|
||||||
environment_exports=' '.join(
|
environment_exports='\n'.join(environment.as_shell_commands()),
|
||||||
('export %s=%s\n' % (key, shlex_quote(value)) for key, value in environment.items())
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
docker_process = subprocess.Popen([
|
docker_process = subprocess.Popen([
|
||||||
|
|||||||
@@ -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,
|
'/Library/Frameworks/Python.framework/Versions/%s/bin' % config.version,
|
||||||
env['PATH'],
|
env['PATH'],
|
||||||
])
|
])
|
||||||
|
env = environment.as_dictionary(prev_environment=env)
|
||||||
|
|
||||||
python = 'python3' if config.version[0] == '3' else 'python2'
|
python = 'python3' if config.version[0] == '3' else 'python2'
|
||||||
pip = 'pip3' if config.version[0] == '3' else 'pip2'
|
pip = 'pip3' if config.version[0] == '3' else 'pip2'
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be
|
|||||||
os.path.join(config.path, 'Scripts'),
|
os.path.join(config.path, 'Scripts'),
|
||||||
env['PATH']
|
env['PATH']
|
||||||
])
|
])
|
||||||
|
env = environment.as_dictionary(prev_environment=env)
|
||||||
|
|
||||||
# for the logs - check we're running the right version of python
|
# for the logs - check we're running the right version of python
|
||||||
shell(['python', '--version'], env=env)
|
shell(['python', '--version'], env=env)
|
||||||
|
|||||||
Reference in New Issue
Block a user