pack build argument in named tuple, introduce typing arguments

This commit is contained in:
Grzegorz Bokota
2020-04-08 12:54:58 +02:00
parent 3836bb2919
commit 6554c3cf86
7 changed files with 124 additions and 100 deletions
+22 -21
View File
@@ -10,6 +10,7 @@ from collections import namedtuple
from .util import (
get_build_verbosity_extra_flags,
prepare_command,
BuildOptions
)
@@ -75,7 +76,7 @@ def get_python_configurations(build_selector):
return [c for c in python_configurations if matches_platform(c.identifier) and build_selector(c.identifier)]
def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, manylinux_images, dependency_constraints):
def build(opt: BuildOptions):
try:
subprocess.check_call(['docker', '--version'])
except Exception:
@@ -85,14 +86,14 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
file=sys.stderr)
exit(2)
python_configurations = get_python_configurations(build_selector)
python_configurations = get_python_configurations(opt.build_selector)
platforms = [
('cp', 'manylinux_x86_64', manylinux_images['x86_64']),
('cp', 'manylinux_i686', manylinux_images['i686']),
('cp', 'manylinux_aarch64', manylinux_images['aarch64']),
('cp', 'manylinux_ppc64le', manylinux_images['ppc64le']),
('cp', 'manylinux_s390x', manylinux_images['s390x']),
('pp', 'manylinux_x86_64', manylinux_images['pypy_x86_64']),
('cp', 'manylinux_x86_64', opt.manylinux_images['x86_64']),
('cp', 'manylinux_i686', opt.manylinux_images['i686']),
('cp', 'manylinux_aarch64', opt.manylinux_images['aarch64']),
('cp', 'manylinux_ppc64le', opt.manylinux_images['ppc64le']),
('cp', 'manylinux_s390x', opt.manylinux_images['s390x']),
('pp', 'manylinux_x86_64', opt.manylinux_images['pypy_x86_64']),
]
for implementation, platform_tag, docker_image in platforms:
@@ -111,14 +112,14 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
'/bin/bash'])
call(['docker', 'cp',
os.path.abspath(project_dir) + '/.',
os.path.abspath(opt.project_dir) + '/.',
container_name + ':/project'])
call(['docker', 'start', container_name])
for config in platform_configs:
if dependency_constraints:
constraints_file = dependency_constraints.get_for_python_version(config.version)
if opt.dependency_constraints:
constraints_file = opt.dependency_constraints.get_for_python_version(config.version)
# `docker cp` causes 'no space left on device' error when
# a container is running and the host filesystem is
@@ -233,32 +234,32 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
done
'''.format(
config_python_bin=config.path + '/bin',
test_requires=' '.join(test_requires),
test_extras=test_extras,
test_requires=' '.join(opt.test_requires),
test_extras=opt.test_extras,
test_command=shlex.quote(
prepare_command(test_command, project='/project') if test_command else ''
prepare_command(opt.test_command, project='/project') if opt.test_command else ''
),
before_build=shlex.quote(
prepare_command(before_build, project='/project') if before_build else ''
prepare_command(opt.before_build, project='/project') if opt.before_build else ''
),
build_verbosity_flag=' '.join(get_build_verbosity_extra_flags(build_verbosity)),
build_verbosity_flag=' '.join(get_build_verbosity_extra_flags(opt.build_verbosity)),
repair_command=shlex.quote(
prepare_command(repair_command, wheel='"$1"', dest_dir='/tmp/repaired_wheels') if repair_command else ''
prepare_command(opt.repair_command, wheel='"$1"', dest_dir='/tmp/repaired_wheels') if opt.repair_command else ''
),
environment_exports='\n'.join(environment.as_shell_commands()),
environment_exports='\n'.join(opt.environment.as_shell_commands()),
uid=os.getuid(),
gid=os.getgid(),
before_test=shlex.quote(
prepare_command(before_test, project='/project') if before_test else ''
prepare_command(opt.before_test, project='/project') if opt.before_test else ''
),
dependency_install_flags='-c /constraints.txt' if dependency_constraints else '',
dependency_install_flags='-c /constraints.txt' if opt.dependency_constraints else '',
)
)
# copy the output back into the host
call(['docker', 'cp',
container_name + ':/output/.',
os.path.abspath(output_dir)])
os.path.abspath(opt.output_dir)])
except subprocess.CalledProcessError:
exit(1)
finally: