-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor cibuildwheel.utils (#2252)
* chore: refactor cibuildwheel.utils * rework build_frontend extra flags * ci(fix): use tonistiigi/binfmt:qemu-v8.1.5 image for qemu
- Loading branch information
Showing
39 changed files
with
1,188 additions
and
1,187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import re | ||
from enum import Enum | ||
|
||
from .util.helpers import strtobool | ||
|
||
|
||
class CIProvider(Enum): | ||
travis_ci = "travis" | ||
appveyor = "appveyor" | ||
circle_ci = "circle_ci" | ||
azure_pipelines = "azure_pipelines" | ||
github_actions = "github_actions" | ||
gitlab = "gitlab" | ||
cirrus_ci = "cirrus_ci" | ||
other = "other" | ||
|
||
|
||
def detect_ci_provider() -> CIProvider | None: | ||
if "TRAVIS" in os.environ: | ||
return CIProvider.travis_ci | ||
elif "APPVEYOR" in os.environ: | ||
return CIProvider.appveyor | ||
elif "CIRCLECI" in os.environ: | ||
return CIProvider.circle_ci | ||
elif "AZURE_HTTP_USER_AGENT" in os.environ: | ||
return CIProvider.azure_pipelines | ||
elif "GITHUB_ACTIONS" in os.environ: | ||
return CIProvider.github_actions | ||
elif "GITLAB_CI" in os.environ: | ||
return CIProvider.gitlab | ||
elif "CIRRUS_CI" in os.environ: | ||
return CIProvider.cirrus_ci | ||
elif strtobool(os.environ.get("CI", "false")): | ||
return CIProvider.other | ||
else: | ||
return None | ||
|
||
|
||
def fix_ansi_codes_for_github_actions(text: str) -> str: | ||
""" | ||
Github Actions forgets the current ANSI style on every new line. This | ||
function repeats the current ANSI style on every new line. | ||
""" | ||
ansi_code_regex = re.compile(r"(\033\[[0-9;]*m)") | ||
ansi_codes: list[str] = [] | ||
output = "" | ||
|
||
for line in text.splitlines(keepends=True): | ||
# add the current ANSI codes to the beginning of the line | ||
output += "".join(ansi_codes) + line | ||
|
||
# split the line at each ANSI code | ||
parts = ansi_code_regex.split(line) | ||
# if there are any ANSI codes, save them | ||
if len(parts) > 1: | ||
# iterate over the ANSI codes in this line | ||
for code in parts[1::2]: | ||
if code == "\033[0m": | ||
# reset the list of ANSI codes when the clear code is found | ||
ansi_codes = [] | ||
else: | ||
ansi_codes.append(code) | ||
|
||
return output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from __future__ import annotations | ||
|
||
import shlex | ||
import typing | ||
from collections.abc import Sequence | ||
from dataclasses import dataclass | ||
from typing import Literal | ||
|
||
from .logger import log | ||
from .util.helpers import parse_key_value_string | ||
|
||
BuildFrontendName = Literal["pip", "build", "build[uv]"] | ||
|
||
|
||
@dataclass(frozen=True) | ||
class BuildFrontendConfig: | ||
name: BuildFrontendName | ||
args: Sequence[str] = () | ||
|
||
@staticmethod | ||
def from_config_string(config_string: str) -> BuildFrontendConfig: | ||
config_dict = parse_key_value_string(config_string, ["name"], ["args"]) | ||
name = " ".join(config_dict["name"]) | ||
if name not in {"pip", "build", "build[uv]"}: | ||
msg = f"Unrecognised build frontend {name!r}, only 'pip', 'build', and 'build[uv]' are supported" | ||
raise ValueError(msg) | ||
|
||
name = typing.cast(BuildFrontendName, name) | ||
|
||
args = config_dict.get("args") or [] | ||
return BuildFrontendConfig(name=name, args=args) | ||
|
||
def options_summary(self) -> str | dict[str, str]: | ||
if not self.args: | ||
return self.name | ||
else: | ||
return {"name": self.name, "args": repr(self.args)} | ||
|
||
|
||
def _get_verbosity_flags(level: int, frontend: BuildFrontendName) -> list[str]: | ||
if frontend == "pip": | ||
if level > 0: | ||
return ["-" + level * "v"] | ||
if level < 0: | ||
return ["-" + -level * "q"] | ||
elif not 0 <= level < 2: | ||
msg = f"build_verbosity {level} is not supported for build frontend. Ignoring." | ||
log.warning(msg) | ||
return [] | ||
|
||
|
||
def _split_config_settings(config_settings: str, frontend: BuildFrontendName) -> list[str]: | ||
config_settings_list = shlex.split(config_settings) | ||
s = "s" if frontend == "pip" else "" | ||
return [f"--config-setting{s}={setting}" for setting in config_settings_list] | ||
|
||
|
||
def get_build_frontend_extra_flags( | ||
build_frontend: BuildFrontendConfig, verbosity_level: int, config_settings: str | ||
) -> list[str]: | ||
return [ | ||
*_split_config_settings(config_settings, build_frontend.name), | ||
*build_frontend.args, | ||
*_get_verbosity_flags(verbosity_level, build_frontend.name), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.