Remove str() calls in call/shell functions using destructuring syntax
This commit is contained in:
+28
-21
@@ -4,27 +4,22 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from os import PathLike
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Dict, List, NamedTuple, Optional, Sequence, Union
|
||||||
from typing import Dict, List, Optional, NamedTuple, Union
|
|
||||||
|
|
||||||
from .environment import ParsedEnvironment
|
from .environment import ParsedEnvironment
|
||||||
from .util import (
|
from .util import (BuildOptions, BuildSelector, download,
|
||||||
BuildOptions,
|
get_build_verbosity_extra_flags, get_pip_script,
|
||||||
BuildSelector,
|
prepare_command)
|
||||||
download,
|
|
||||||
get_build_verbosity_extra_flags,
|
|
||||||
get_pip_script,
|
|
||||||
prepare_command,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def call(args: Union[str, List[str]], env: Optional[Dict[str, str]] = None, cwd: Optional[str] = None, shell: bool = False) -> int:
|
def call(args: Union[str, Sequence[Union[str, PathLike]]], env: Optional[Dict[str, str]] = None, cwd: Optional[str] = None, shell: bool = False) -> int:
|
||||||
# print the command executing for the logs
|
# print the command executing for the logs
|
||||||
if shell:
|
if shell:
|
||||||
print(f'+ {args}')
|
print(f'+ {args}')
|
||||||
else:
|
else:
|
||||||
print('+ ' + ' '.join(shlex.quote(a) for a in args))
|
print('+ ' + ' '.join(shlex.quote(str(a)) for a in args))
|
||||||
|
|
||||||
return subprocess.check_call(args, env=env, cwd=cwd, shell=shell)
|
return subprocess.check_call(args, env=env, cwd=cwd, shell=shell)
|
||||||
|
|
||||||
@@ -103,7 +98,7 @@ def install_pypy(version: str, url: str) -> Path:
|
|||||||
if not installation_path.exists():
|
if not installation_path.exists():
|
||||||
downloaded_tar_bz2 = Path("/tmp") / pypy_tar_bz2
|
downloaded_tar_bz2 = Path("/tmp") / pypy_tar_bz2
|
||||||
download(url, downloaded_tar_bz2)
|
download(url, downloaded_tar_bz2)
|
||||||
call(['tar', '-C', '/tmp', '-xf', str(downloaded_tar_bz2)])
|
call(['tar', '-C', '/tmp', '-xf', downloaded_tar_bz2])
|
||||||
|
|
||||||
installation_bin_path = installation_path / 'bin'
|
installation_bin_path = installation_path / 'bin'
|
||||||
python_executable = 'pypy3' if version[0] == '3' else 'pypy'
|
python_executable = 'pypy3' if version[0] == '3' else 'pypy'
|
||||||
@@ -113,7 +108,9 @@ def install_pypy(version: str, url: str) -> Path:
|
|||||||
return installation_bin_path
|
return installation_bin_path
|
||||||
|
|
||||||
|
|
||||||
def setup_python(python_configuration: PythonConfiguration, dependency_constraint_flags: List[str], environment: ParsedEnvironment) -> Dict[str, str]:
|
def setup_python(python_configuration: PythonConfiguration,
|
||||||
|
dependency_constraint_flags: Sequence[Union[str, PathLike]],
|
||||||
|
environment: ParsedEnvironment) -> Dict[str, str]:
|
||||||
if python_configuration.identifier.startswith('cp'):
|
if python_configuration.identifier.startswith('cp'):
|
||||||
installation_bin_path = install_cpython(python_configuration.version, python_configuration.url)
|
installation_bin_path = install_cpython(python_configuration.version, python_configuration.url)
|
||||||
elif python_configuration.identifier.startswith('pp'):
|
elif python_configuration.identifier.startswith('pp'):
|
||||||
@@ -146,7 +143,7 @@ def setup_python(python_configuration: PythonConfiguration, dependency_constrain
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# install pip & wheel
|
# install pip & wheel
|
||||||
call(['python', str(get_pip_script)] + dependency_constraint_flags, env=env, cwd="/tmp")
|
call(['python', get_pip_script, *dependency_constraint_flags], env=env, cwd="/tmp")
|
||||||
assert (installation_bin_path / 'pip').exists()
|
assert (installation_bin_path / 'pip').exists()
|
||||||
call(['which', 'pip'], env=env)
|
call(['which', 'pip'], env=env)
|
||||||
call(['pip', '--version'], env=env)
|
call(['pip', '--version'], env=env)
|
||||||
@@ -154,7 +151,7 @@ def setup_python(python_configuration: PythonConfiguration, dependency_constrain
|
|||||||
if which_pip != '/tmp/cibw_bin/pip':
|
if which_pip != '/tmp/cibw_bin/pip':
|
||||||
print("cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", file=sys.stderr)
|
print("cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", file=sys.stderr)
|
||||||
exit(1)
|
exit(1)
|
||||||
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate'] + dependency_constraint_flags, env=env)
|
call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate', *dependency_constraint_flags], env=env)
|
||||||
|
|
||||||
# Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it.
|
# Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it.
|
||||||
# CPython 3.5 defaults to 10.6, and pypy defaults to 10.7, causing
|
# CPython 3.5 defaults to 10.6, and pypy defaults to 10.7, causing
|
||||||
@@ -184,10 +181,10 @@ def build(options: BuildOptions) -> None:
|
|||||||
python_configurations = get_python_configurations(options.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: Sequence[Union[str, PathLike]] = []
|
||||||
if options.dependency_constraints:
|
if options.dependency_constraints:
|
||||||
dependency_constraint_flags = [
|
dependency_constraint_flags = [
|
||||||
'-c', str(options.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, options.environment)
|
env = setup_python(config, dependency_constraint_flags, options.environment)
|
||||||
@@ -201,9 +198,19 @@ def build(options: BuildOptions) -> None:
|
|||||||
if built_wheel_dir.exists():
|
if built_wheel_dir.exists():
|
||||||
shutil.rmtree(built_wheel_dir)
|
shutil.rmtree(built_wheel_dir)
|
||||||
built_wheel_dir.mkdir(parents=True)
|
built_wheel_dir.mkdir(parents=True)
|
||||||
|
|
||||||
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
|
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
|
||||||
# see https://github.com/joerick/cibuildwheel/pull/369
|
# see https://github.com/joerick/cibuildwheel/pull/369
|
||||||
call(['pip', 'wheel', str(options.package_dir.resolve()), '-w', str(built_wheel_dir), '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
|
call(
|
||||||
|
[
|
||||||
|
'pip', 'wheel',
|
||||||
|
options.package_dir.resolve(),
|
||||||
|
'-w', built_wheel_dir,
|
||||||
|
'--no-deps',
|
||||||
|
*get_build_verbosity_extra_flags(options.build_verbosity)
|
||||||
|
],
|
||||||
|
env=env,
|
||||||
|
)
|
||||||
built_wheel = next(built_wheel_dir.glob('*.whl'))
|
built_wheel = next(built_wheel_dir.glob('*.whl'))
|
||||||
|
|
||||||
# repair the wheel
|
# repair the wheel
|
||||||
@@ -221,12 +228,12 @@ def build(options: BuildOptions) -> None:
|
|||||||
if options.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)
|
||||||
venv_dir = Path(tempfile.mkdtemp())
|
venv_dir = Path(tempfile.mkdtemp())
|
||||||
|
|
||||||
# Use --no-download to ensure determinism by using seed libraries
|
# Use --no-download to ensure determinism by using seed libraries
|
||||||
# built into virtualenv
|
# built into virtualenv
|
||||||
call(['python', '-m', 'virtualenv', '--no-download', str(venv_dir)], env=env)
|
call(['python', '-m', 'virtualenv', '--no-download', venv_dir], env=env)
|
||||||
|
|
||||||
virtualenv_env = env.copy()
|
virtualenv_env = env.copy()
|
||||||
virtualenv_env['PATH'] = os.pathsep.join([
|
virtualenv_env['PATH'] = os.pathsep.join([
|
||||||
|
|||||||
+30
-24
@@ -3,29 +3,25 @@ import shutil
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from os import PathLike
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Dict, List, NamedTuple, Optional, Sequence, Union
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from typing import Dict, List, Optional, NamedTuple
|
|
||||||
|
|
||||||
from .environment import ParsedEnvironment
|
from .environment import ParsedEnvironment
|
||||||
from .util import (
|
from .util import (BuildOptions, BuildSelector, download,
|
||||||
BuildOptions,
|
get_build_verbosity_extra_flags, get_pip_script,
|
||||||
BuildSelector,
|
prepare_command)
|
||||||
download,
|
|
||||||
get_build_verbosity_extra_flags,
|
|
||||||
get_pip_script,
|
|
||||||
prepare_command,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
IS_RUNNING_ON_AZURE = Path('C:\\hostedtoolcache').exists()
|
IS_RUNNING_ON_AZURE = Path('C:\\hostedtoolcache').exists()
|
||||||
IS_RUNNING_ON_TRAVIS = os.environ.get('TRAVIS_OS_NAME') == 'windows'
|
IS_RUNNING_ON_TRAVIS = os.environ.get('TRAVIS_OS_NAME') == 'windows'
|
||||||
|
|
||||||
|
|
||||||
def shell(args: List[str], env: Optional[Dict[str, str]] = None, cwd: Optional[str] = None) -> int:
|
def shell(args: Sequence[Union[str, PathLike]], env: Optional[Dict[str, str]] = None,
|
||||||
print('+ ' + ' '.join(args))
|
cwd: Optional[str] = None) -> int:
|
||||||
return subprocess.check_call(' '.join(args), env=env, cwd=cwd, shell=True)
|
command = ' '.join(str(a) for a in args)
|
||||||
|
print(f'+ {command}')
|
||||||
|
return subprocess.check_call(command, env=env, cwd=cwd, shell=True)
|
||||||
|
|
||||||
|
|
||||||
def get_nuget_args(version: str, arch: str) -> List[str]:
|
def get_nuget_args(version: str, arch: str) -> List[str]:
|
||||||
@@ -79,7 +75,7 @@ def extract_zip(zip_src: Path, dest: Path) -> None:
|
|||||||
def install_cpython(version: str, arch: str, nuget: Path) -> Path:
|
def install_cpython(version: str, arch: str, nuget: Path) -> Path:
|
||||||
nuget_args = get_nuget_args(version, arch)
|
nuget_args = get_nuget_args(version, arch)
|
||||||
installation_path = Path(nuget_args[-1]) / (nuget_args[0] + '.' + version) / 'tools'
|
installation_path = Path(nuget_args[-1]) / (nuget_args[0] + '.' + version) / 'tools'
|
||||||
shell([str(nuget), 'install'] + nuget_args)
|
shell([nuget, 'install', *nuget_args])
|
||||||
return installation_path
|
return installation_path
|
||||||
|
|
||||||
|
|
||||||
@@ -100,7 +96,7 @@ def install_pypy(version: str, arch: str, url: str) -> Path:
|
|||||||
return installation_path
|
return installation_path
|
||||||
|
|
||||||
|
|
||||||
def setup_python(python_configuration: PythonConfiguration, dependency_constraint_flags: List[str], environment: ParsedEnvironment) -> Dict[str, str]:
|
def setup_python(python_configuration: PythonConfiguration, dependency_constraint_flags: Sequence[Union[str, PathLike]], environment: ParsedEnvironment) -> Dict[str, str]:
|
||||||
nuget = Path('C:\\cibw\\nuget.exe')
|
nuget = Path('C:\\cibw\\nuget.exe')
|
||||||
if not nuget.exists():
|
if not nuget.exists():
|
||||||
download('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', nuget)
|
download('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', nuget)
|
||||||
@@ -138,7 +134,7 @@ def setup_python(python_configuration: PythonConfiguration, dependency_constrain
|
|||||||
|
|
||||||
# make sure pip is installed
|
# make sure pip is installed
|
||||||
if not (installation_path / 'Scripts' / 'pip.exe').exists():
|
if not (installation_path / 'Scripts' / 'pip.exe').exists():
|
||||||
shell(['python', str(get_pip_script)] + dependency_constraint_flags, env=env, cwd="C:\\cibw")
|
shell(['python', get_pip_script, *dependency_constraint_flags], env=env, cwd="C:\\cibw")
|
||||||
assert (installation_path / 'Scripts' / 'pip.exe').exists()
|
assert (installation_path / 'Scripts' / 'pip.exe').exists()
|
||||||
where_pip = subprocess.check_output(['where', 'pip'], env=env, universal_newlines=True).splitlines()[0].strip()
|
where_pip = subprocess.check_output(['where', 'pip'], env=env, universal_newlines=True).splitlines()[0].strip()
|
||||||
if where_pip.strip() != str(installation_path / 'Scripts' / 'pip.exe'):
|
if where_pip.strip() != str(installation_path / 'Scripts' / 'pip.exe'):
|
||||||
@@ -146,9 +142,9 @@ def setup_python(python_configuration: PythonConfiguration, dependency_constrain
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# prepare the Python environment
|
# prepare the Python environment
|
||||||
shell(['python', '-m', 'pip', 'install', '--upgrade', 'pip'] + dependency_constraint_flags, env=env)
|
shell(['python', '-m', 'pip', 'install', '--upgrade', 'pip', *dependency_constraint_flags], env=env)
|
||||||
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
|
return env
|
||||||
|
|
||||||
@@ -169,10 +165,10 @@ def build(options: BuildOptions) -> None:
|
|||||||
|
|
||||||
python_configurations = get_python_configurations(options.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: Sequence[Union[str, PathLike]] = []
|
||||||
if options.dependency_constraints:
|
if options.dependency_constraints:
|
||||||
dependency_constraint_flags = [
|
dependency_constraint_flags = [
|
||||||
'-c', str(options.dependency_constraints.get_for_python_version(config.version))
|
'-c', options.dependency_constraints.get_for_python_version(config.version)
|
||||||
]
|
]
|
||||||
|
|
||||||
# install Python
|
# install Python
|
||||||
@@ -189,7 +185,17 @@ def build(options: BuildOptions) -> None:
|
|||||||
built_wheel_dir.mkdir(parents=True)
|
built_wheel_dir.mkdir(parents=True)
|
||||||
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
|
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
|
||||||
# see https://github.com/joerick/cibuildwheel/pull/369
|
# see https://github.com/joerick/cibuildwheel/pull/369
|
||||||
shell(['pip', 'wheel', str(options.package_dir.resolve()), '-w', str(built_wheel_dir), '--no-deps'] + get_build_verbosity_extra_flags(options.build_verbosity), env=env)
|
shell(
|
||||||
|
[
|
||||||
|
'pip', 'wheel',
|
||||||
|
options.package_dir.resolve(),
|
||||||
|
'-w', built_wheel_dir,
|
||||||
|
'--no-deps',
|
||||||
|
*get_build_verbosity_extra_flags(options.build_verbosity)
|
||||||
|
],
|
||||||
|
env=env,
|
||||||
|
)
|
||||||
|
|
||||||
built_wheel = next(built_wheel_dir.glob('*.whl'))
|
built_wheel = next(built_wheel_dir.glob('*.whl'))
|
||||||
|
|
||||||
# repair the wheel
|
# repair the wheel
|
||||||
@@ -207,12 +213,12 @@ def build(options: BuildOptions) -> None:
|
|||||||
if options.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)
|
||||||
venv_dir = Path(tempfile.mkdtemp())
|
venv_dir = Path(tempfile.mkdtemp())
|
||||||
|
|
||||||
# Use --no-download to ensure determinism by using seed libraries
|
# Use --no-download to ensure determinism by using seed libraries
|
||||||
# built into virtualenv
|
# built into virtualenv
|
||||||
shell(['python', '-m', 'virtualenv', '--no-download', str(venv_dir)], env=env)
|
shell(['python', '-m', 'virtualenv', '--no-download', venv_dir], env=env)
|
||||||
|
|
||||||
virtualenv_env = env.copy()
|
virtualenv_env = env.copy()
|
||||||
virtualenv_env['PATH'] = os.pathsep.join([
|
virtualenv_env['PATH'] = os.pathsep.join([
|
||||||
|
|||||||
Reference in New Issue
Block a user