move python setup to separated function

This commit is contained in:
Grzegorz Bokota
2020-04-05 16:03:35 +02:00
parent 317c0f4baf
commit 8b465bc94a
2 changed files with 123 additions and 106 deletions
+22 -15
View File
@@ -108,19 +108,11 @@ def install_pypy(version, url):
return installation_bin_path return installation_bin_path
def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, dependency_constraints): def setup_python(python_configuration, dependency_constraints, environment):
abs_project_dir = os.path.abspath(project_dir) if python_configuration.identifier.startswith('cp'):
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') installation_bin_path = install_cpython(python_configuration.version, python_configuration.url)
built_wheel_dir = os.path.join(temp_dir, 'built_wheel') elif python_configuration.identifier.startswith('pp'):
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel') installation_bin_path = install_pypy(python_configuration.version, python_configuration.url)
python_configurations = get_python_configurations(build_selector)
for config in python_configurations:
if config.identifier.startswith('cp'):
installation_bin_path = install_cpython(config.version, config.url)
elif config.identifier.startswith('pp'):
installation_bin_path = install_pypy(config.version, config.url)
else: else:
raise ValueError("Unknown Python implementation") raise ValueError("Unknown Python implementation")
@@ -151,7 +143,7 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
dependency_constraint_flags = [] dependency_constraint_flags = []
if dependency_constraints: if dependency_constraints:
dependency_constraint_flags = [ dependency_constraint_flags = [
'-c', dependency_constraints.get_for_python_version(config.version) '-c', dependency_constraints.get_for_python_version(python_configuration.version)
] ]
# install pip & wheel # install pip & wheel
@@ -166,7 +158,7 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate'] + dependency_constraint_flags, env=env) call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate'] + dependency_constraint_flags, env=env)
# setup target platform, only required for python 3.5 # setup target platform, only required for python 3.5
if config.version == '3.5': if python_configuration.version == '3.5':
if '_PYTHON_HOST_PLATFORM' not in env: if '_PYTHON_HOST_PLATFORM' not in env:
# cross-compilation platform override # cross-compilation platform override
env['_PYTHON_HOST_PLATFORM'] = 'macosx-10.9-x86_64' env['_PYTHON_HOST_PLATFORM'] = 'macosx-10.9-x86_64'
@@ -176,6 +168,21 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
if 'MACOSX_DEPLOYMENT_TARGET' not in env: if 'MACOSX_DEPLOYMENT_TARGET' not in env:
env['MACOSX_DEPLOYMENT_TARGET'] = '10.9' env['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
return env, dependency_constraint_flags
def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, dependency_constraints):
abs_project_dir = os.path.abspath(project_dir)
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
python_configurations = get_python_configurations(build_selector)
for config in python_configurations:
env, dependency_constraint_flags = setup_python(config, dependency_constraints, environment)
# run the before_build command # run the before_build command
if before_build: if before_build:
before_build_prepared = prepare_command(before_build, project=abs_project_dir) before_build_prepared = prepare_command(before_build, project=abs_project_dir)
+27 -17
View File
@@ -89,23 +89,15 @@ def install_pypy(version, arch, url):
return installation_path return installation_path
def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, dependency_constraints): def setup_python(python_configuration, dependency_constraints, environment):
abs_project_dir = os.path.abspath(project_dir)
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
# install nuget as best way to provide python
nuget = 'C:\\cibw\\nuget.exe' nuget = 'C:\\cibw\\nuget.exe'
if not os.path.exists(nuget):
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(build_selector) if python_configuration.identifier.startswith('cp'):
for config in python_configurations: installation_path = install_cpython(python_configuration.version, python_configuration.arch, nuget)
# install Python elif python_configuration.identifier.startswith('pp'):
if config.identifier.startswith('cp'): installation_path = install_pypy(python_configuration.version, python_configuration.arch, python_configuration.url)
installation_path = install_cpython(config.version, config.arch, nuget)
elif config.identifier.startswith('pp'):
installation_path = install_pypy(config.version, config.arch, config.url)
else: else:
raise ValueError("Unknown Python implementation") raise ValueError("Unknown Python implementation")
@@ -113,8 +105,8 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
# set up PATH and environment variables for run_with_env # set up PATH and environment variables for run_with_env
env = os.environ.copy() env = os.environ.copy()
env['PYTHON_VERSION'] = config.version env['PYTHON_VERSION'] = python_configuration.version
env['PYTHON_ARCH'] = config.arch env['PYTHON_ARCH'] = python_configuration.arch
env['PATH'] = os.pathsep.join([ env['PATH'] = os.pathsep.join([
installation_path, installation_path,
os.path.join(installation_path, 'Scripts'), os.path.join(installation_path, 'Scripts'),
@@ -135,7 +127,7 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
dependency_constraint_flags = [] dependency_constraint_flags = []
if dependency_constraints: if dependency_constraints:
dependency_constraint_flags = [ dependency_constraint_flags = [
'-c', dependency_constraints.get_for_python_version(config.version) '-c', dependency_constraints.get_for_python_version(python_configuration.version)
] ]
# make sure pip is installed # make sure pip is installed
@@ -152,6 +144,24 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes
shell(['pip', '--version'], env=env) shell(['pip', '--version'], env=env)
shell(['pip', 'install', '--upgrade', 'setuptools', 'wheel'] + dependency_constraint_flags, env=env) shell(['pip', 'install', '--upgrade', 'setuptools', 'wheel'] + dependency_constraint_flags, env=env)
return env, dependency_constraint_flags
def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, dependency_constraints):
abs_project_dir = os.path.abspath(project_dir)
temp_dir = tempfile.mkdtemp(prefix='cibuildwheel')
built_wheel_dir = os.path.join(temp_dir, 'built_wheel')
repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel')
# install nuget as best way to provide python
nuget = 'C:\\cibw\\nuget.exe'
download('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', nuget)
python_configurations = get_python_configurations(build_selector)
for config in python_configurations:
# install Python
env, dependency_constraint_flags = setup_python(config, dependency_constraints, environment)
# run the before_build command # run the before_build command
if before_build: if before_build:
before_build_prepared = prepare_command(before_build, project=abs_project_dir) before_build_prepared = prepare_command(before_build, project=abs_project_dir)