diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 17fdf393..a624baa9 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -134,7 +134,7 @@ def main() -> None: dependency_versions = get_option_from_environment('CIBW_DEPENDENCY_VERSIONS', platform=platform, default='pinned') if dependency_versions == 'pinned': - dependency_constraints = DependencyConstraints.with_defaults() # type: Optional[DependencyConstraints] + dependency_constraints: Optional[DependencyConstraints] = DependencyConstraints.with_defaults() elif dependency_versions == 'latest': dependency_constraints = None else: @@ -169,7 +169,7 @@ def main() -> None: print_build_identifiers(platform, build_selector) exit(0) - manylinux_images = None # type: Optional[Dict[str, str]] + manylinux_images: Optional[Dict[str, str]] = None if platform == 'linux': pinned_docker_images_file = os.path.join( os.path.dirname(__file__), 'resources', 'pinned_docker_images.cfg' @@ -287,14 +287,13 @@ def print_preamble(platform: str, build_options: BuildOptions) -> None: def print_build_identifiers(platform: str, build_selector: BuildSelector) -> None: + python_configurations: List[Any] = [] if platform == 'linux': - python_configurations = cibuildwheel.linux.get_python_configurations(build_selector) # type: List[Any] + python_configurations = cibuildwheel.linux.get_python_configurations(build_selector) elif platform == 'windows': python_configurations = cibuildwheel.windows.get_python_configurations(build_selector) elif platform == 'macos': python_configurations = cibuildwheel.macos.get_python_configurations(build_selector) - else: - python_configurations = [] for config in python_configurations: print(config.identifier) diff --git a/cibuildwheel/bashlex_eval.py b/cibuildwheel/bashlex_eval.py index a10fe832..3101089d 100644 --- a/cibuildwheel/bashlex_eval.py +++ b/cibuildwheel/bashlex_eval.py @@ -5,9 +5,10 @@ from typing import Dict, List, NamedTuple, Optional import bashlex # type: ignore -NodeExecutionContext = NamedTuple('NodeExecutionContext', - [('environment', Dict[str, str]), - ('input', str)]) + +class NodeExecutionContext(NamedTuple): + environment: Dict[str, str] + input: str def evaluate(value: str, environment: Dict[str, str]) -> str: @@ -44,7 +45,7 @@ def evaluate_word_node(node: bashlex.ast.node, context: NodeExecutionContext) -> word_start = node.pos[0] word_end = node.pos[1] word_string = context.input[word_start:word_end] - letters = list(word_string) # type: List[Optional[str]] + letters: List[Optional[str]] = list(word_string) for part in node.parts: part_start = part.pos[0] - word_start diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 38ecf943..2ceaf8f1 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -43,7 +43,10 @@ def matches_platform(identifier: str) -> bool: return False -PythonConfiguration = NamedTuple('PythonConfiguration', [('version', str), ('identifier', str), ('path', str)]) +class PythonConfiguration(NamedTuple): + version: str + identifier: str + path: str def get_python_configurations(build_selector: Callable[[str], bool]) -> List[PythonConfiguration]: diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 911d9978..e2b18b88 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -28,7 +28,10 @@ def call(args: Union[str, List[str]], env: Optional[Dict[str, str]] = None, cwd: return subprocess.check_call(args, env=env, cwd=cwd, shell=shell) -PythonConfiguration = NamedTuple('PythonConfiguration', [('version', str), ('identifier', str), ('url', str)]) +class PythonConfiguration(NamedTuple): + version: str + identifier: str + url: str def get_python_configurations(build_selector: Callable[[str], bool]) -> List[PythonConfiguration]: diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 33e45adf..c466af3f 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -110,26 +110,21 @@ class DependencyConstraints: return self.base_file_path -BuildOptions = NamedTuple("BuildOptions", [ - ("package_dir", str), - ("output_dir", str), - ("test_command", Optional[str]), - ("test_requires", List[str]), - ("test_extras", str), - ("before_build", Optional[str]), - ("build_verbosity", int), - ("build_selector", BuildSelector), - ("repair_command", str), - ("environment", ParsedEnvironment), - ("before_test", str), - ("dependency_constraints", Optional[DependencyConstraints]), - ("manylinux_images", Optional[Dict[str, str]]), -]) +class BuildOptions(NamedTuple): + package_dir: str + output_dir: str + test_command: Optional[str] + test_requires: List[str] + test_extras: str + before_build: Optional[str] + build_verbosity: int + build_selector: BuildSelector + repair_command: str + environment: ParsedEnvironment + before_test: str + dependency_constraints: Optional[DependencyConstraints] + manylinux_images: Optional[Dict[str, str]] -""" -Replace this definition with a class-style NamedTuple in the -PEP526 style when Python 3.5 host support is dropped -""" resources_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'resources')) get_pip_script = os.path.join(resources_dir, 'get-pip.py') diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index ffa8152a..4e99094b 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -34,7 +34,11 @@ def get_nuget_args(version: str, arch: str) -> List[str]: return [python_name, '-Version', version, '-OutputDirectory', 'C:\\cibw\\python'] -PythonConfiguration = NamedTuple('PythonConfiguration', [('version', str), ('arch', str), ('identifier', str), ('url', Optional[str])]) +class PythonConfiguration(NamedTuple): + version: str + arch: str + identifier: str + url: Optional[str] def get_python_configurations(build_selector: Callable[[str], bool]) -> List[PythonConfiguration]: