style(types): use new bracex static typing support (#887)

* style(types): use new bracex static typing support

* style(types): add a bit more basic typing

* style(types): globally ignore ghapi

* style(types): include a bit more in the global ignores

* fix(types): line invalid on Python 3.6

* fix: require typing_extensions 3.10
This commit is contained in:
Henry Schreiner
2021-10-26 15:56:35 -04:00
committed by GitHub
parent 2f4987fab9
commit 603a7b5bde
7 changed files with 21 additions and 20 deletions
+4 -1
View File
@@ -55,7 +55,9 @@ repos:
exclude: ^(bin|cibuildwheel/resources|docs)/.*py$ exclude: ^(bin|cibuildwheel/resources|docs)/.*py$
args: ["--python-version=3.6", "--scripts-are-modules", "--show-error-codes"] args: ["--python-version=3.6", "--scripts-are-modules", "--show-error-codes"]
additional_dependencies: &mypy-dependencies additional_dependencies: &mypy-dependencies
- nox
- packaging>=21.0 - packaging>=21.0
- pygithub
- rich - rich
- tomli - tomli
- types-certifi - types-certifi
@@ -64,9 +66,10 @@ repos:
- types-jinja2 - types-jinja2
- types-pyyaml - types-pyyaml
- types-requests - types-requests
- bracex
- id: mypy - id: mypy
name: mypy 3.7+ on bin/ name: mypy 3.7+ on bin/
files: ^((bin|docs)/.*py|noxfile.py)$ files: ^((bin|docs)/.*py)$
args: ["--python-version=3.7", "--scripts-are-modules", "--show-error-codes"] args: ["--python-version=3.7", "--scripts-are-modules", "--show-error-codes"]
additional_dependencies: *mypy-dependencies additional_dependencies: *mypy-dependencies
+1 -1
View File
@@ -7,7 +7,7 @@ from typing import Iterator
import click import click
import yaml import yaml
from ghapi.core import GhApi, HTTP404NotFoundError # type: ignore[import] from ghapi.core import GhApi, HTTP404NotFoundError
from rich import print from rich import print
from cibuildwheel.projectfiles import Analyzer from cibuildwheel.projectfiles import Analyzer
+1 -1
View File
@@ -163,7 +163,7 @@ def main() -> None:
os.environ["CIBUILDWHEEL"] = "1" os.environ["CIBUILDWHEEL"] = "1"
# Python is buffering by default when running on the CI platforms, giving problems interleaving subprocess call output with unflushed calls to 'print' # 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) # type: ignore[no-untyped-call,assignment] sys.stdout = Unbuffered(sys.stdout) # type: ignore[assignment]
print_preamble(platform=platform, options=options, identifiers=identifiers) print_preamble(platform=platform, options=options, identifiers=identifiers)
+3 -4
View File
@@ -1,15 +1,14 @@
import subprocess import subprocess
import sys import sys
import textwrap import textwrap
from collections import OrderedDict
from pathlib import Path, PurePath from pathlib import Path, PurePath
from typing import Iterator, List, NamedTuple, Set from typing import Iterator, List, NamedTuple, Set, Tuple
from .architecture import Architecture from .architecture import Architecture
from .docker_container import DockerContainer from .docker_container import DockerContainer
from .logger import log from .logger import log
from .options import Options from .options import Options
from .typing import PathOrStr, assert_never from .typing import OrderedDict, PathOrStr, assert_never
from .util import ( from .util import (
BuildSelector, BuildSelector,
NonPlatformWheelError, NonPlatformWheelError,
@@ -80,7 +79,7 @@ def get_build_steps(
Groups PythonConfigurations into BuildSteps. Each BuildStep represents a Groups PythonConfigurations into BuildSteps. Each BuildStep represents a
separate Docker container. separate Docker container.
""" """
steps: OrderedDict[tuple, BuildStep] = OrderedDict() # type: ignore[type-arg] steps = OrderedDict[Tuple[str, str, str], BuildStep]()
for config in python_configurations: for config in python_configurations:
_, platform_tag = config.identifier.split("-", 1) _, platform_tag = config.identifier.split("-", 1)
+8 -8
View File
@@ -12,7 +12,7 @@ import urllib.request
from enum import Enum from enum import Enum
from pathlib import Path from pathlib import Path
from time import sleep from time import sleep
from typing import Dict, Iterator, List, Optional from typing import Any, Dict, Iterable, Iterator, List, Optional, TextIO
import bracex import bracex
import certifi import certifi
@@ -84,9 +84,9 @@ def selector_matches(patterns: str, string: str) -> bool:
expansion. For example, 'cp{36,37}-*' would match either of 'cp36-*' or expansion. For example, 'cp{36,37}-*' would match either of 'cp36-*' or
'cp37-*'. 'cp37-*'.
""" """
patterns_list: List[str] = patterns.split() patterns_list = patterns.split()
patterns_list = itertools.chain.from_iterable(bracex.expand(p) for p in patterns_list) # type: ignore[assignment] expanded_patterns = itertools.chain.from_iterable(bracex.expand(p) for p in patterns_list)
return any(fnmatch.fnmatch(string, pat) for pat in patterns_list) return any(fnmatch.fnmatch(string, pat) for pat in expanded_patterns)
class IdentifierSelector: class IdentifierSelector:
@@ -161,18 +161,18 @@ class TestSelector(IdentifierSelector):
# Taken from https://stackoverflow.com/a/107717 # Taken from https://stackoverflow.com/a/107717
class Unbuffered: class Unbuffered:
def __init__(self, stream): # type: ignore[no-untyped-def] def __init__(self, stream: TextIO) -> None:
self.stream = stream self.stream = stream
def write(self, data): # type: ignore[no-untyped-def] def write(self, data: str) -> None:
self.stream.write(data) self.stream.write(data)
self.stream.flush() self.stream.flush()
def writelines(self, data): # type: ignore[no-untyped-def] def writelines(self, data: Iterable[str]) -> None:
self.stream.writelines(data) self.stream.writelines(data)
self.stream.flush() self.stream.flush()
def __getattr__(self, attr): # type: ignore[no-untyped-def] def __getattr__(self, attr: str) -> Any:
return getattr(self.stream, attr) return getattr(self.stream, attr)
+3 -4
View File
@@ -32,7 +32,8 @@ files = [
"cibuildwheel/*.py", "cibuildwheel/*.py",
"test/**/*.py", "test/**/*.py",
"unit_test/**/*.py", "unit_test/**/*.py",
"bin/*.py" "bin/*.py",
"noxfile.py",
] ]
warn_unused_configs = true warn_unused_configs = true
warn_redundant_casts = true warn_redundant_casts = true
@@ -58,10 +59,8 @@ module = [
"setuptools", "setuptools",
"pytest", # ignored in pre-commit to speed up check "pytest", # ignored in pre-commit to speed up check
"bashlex", "bashlex",
"bracex",
"importlib_resources", "importlib_resources",
"nox", "ghapi.*",
"github",
] ]
ignore_missing_imports = true ignore_missing_imports = true
+1 -1
View File
@@ -37,7 +37,7 @@ install_requires =
packaging packaging
tomli tomli
dataclasses;python_version < '3.7' dataclasses;python_version < '3.7'
typing_extensions;python_version < '3.8' typing_extensions>=3.10.0.0;python_version < '3.8'
python_requires = >=3.6 python_requires = >=3.6
include_package_data = True include_package_data = True
zip_safe = False zip_safe = False