Added majority of type annotations (to a by now outdated version)

This commit is contained in:
Yannick Jadoul
2020-05-06 23:55:54 +02:00
parent 185a1c09ad
commit 618f1cefae
7 changed files with 110 additions and 74 deletions
+22 -13
View File
@@ -5,6 +5,8 @@ import textwrap
import traceback
from configparser import ConfigParser
from typing import Any, Dict, List, Optional, Union, overload
import cibuildwheel
import cibuildwheel.linux
import cibuildwheel.macos
@@ -14,14 +16,20 @@ from cibuildwheel.environment import (
parse_environment,
)
from cibuildwheel.util import (
BuildOptions,
BuildSelector,
DependencyConstraints,
Unbuffered,
BuildOptions
)
def get_option_from_environment(option_name, platform=None, default=None):
@overload
def get_option_from_environment(option_name: str, platform: Optional[str], default: str) -> str:
...
@overload
def get_option_from_environment(option_name: str, platform: Optional[str] = None, default: None = None) -> Optional[str]:
...
def get_option_from_environment(option_name: str, platform: Optional[str] = None, default: Optional[str] = None) -> Optional[str]:
'''
Returns an option from the environment, optionally scoped by the platform.
@@ -39,13 +47,13 @@ def get_option_from_environment(option_name, platform=None, default=None):
return os.environ.get(option_name, default)
def strtobool(val):
def strtobool(val: str) -> bool:
if val.lower() in ('y', 'yes', 't', 'true', 'on', '1'):
return True
return False
def main():
def main() -> None:
parser = argparse.ArgumentParser(
description='Build wheels for all the platforms.',
epilog='''
@@ -114,7 +122,7 @@ def main():
test_extras = get_option_from_environment('CIBW_TEST_EXTRAS', platform=platform, default='')
package_dir = args.package_dir
before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform)
build_verbosity = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='')
build_verbosity_str = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='')
build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '')
if platform == 'linux':
repair_command_default = 'auditwheel repair -w {dest_dir} {wheel}'
@@ -138,7 +146,7 @@ def main():
test_extras = '[{0}]'.format(test_extras)
try:
build_verbosity = min(3, max(-3, int(build_verbosity)))
build_verbosity = min(3, max(-3, int(build_verbosity_str)))
except ValueError:
build_verbosity = 0
@@ -175,7 +183,8 @@ def main():
# 'pypy_x86_64': {'manylinux2010': '...' }
# ... }
manylinux_images = {}
manylinux_images = {} # type: Optional[Dict[str, str]]
assert manylinux_images is not None # Weird problem with mypy
for build_platform in ['x86_64', 'i686', 'pypy_x86_64', 'aarch64', 'ppc64le', 's390x']:
pinned_images = all_pinned_docker_images[build_platform]
@@ -213,7 +222,7 @@ def main():
)
# Python is buffering by default when running on the CI platforms, giving problems interleaving subprocess call output with unflushed calls to 'print'
sys.stdout = Unbuffered(sys.stdout)
sys.stdout = Unbuffered(sys.stdout) # type: ignore
print_preamble(platform, build_options)
@@ -231,7 +240,7 @@ def main():
exit(2)
def detect_obsolete_options():
def detect_obsolete_options() -> None:
# Check the old 'MANYLINUX1_*_IMAGE' options
for (deprecated, alternative) in [('CIBW_MANYLINUX1_X86_64_IMAGE', 'CIBW_MANYLINUX_X86_64_IMAGE'),
('CIBW_MANYLINUX1_I686_IMAGE', 'CIBW_MANYLINUX_I686_IMAGE')]:
@@ -258,7 +267,7 @@ def detect_obsolete_options():
os.environ[option] = os.environ[option].replace(deprecated, alternative)
def print_preamble(platform, build_options):
def print_preamble(platform: str, build_options: BuildOptions) -> None:
print(textwrap.dedent('''
_ _ _ _ _ _ _
___|_| |_ _ _|_| |_| |_ _ _| |_ ___ ___| |
@@ -282,9 +291,9 @@ def print_preamble(platform, build_options):
print('\nHere we go!\n')
def print_build_identifiers(platform, build_selector):
def print_build_identifiers(platform: str, build_selector: BuildSelector) -> None:
if platform == 'linux':
python_configurations = cibuildwheel.linux.get_python_configurations(build_selector)
python_configurations = cibuildwheel.linux.get_python_configurations(build_selector) # type: List[Any]
elif platform == 'windows':
python_configurations = cibuildwheel.windows.get_python_configurations(build_selector)
elif platform == 'macos':
@@ -296,7 +305,7 @@ def print_build_identifiers(platform, build_selector):
print(config.identifier)
def detect_warnings(platform, build_options):
def detect_warnings(platform: str, build_options: BuildOptions) -> List[str]:
warnings = []
# warn about deprecated {python} and {pip}