rename opt to options

This commit is contained in:
Grzegorz Bokota
2020-04-08 12:54:58 +02:00
parent 8d7d41cd83
commit 13a8c549bf
3 changed files with 59 additions and 59 deletions
+21 -21
View File
@@ -76,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)] return [c for c in python_configurations if matches_platform(c.identifier) and build_selector(c.identifier)]
def build(opt: BuildOptions): def build(options: BuildOptions):
try: try:
subprocess.check_call(['docker', '--version']) subprocess.check_call(['docker', '--version'])
except Exception: except Exception:
@@ -86,14 +86,14 @@ def build(opt: BuildOptions):
file=sys.stderr) file=sys.stderr)
exit(2) exit(2)
python_configurations = get_python_configurations(opt.build_selector) python_configurations = get_python_configurations(options.build_selector)
platforms = [ platforms = [
('cp', 'manylinux_x86_64', opt.manylinux_images['x86_64']), ('cp', 'manylinux_x86_64', options.manylinux_images['x86_64']),
('cp', 'manylinux_i686', opt.manylinux_images['i686']), ('cp', 'manylinux_i686', options.manylinux_images['i686']),
('cp', 'manylinux_aarch64', opt.manylinux_images['aarch64']), ('cp', 'manylinux_aarch64', options.manylinux_images['aarch64']),
('cp', 'manylinux_ppc64le', opt.manylinux_images['ppc64le']), ('cp', 'manylinux_ppc64le', options.manylinux_images['ppc64le']),
('cp', 'manylinux_s390x', opt.manylinux_images['s390x']), ('cp', 'manylinux_s390x', options.manylinux_images['s390x']),
('pp', 'manylinux_x86_64', opt.manylinux_images['pypy_x86_64']), ('pp', 'manylinux_x86_64', options.manylinux_images['pypy_x86_64']),
] ]
for implementation, platform_tag, docker_image in platforms: for implementation, platform_tag, docker_image in platforms:
@@ -112,14 +112,14 @@ def build(opt: BuildOptions):
'/bin/bash']) '/bin/bash'])
call(['docker', 'cp', call(['docker', 'cp',
os.path.abspath(opt.project_dir) + '/.', os.path.abspath(options.project_dir) + '/.',
container_name + ':/project']) container_name + ':/project'])
call(['docker', 'start', container_name]) call(['docker', 'start', container_name])
for config in platform_configs: for config in platform_configs:
if opt.dependency_constraints: if options.dependency_constraints:
constraints_file = opt.dependency_constraints.get_for_python_version(config.version) constraints_file = options.dependency_constraints.get_for_python_version(config.version)
# `docker cp` causes 'no space left on device' error when # `docker cp` causes 'no space left on device' error when
# a container is running and the host filesystem is # a container is running and the host filesystem is
@@ -234,32 +234,32 @@ def build(opt: BuildOptions):
done done
'''.format( '''.format(
config_python_bin=config.path + '/bin', config_python_bin=config.path + '/bin',
test_requires=' '.join(opt.test_requires), test_requires=' '.join(options.test_requires),
test_extras=opt.test_extras, test_extras=options.test_extras,
test_command=shlex.quote( test_command=shlex.quote(
prepare_command(opt.test_command, project='/project') if opt.test_command else '' prepare_command(options.test_command, project='/project') if options.test_command else ''
), ),
before_build=shlex.quote( before_build=shlex.quote(
prepare_command(opt.before_build, project='/project') if opt.before_build else '' prepare_command(options.before_build, project='/project') if options.before_build else ''
), ),
build_verbosity_flag=' '.join(get_build_verbosity_extra_flags(opt.build_verbosity)), build_verbosity_flag=' '.join(get_build_verbosity_extra_flags(options.build_verbosity)),
repair_command=shlex.quote( repair_command=shlex.quote(
prepare_command(opt.repair_command, wheel='"$1"', dest_dir='/tmp/repaired_wheels') if opt.repair_command else '' prepare_command(options.repair_command, wheel='"$1"', dest_dir='/tmp/repaired_wheels') if options.repair_command else ''
), ),
environment_exports='\n'.join(opt.environment.as_shell_commands()), environment_exports='\n'.join(options.environment.as_shell_commands()),
uid=os.getuid(), uid=os.getuid(),
gid=os.getgid(), gid=os.getgid(),
before_test=shlex.quote( before_test=shlex.quote(
prepare_command(opt.before_test, project='/project') if opt.before_test else '' prepare_command(options.before_test, project='/project') if options.before_test else ''
), ),
dependency_install_flags='-c /constraints.txt' if opt.dependency_constraints else '', dependency_install_flags='-c /constraints.txt' if options.dependency_constraints else '',
) )
) )
# copy the output back into the host # copy the output back into the host
call(['docker', 'cp', call(['docker', 'cp',
container_name + ':/output/.', container_name + ':/output/.',
os.path.abspath(opt.output_dir)]) os.path.abspath(options.output_dir)])
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
exit(1) exit(1)
finally: finally:
+19 -19
View File
@@ -167,48 +167,48 @@ def setup_python(python_configuration, dependency_constraint_flags, environment)
return env return env
def build(opt: BuildOptions): def build(options: BuildOptions):
abs_project_dir = os.path.abspath(opt.project_dir) abs_project_dir = os.path.abspath(options.project_dir)
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') temp_dir = tempfile.mkdtemp(prefix='cibuildwheel')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel') built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel') repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
python_configurations = get_python_configurations(opt.build_selector) python_configurations = get_python_configurations(options.build_selector)
for config in python_configurations: for config in python_configurations:
dependency_constraint_flags = [] dependency_constraint_flags = []
if opt.dependency_constraints: if options.dependency_constraints:
dependency_constraint_flags = [ dependency_constraint_flags = [
'-c', opt.dependency_constraints.get_for_python_version(config.version) '-c', options.dependency_constraints.get_for_python_version(config.version)
] ]
env = setup_python(config, dependency_constraint_flags, opt.environment) env = setup_python(config, dependency_constraint_flags, options.environment)
# run the before_build command # run the before_build command
if opt.before_build: if options.before_build:
before_build_prepared = prepare_command(opt.before_build, project=abs_project_dir) before_build_prepared = prepare_command(options.before_build, project=abs_project_dir)
call(before_build_prepared, env=env, shell=True) call(before_build_prepared, env=env, shell=True)
# build the wheel # build the wheel
if os.path.exists(built_wheel_dir): if os.path.exists(built_wheel_dir):
shutil.rmtree(built_wheel_dir) shutil.rmtree(built_wheel_dir)
os.makedirs(built_wheel_dir) os.makedirs(built_wheel_dir)
call(['pip', 'wheel', abs_project_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(opt.build_verbosity), env=env) call(['pip', 'wheel', abs_project_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0] built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0]
# repair the wheel # repair the wheel
if os.path.exists(repaired_wheel_dir): if os.path.exists(repaired_wheel_dir):
shutil.rmtree(repaired_wheel_dir) shutil.rmtree(repaired_wheel_dir)
os.makedirs(repaired_wheel_dir) os.makedirs(repaired_wheel_dir)
if built_wheel.endswith('none-any.whl') or not opt.repair_command: if built_wheel.endswith('none-any.whl') or not options.repair_command:
# pure Python wheel or empty repair command # pure Python wheel or empty repair command
shutil.move(built_wheel, repaired_wheel_dir) shutil.move(built_wheel, repaired_wheel_dir)
else: else:
repair_command_prepared = prepare_command(opt.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir) repair_command_prepared = prepare_command(options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir)
call(repair_command_prepared, env=env, shell=True) call(repair_command_prepared, env=env, shell=True)
repaired_wheel = glob(os.path.join(repaired_wheel_dir, '*.whl'))[0] repaired_wheel = glob(os.path.join(repaired_wheel_dir, '*.whl'))[0]
if opt.test_command: if options.test_command:
# set up a virtual environment to install and test from, to make sure # set up a virtual environment to install and test from, to make sure
# there are no dependencies that were pulled in at build time. # there are no dependencies that were pulled in at build time.
call(['pip', 'install', 'virtualenv'] + dependency_constraint_flags, env=env) call(['pip', 'install', 'virtualenv'] + dependency_constraint_flags, env=env)
@@ -228,26 +228,26 @@ def build(opt: BuildOptions):
# check that we are using the Python from the virtual environment # check that we are using the Python from the virtual environment
call(['which', 'python'], env=virtualenv_env) call(['which', 'python'], env=virtualenv_env)
if opt.before_test: if options.before_test:
before_test_prepared = prepare_command(opt.before_test, project=abs_project_dir) before_test_prepared = prepare_command(options.before_test, project=abs_project_dir)
call(before_test_prepared, env=virtualenv_env, shell=True) call(before_test_prepared, env=virtualenv_env, shell=True)
# install the wheel # install the wheel
call(['pip', 'install', repaired_wheel + opt.test_extras], env=virtualenv_env) call(['pip', 'install', repaired_wheel + options.test_extras], env=virtualenv_env)
# test the wheel # test the wheel
if opt.test_requires: if options.test_requires:
call(['pip', 'install'] + opt.test_requires, env=virtualenv_env) call(['pip', 'install'] + options.test_requires, env=virtualenv_env)
# run the tests from $HOME, with an absolute path in the command # run the tests from $HOME, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel # (this ensures that Python runs the tests against the installed wheel
# and not the repo code) # and not the repo code)
test_command_prepared = prepare_command(opt.test_command, project=abs_project_dir) test_command_prepared = prepare_command(options.test_command, project=abs_project_dir)
call(test_command_prepared, cwd=os.environ['HOME'], env=virtualenv_env, shell=True) call(test_command_prepared, cwd=os.environ['HOME'], env=virtualenv_env, shell=True)
# clean up # clean up
shutil.rmtree(venv_dir) shutil.rmtree(venv_dir)
# we're all done here; move it to output (overwrite existing) # we're all done here; move it to output (overwrite existing)
dst = os.path.join(opt.output_dir, os.path.basename(repaired_wheel)) dst = os.path.join(options.output_dir, os.path.basename(repaired_wheel))
shutil.move(repaired_wheel, dst) shutil.move(repaired_wheel, dst)
+19 -19
View File
@@ -142,8 +142,8 @@ def setup_python(python_configuration, dependency_constraint_flags, environment)
return env return env
def build(opt: BuildOptions): def build(options: BuildOptions):
abs_project_dir = os.path.abspath(opt.project_dir) abs_project_dir = os.path.abspath(options.project_dir)
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') temp_dir = tempfile.mkdtemp(prefix='cibuildwheel')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel') built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel') repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
@@ -152,42 +152,42 @@ def build(opt: BuildOptions):
nuget = 'C:\\cibw\\nuget.exe' nuget = 'C:\\cibw\\nuget.exe'
download('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', nuget) download('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', nuget)
python_configurations = get_python_configurations(opt.build_selector) python_configurations = get_python_configurations(options.build_selector)
for config in python_configurations: for config in python_configurations:
dependency_constraint_flags = [] dependency_constraint_flags = []
if opt.dependency_constraints: if options.dependency_constraints:
dependency_constraint_flags = [ dependency_constraint_flags = [
'-c', opt.dependency_constraints.get_for_python_version(config.version) '-c', options.dependency_constraints.get_for_python_version(config.version)
] ]
# install Python # install Python
env = setup_python(config, dependency_constraint_flags, opt.environment) env = setup_python(config, dependency_constraint_flags, options.environment)
# run the before_build command # run the before_build command
if opt.before_build: if options.before_build:
before_build_prepared = prepare_command(opt.before_build, project=abs_project_dir) before_build_prepared = prepare_command(options.before_build, project=abs_project_dir)
shell([before_build_prepared], env=env) shell([before_build_prepared], env=env)
# build the wheel # build the wheel
if os.path.exists(built_wheel_dir): if os.path.exists(built_wheel_dir):
shutil.rmtree(built_wheel_dir) shutil.rmtree(built_wheel_dir)
os.makedirs(built_wheel_dir) os.makedirs(built_wheel_dir)
shell(['pip', 'wheel', abs_project_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(opt.build_verbosity), env=env) shell(['pip', 'wheel', abs_project_dir, '-w', built_wheel_dir, '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0] built_wheel = glob(os.path.join(built_wheel_dir, '*.whl'))[0]
# repair the wheel # repair the wheel
if os.path.exists(repaired_wheel_dir): if os.path.exists(repaired_wheel_dir):
shutil.rmtree(repaired_wheel_dir) shutil.rmtree(repaired_wheel_dir)
os.makedirs(repaired_wheel_dir) os.makedirs(repaired_wheel_dir)
if built_wheel.endswith('none-any.whl') or not opt.repair_command: if built_wheel.endswith('none-any.whl') or not options.repair_command:
# pure Python wheel or empty repair command # pure Python wheel or empty repair command
shutil.move(built_wheel, repaired_wheel_dir) shutil.move(built_wheel, repaired_wheel_dir)
else: else:
repair_command_prepared = prepare_command(opt.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir) repair_command_prepared = prepare_command(options.repair_command, wheel=built_wheel, dest_dir=repaired_wheel_dir)
shell([repair_command_prepared], env=env) shell([repair_command_prepared], env=env)
repaired_wheel = glob(os.path.join(repaired_wheel_dir, '*.whl'))[0] repaired_wheel = glob(os.path.join(repaired_wheel_dir, '*.whl'))[0]
if opt.test_command: if options.test_command:
# set up a virtual environment to install and test from, to make sure # set up a virtual environment to install and test from, to make sure
# there are no dependencies that were pulled in at build time. # there are no dependencies that were pulled in at build time.
shell(['pip', 'install', 'virtualenv'] + dependency_constraint_flags, env=env) shell(['pip', 'install', 'virtualenv'] + dependency_constraint_flags, env=env)
@@ -212,28 +212,28 @@ def build(opt: BuildOptions):
# check that we are using the Python from the virtual environment # check that we are using the Python from the virtual environment
shell(['which', 'python'], env=virtualenv_env) shell(['which', 'python'], env=virtualenv_env)
if opt.before_test: if options.before_test:
before_test_prepared = prepare_command(opt.before_test, project=abs_project_dir) before_test_prepared = prepare_command(options.before_test, project=abs_project_dir)
shell([before_test_prepared], env=virtualenv_env) shell([before_test_prepared], env=virtualenv_env)
# install the wheel # install the wheel
shell(['pip', 'install', repaired_wheel + opt.test_extras], env=virtualenv_env) shell(['pip', 'install', repaired_wheel + options.test_extras], env=virtualenv_env)
# test the wheel # test the wheel
if opt.test_requires: if options.test_requires:
shell(['pip', 'install'] + opt.test_requires, env=virtualenv_env) shell(['pip', 'install'] + options.test_requires, env=virtualenv_env)
# run the tests from c:\, with an absolute path in the command # run the tests from c:\, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel # (this ensures that Python runs the tests against the installed wheel
# and not the repo code) # and not the repo code)
test_command_prepared = prepare_command(opt.test_command, project=abs_project_dir) test_command_prepared = prepare_command(options.test_command, project=abs_project_dir)
shell([test_command_prepared], cwd='c:\\', env=virtualenv_env) shell([test_command_prepared], cwd='c:\\', env=virtualenv_env)
# clean up # clean up
shutil.rmtree(venv_dir) shutil.rmtree(venv_dir)
# we're all done here; move it to output (remove if already exists) # we're all done here; move it to output (remove if already exists)
dst = os.path.join(opt.output_dir, os.path.basename(repaired_wheel)) dst = os.path.join(options.output_dir, os.path.basename(repaired_wheel))
if os.path.isfile(dst): if os.path.isfile(dst):
os.remove(dst) os.remove(dst)
shutil.move(repaired_wheel, dst) shutil.move(repaired_wheel, dst)