* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.2.2 → v0.3.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.2.2...v0.3.2) - [github.com/pre-commit/mirrors-mypy: v1.8.0 → v1.9.0](https://github.com/pre-commit/mirrors-mypy/compare/v1.8.0...v1.9.0) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
"""
|
|
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
|
|
|
|
__all__ = ("Printable", "dump_python_configurations")
|
|
|
|
|
|
class Printable(Protocol):
|
|
def __str__(self) -> str: ...
|
|
|
|
|
|
def dump_python_configurations(
|
|
inp: Mapping[str, Mapping[str, Sequence[Mapping[str, Printable]]]],
|
|
) -> str:
|
|
output = StringIO()
|
|
for header, values in inp.items():
|
|
output.write(f"[{header}]\n")
|
|
for inner_header, listing in values.items():
|
|
output.write(f"{inner_header} = [\n")
|
|
for item in listing:
|
|
output.write(" { ")
|
|
dict_contents = (f'{key} = "{value}"' for key, value in item.items())
|
|
output.write(", ".join(dict_contents))
|
|
output.write(" },\n")
|
|
output.write("]\n")
|
|
output.write("\n")
|
|
# Strip the final newline, to avoid two blank lines at the end.
|
|
return output.getvalue()[:-1]
|