From 40967a6572a808c2b74d8fca9af189f48911fffd Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Wed, 8 Apr 2020 11:08:23 +0200 Subject: [PATCH] collections.namedtuple to typing.NameTuple and flake8 fixes --- cibuildwheel/__main__.py | 10 ++++------ cibuildwheel/bashlex_eval.py | 1 - cibuildwheel/linux.py | 8 ++------ cibuildwheel/macos.py | 8 ++------ cibuildwheel/windows.py | 11 ++++------- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index 09471d76..83e57f03 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -5,7 +5,7 @@ import textwrap import traceback from configparser import ConfigParser -from typing import Any, Dict, List, Optional, Union, overload +from typing import Any, Dict, List, Optional, overload import cibuildwheel import cibuildwheel.linux @@ -24,12 +24,10 @@ from cibuildwheel.util import ( @overload -def get_option_from_environment(option_name: str, platform: Optional[str], default: str) -> str: - ... +def get_option_from_environment(option_name: str, platform: Optional[str], default: str) -> str: ... # noqa: E704 @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]: +def get_option_from_environment(option_name: str, platform: Optional[str] = None, default: None = None) -> Optional[str]: ... # noqa: E704 E302 +def get_option_from_environment(option_name: str, platform: Optional[str] = None, default: Optional[str] = None) -> Optional[str]: # noqa: E302 ''' Returns an option from the environment, optionally scoped by the platform. diff --git a/cibuildwheel/bashlex_eval.py b/cibuildwheel/bashlex_eval.py index f8bd0800..a10fe832 100644 --- a/cibuildwheel/bashlex_eval.py +++ b/cibuildwheel/bashlex_eval.py @@ -1,6 +1,5 @@ import shlex import subprocess -from collections import namedtuple from typing import Dict, List, NamedTuple, Optional diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index b1a27de0..33cd493d 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -5,13 +5,9 @@ import subprocess import sys import textwrap import uuid -from collections import namedtuple -from typing import Callable, Dict, List, Optional +from typing import Callable, List, NamedTuple -from .environment import ( - ParsedEnvironment, -) from .util import ( BuildOptions, get_build_verbosity_extra_flags, @@ -47,7 +43,7 @@ def matches_platform(identifier): return False -PythonConfiguration = namedtuple('PythonConfiguration', ['version', 'identifier', 'path']) +PythonConfiguration = NamedTuple('PythonConfiguration', [('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 610c30e1..2e0a2535 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -4,14 +4,10 @@ import shutil import subprocess import sys import tempfile -from collections import namedtuple from glob import glob -from typing import Callable, Dict, List, Optional, Union +from typing import Callable, Dict, List, Optional, NamedTuple, Union -from .environment import ( - ParsedEnvironment, -) from .util import ( BuildOptions, download, @@ -31,7 +27,7 @@ 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', 'identifier', 'url']) +PythonConfiguration = NamedTuple('PythonConfiguration', [('version', str), ('identifier', str), ('url', str)]) def get_python_configurations(build_selector: Callable[[str], bool]) -> List[PythonConfiguration]: diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 48db6733..cb78fe60 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -3,15 +3,11 @@ import shutil import subprocess import sys import tempfile -from collections import namedtuple from glob import glob from zipfile import ZipFile -from typing import Callable, Dict, List, Optional +from typing import Callable, Dict, List, Optional, NamedTuple -from .environment import ( - ParsedEnvironment, -) from .util import ( BuildOptions, download, @@ -37,7 +33,7 @@ def get_nuget_args(version: str, arch: str) -> List[str]: return [python_name, '-Version', version, '-OutputDirectory', 'C:\\cibw\\python'] -PythonConfiguration = namedtuple('PythonConfiguration', ['version', 'arch', 'identifier', 'url']) +PythonConfiguration = NamedTuple('PythonConfiguration', [('version', str), ('arch', str), ('identifier', str), ('url', Optional[str])]) def get_python_configurations(build_selector: Callable[[str], bool]) -> List[PythonConfiguration]: @@ -81,8 +77,9 @@ def install_cpython(version: str, arch: str, nuget: str) -> str: return installation_path -def install_pypy(version: str, arch: str, url: str) -> str: +def install_pypy(version: str, arch: str, url: Optional[str]) -> str: assert arch == '32' + assert url is not None # Inside the PyPy zip file is a directory with the same name zip_filename = url.rsplit('/', 1)[-1] installation_path = os.path.join('C:\\cibw', os.path.splitext(zip_filename)[0])