Skip to content

Commit

Permalink
style: remove from future import annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Feb 28, 2025
1 parent 1b63074 commit 708cf1d
Show file tree
Hide file tree
Showing 93 changed files with 63 additions and 239 deletions.
2 changes: 0 additions & 2 deletions bin/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# ///


from __future__ import annotations

import os
import subprocess
import sys
Expand Down
2 changes: 0 additions & 2 deletions bin/inspect_all_known_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
the results without the `--online` setting.
"""

from __future__ import annotations

import ast
from collections.abc import Iterable, Iterator
from pathlib import Path
Expand Down
1 change: 0 additions & 1 deletion bin/make_dependency_update_pr.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import os
import subprocess
Expand Down
6 changes: 2 additions & 4 deletions bin/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
git diff
"""

from __future__ import annotations

import builtins
import functools
import textwrap
Expand All @@ -28,7 +26,7 @@
from datetime import datetime
from io import StringIO
from pathlib import Path
from typing import Any, TextIO
from typing import Any, Self, TextIO

import click
import yaml
Expand Down Expand Up @@ -85,7 +83,7 @@ def __init__(self, config: Mapping[str, Any], github: Github | None = None):
name_len = len(self.name) + 4
self.__class__.NAME = max(self.__class__.NAME, name_len)

def __lt__(self, other: Project) -> bool:
def __lt__(self, other: Self) -> bool:
if self.online:
return self.num_stars < other.num_stars
else:
Expand Down
1 change: 0 additions & 1 deletion bin/run_example_ci_configs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import os
import shutil
Expand Down
1 change: 0 additions & 1 deletion bin/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import argparse
import os
Expand Down
1 change: 0 additions & 1 deletion bin/sample_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import argparse
import os
Expand Down
1 change: 0 additions & 1 deletion bin/update_docker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
from __future__ import annotations

import configparser
from dataclasses import dataclass
Expand Down
1 change: 0 additions & 1 deletion bin/update_how_it_works_image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import subprocess
import sys
Expand Down
1 change: 0 additions & 1 deletion bin/update_nodejs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import difflib
import logging
Expand Down
1 change: 0 additions & 1 deletion bin/update_pythons.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import copy
import difflib
Expand Down
1 change: 0 additions & 1 deletion bin/update_readme_changelog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import re
import sys
Expand Down
1 change: 0 additions & 1 deletion bin/update_virtualenv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env python3

from __future__ import annotations

import difflib
import logging
Expand Down
2 changes: 0 additions & 2 deletions cibuildwheel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from __future__ import annotations

__version__ = "2.22.0"
2 changes: 0 additions & 2 deletions cibuildwheel/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import argparse
import contextlib
import dataclasses
Expand Down
18 changes: 9 additions & 9 deletions cibuildwheel/architecture.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from __future__ import annotations

import platform as platform_module
import re
import shutil
import subprocess
import sys
import typing
from collections.abc import Set
from enum import StrEnum, auto
from typing import Final, Literal, assert_never
from typing import Final, Literal

from .typing import PlatformName

Expand Down Expand Up @@ -38,6 +37,7 @@ def _check_aarch32_el0() -> bool:
return check.returncode == 0 and check.stdout.startswith("armv")


@typing.final
class Architecture(StrEnum):
# mac/linux archs
x86_64 = auto()
Expand All @@ -62,7 +62,7 @@ class Architecture(StrEnum):
wasm32 = auto()

@staticmethod
def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
def parse_config(config: str, platform: PlatformName) -> "set[Architecture]":
result = set()
for arch_str in re.split(r"[\s,]+", config):
if arch_str == "auto":
Expand All @@ -82,7 +82,7 @@ def parse_config(config: str, platform: PlatformName) -> set[Architecture]:
return result

@staticmethod
def native_arch(platform: PlatformName) -> Architecture | None:
def native_arch(platform: PlatformName) -> "Architecture | None":
if platform == "pyodide":
return Architecture.wasm32

Expand Down Expand Up @@ -112,7 +112,7 @@ def native_arch(platform: PlatformName) -> Architecture | None:
return native_architecture

@staticmethod
def auto_archs(platform: PlatformName) -> set[Architecture]:
def auto_archs(platform: PlatformName) -> "set[Architecture]":
native_arch = Architecture.native_arch(platform)
if native_arch is None:
return set() # can't build anything on this platform
Expand All @@ -131,7 +131,7 @@ def auto_archs(platform: PlatformName) -> set[Architecture]:
return result

@staticmethod
def all_archs(platform: PlatformName) -> set[Architecture]:
def all_archs(platform: PlatformName) -> "set[Architecture]":
all_archs_map = {
"linux": {
Architecture.x86_64,
Expand All @@ -148,15 +148,15 @@ def all_archs(platform: PlatformName) -> set[Architecture]:
return all_archs_map[platform]

@staticmethod
def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> set[Architecture]:
def bitness_archs(platform: PlatformName, bitness: Literal["64", "32"]) -> "set[Architecture]":
archs_32 = {Architecture.i686, Architecture.x86, Architecture.armv7l}
auto_archs = Architecture.auto_archs(platform)

if bitness == "64":
return auto_archs - archs_32
if bitness == "32":
return auto_archs & archs_32
assert_never(bitness)
typing.assert_never(bitness)


def allowed_architectures_check(
Expand Down
2 changes: 0 additions & 2 deletions cibuildwheel/bashlex_eval.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import subprocess
from collections.abc import (
Callable,
Expand Down
2 changes: 0 additions & 2 deletions cibuildwheel/ci.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import os
import re
from enum import Enum
Expand Down
2 changes: 0 additions & 2 deletions cibuildwheel/environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import dataclasses
from collections.abc import Mapping, Sequence
from typing import Any, Protocol
Expand Down
2 changes: 0 additions & 2 deletions cibuildwheel/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
These are utilities for the `/bin` scripts, not for the `cibuildwheel` program.
"""

from __future__ import annotations

from collections.abc import Mapping, Sequence
from io import StringIO
from typing import Protocol
Expand Down
10 changes: 4 additions & 6 deletions cibuildwheel/frontend.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from __future__ import annotations

import shlex
import typing
from collections.abc import Sequence
from dataclasses import dataclass
from typing import Literal, get_args
from typing import Literal, Self, get_args

from .logger import log
from .util.helpers import parse_key_value_string
Expand All @@ -17,8 +15,8 @@ class BuildFrontendConfig:
name: BuildFrontendName
args: Sequence[str] = ()

@staticmethod
def from_config_string(config_string: str) -> BuildFrontendConfig:
@classmethod
def from_config_string(cls, config_string: str) -> Self:
config_dict = parse_key_value_string(config_string, ["name"], ["args"])
name = " ".join(config_dict["name"])
if name not in get_args(BuildFrontendName):
Expand All @@ -29,7 +27,7 @@ def from_config_string(config_string: str) -> BuildFrontendConfig:
name = typing.cast(BuildFrontendName, name)

args = config_dict.get("args") or []
return BuildFrontendConfig(name=name, args=args)
return cls(name=name, args=args)

def options_summary(self) -> str | dict[str, str]:
if not self.args:
Expand Down
2 changes: 0 additions & 2 deletions cibuildwheel/linux.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import contextlib
import subprocess
import sys
Expand Down
54 changes: 26 additions & 28 deletions cibuildwheel/logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import codecs
import os
import re
Expand Down Expand Up @@ -40,6 +38,32 @@
}


class Colors:
def __init__(self, *, enabled: bool) -> None:
self.red = "\033[31m" if enabled else ""
self.green = "\033[32m" if enabled else ""
self.yellow = "\033[33m" if enabled else ""
self.blue = "\033[34m" if enabled else ""
self.cyan = "\033[36m" if enabled else ""
self.bright_red = "\033[91m" if enabled else ""
self.bright_green = "\033[92m" if enabled else ""
self.white = "\033[37m\033[97m" if enabled else ""
self.gray = "\033[38;5;244m" if enabled else ""

self.bg_grey = "\033[48;5;235m" if enabled else ""

self.bold = "\033[1m" if enabled else ""
self.faint = "\033[2m" if enabled else ""

self.end = "\033[0m" if enabled else ""


class Symbols:
def __init__(self, *, unicode: bool) -> None:
self.done = "✓" if unicode else "done"
self.error = "✕" if unicode else "failed"


class Logger:
fold_mode: str
colors_enabled: bool
Expand Down Expand Up @@ -229,32 +253,6 @@ def build_description_from_identifier(identifier: str) -> str:
return build_description


class Colors:
def __init__(self, *, enabled: bool) -> None:
self.red = "\033[31m" if enabled else ""
self.green = "\033[32m" if enabled else ""
self.yellow = "\033[33m" if enabled else ""
self.blue = "\033[34m" if enabled else ""
self.cyan = "\033[36m" if enabled else ""
self.bright_red = "\033[91m" if enabled else ""
self.bright_green = "\033[92m" if enabled else ""
self.white = "\033[37m\033[97m" if enabled else ""
self.gray = "\033[38;5;244m" if enabled else ""

self.bg_grey = "\033[48;5;235m" if enabled else ""

self.bold = "\033[1m" if enabled else ""
self.faint = "\033[2m" if enabled else ""

self.end = "\033[0m" if enabled else ""


class Symbols:
def __init__(self, *, unicode: bool) -> None:
self.done = "✓" if unicode else "done"
self.error = "✕" if unicode else "failed"


def file_supports_color(file_obj: IO[AnyStr]) -> bool:
"""
Returns True if the running system's terminal supports color.
Expand Down
2 changes: 0 additions & 2 deletions cibuildwheel/macos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import functools
import inspect
import os
Expand Down
10 changes: 3 additions & 7 deletions cibuildwheel/oci_container.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import io
import json
import os
Expand Down Expand Up @@ -44,8 +42,8 @@ class OCIContainerEngineConfig:
create_args: tuple[str, ...] = field(default_factory=tuple)
disable_host_mount: bool = False

@staticmethod
def from_config_string(config_string: str) -> OCIContainerEngineConfig:
@classmethod
def from_config_string(cls, config_string: str) -> Self:
config_dict = parse_key_value_string(
config_string,
["name"],
Expand Down Expand Up @@ -75,9 +73,7 @@ def from_config_string(config_string: str) -> OCIContainerEngineConfig:
else:
create_args = [arg for arg in create_args if not arg.startswith("--platform=")]

return OCIContainerEngineConfig(
name=name, create_args=tuple(create_args), disable_host_mount=disable_host_mount
)
return cls(name=name, create_args=tuple(create_args), disable_host_mount=disable_host_mount)

def options_summary(self) -> str | dict[str, str]:
if not self.create_args:
Expand Down
Loading

0 comments on commit 708cf1d

Please sign in to comment.