fix formatting

This commit is contained in:
Yves Delley
2024-11-12 18:43:50 +01:00
parent 329b9f585c
commit 7fa15d224d
7 changed files with 71 additions and 33 deletions

View File

@ -7,3 +7,6 @@ ignore =
E712, E712,
# line break before binary operator # line break before binary operator
W503 W503
per-file-ignores =
# flake8 is just plain wrong here, contradicting black
.github/generate-job-matrix.py:E225,E231

View File

@ -1,13 +1,11 @@
import argparse import argparse
import json import json
import typing
import itertools
import random import random
import dataclasses import typing
from types import SimpleNamespace from types import SimpleNamespace
from dataclasses import dataclass
from job_matrix import Configuration, Compiler, MatrixElement, CombinationCollector, dataclass_to_json from job_matrix import CombinationCollector, Compiler, Configuration, dataclass_to_json
def make_gcc_config(version: int) -> Configuration: def make_gcc_config(version: int) -> Configuration:
return Configuration( return Configuration(
@ -24,7 +22,9 @@ def make_gcc_config(version: int) -> Configuration:
) )
def make_clang_config(version: int, platform: typing.Literal["x86-64", "arm64"] = "x86-64") -> Configuration: def make_clang_config(
version: int, platform: typing.Literal["x86-64", "arm64"] = "x86-64"
) -> Configuration:
ret = SimpleNamespace( ret = SimpleNamespace(
name=f"Clang-{version} ({platform})", name=f"Clang-{version} ({platform})",
os=None, # replaced below os=None, # replaced below
@ -84,10 +84,17 @@ def make_msvc_config(release: str, version: int) -> Configuration:
return ret return ret
configs = {c.name: c for c in [make_gcc_config(ver) for ver in [12, 13, 14]] configs = {
+ [make_clang_config(ver, platform) for ver in [16, 17, 18, 19] for platform in ["x86-64", "arm64"]] c.name: c
+ [make_apple_clang_config(ver) for ver in [15]] for c in [make_gcc_config(ver) for ver in [12, 13, 14]]
+ [make_msvc_config(release="14.4", version=194)]} + [
make_clang_config(ver, platform)
for ver in [16, 17, 18, 19]
for platform in ["x86-64", "arm64"]
]
+ [make_apple_clang_config(ver) for ver in [15]]
+ [make_msvc_config(release="14.4", version=194)]
}
full_matrix = dict( full_matrix = dict(
config=list(configs.values()), config=list(configs.values()),
@ -118,10 +125,18 @@ def main():
case "all": case "all":
collector.all_combinations() collector.all_combinations()
case "conan" | "cmake": case "conan" | "cmake":
collector.all_combinations(formatting="std::format", contracts="gsl-lite", build_type="Debug", std=20) collector.all_combinations(
formatting="std::format",
contracts="gsl-lite",
build_type="Debug",
std=20,
)
collector.all_combinations( collector.all_combinations(
filter=lambda me: not me.config.std_format_support, filter=lambda me: not me.config.std_format_support,
formatting="fmtlib", contracts="gsl-lite", build_type="Debug", std=20, formatting="fmtlib",
contracts="gsl-lite",
build_type="Debug",
std=20,
) )
collector.sample_combinations(rgen=rgen, min_samples_per_value=2) collector.sample_combinations(rgen=rgen, min_samples_per_value=2)
case "clang-tidy": case "clang-tidy":
@ -136,24 +151,29 @@ def main():
raise KeyError(f"Unsupported preset {args.preset!r}") raise KeyError(f"Unsupported preset {args.preset!r}")
if not collector.combinations: if not collector.combinations:
raise ValueError(f"No combination has been produced") raise ValueError("No combination has been produced")
data = sorted(collector.combinations) data = sorted(collector.combinations)
if not args.suppress_output: if not args.suppress_output:
print(f"::set-output name=matrix::{json.dumps(data, default=dataclass_to_json)}") print(
f"::set-output name=matrix::{json.dumps(data, default=dataclass_to_json)}"
)
for dbg in args.debug: for dbg in args.debug:
match dbg: match dbg:
case "yaml": case "yaml":
import yaml import yaml
json_data = json.loads(json.dumps(data, default=dataclass_to_json)) json_data = json.loads(json.dumps(data, default=dataclass_to_json))
print(yaml.safe_dump(json_data)) print(yaml.safe_dump(json_data))
case "json": case "json":
print(json.dumps(data, default=dataclass_to_json, indent=4)) print(json.dumps(data, default=dataclass_to_json, indent=4))
case "combinations": case "combinations":
for e in data: for e in data:
print(f"{e.config!s:17s} c++{e.std:2d} {e.formatting:11s} {e.contracts:8s} {e.build_type:8s}") print(
f"{e.config!s:17s} c++{e.std:2d} {e.formatting:11s} {e.contracts:8s} {e.build_type:8s}"
)
case "counts": case "counts":
print(f"Total combinations {len(data)}") print(f"Total combinations {len(data)}")
for (k, v), n in sorted(collector.per_value_counts.items()): for (k, v), n in sorted(collector.per_value_counts.items()):

47
.github/job_matrix.py vendored
View File

@ -1,10 +1,7 @@
import argparse import dataclasses
import json
import typing
import itertools import itertools
import random import random
import dataclasses import typing
from types import SimpleNamespace
from dataclasses import dataclass from dataclasses import dataclass
@ -29,6 +26,7 @@ class Configuration:
def __str__(self): def __str__(self):
return self.name return self.name
@dataclass(frozen=True, order=True) @dataclass(frozen=True, order=True)
class MatrixElement: class MatrixElement:
config: Configuration config: Configuration
@ -39,21 +37,21 @@ class MatrixElement:
def dataclass_to_json(obj): def dataclass_to_json(obj):
""" Convert dataclasses to something json-serialisable """ """Convert dataclasses to something json-serialisable"""
if dataclasses.is_dataclass(obj): if dataclasses.is_dataclass(obj):
return dataclasses.asdict(obj) return dataclasses.asdict(obj)
raise TypeError(f"Unknown object of type {type(obj).__name__}") raise TypeError(f"Unknown object of type {type(obj).__name__}")
class CombinationCollector: class CombinationCollector:
""" Incremental builder of MatrixElements, allowing successive selection of entries. """Incremental builder of MatrixElements, allowing successive selection of entries."""
"""
def __init__(self, full_matrix: dict[str, list[typing.Any]]): def __init__(self, full_matrix: dict[str, list[typing.Any]]):
self.full_matrix = full_matrix self.full_matrix = full_matrix
self.combinations: set[MatrixElement] = set() self.combinations: set[MatrixElement] = set()
self.per_value_counts: dict[tuple[str, typing.Any], int] = {(k, v): 0 for k, options in full_matrix.items() for self.per_value_counts: dict[tuple[str, typing.Any], int] = {
v in options} (k, v): 0 for k, options in full_matrix.items() for v in options
}
def _make_submatrix(self, **overrides): def _make_submatrix(self, **overrides):
new_matrix = dict(self.full_matrix) new_matrix = dict(self.full_matrix)
@ -64,7 +62,9 @@ class CombinationCollector:
return new_matrix return new_matrix
def _add_combination(self, e: MatrixElement): def _add_combination(self, e: MatrixElement):
if e in self.combinations or (e.formatting == "std::format" and not e.config.std_format_support): if e in self.combinations or (
e.formatting == "std::format" and not e.config.std_format_support
):
return return
self.combinations.add(e) self.combinations.add(e)
# update per_value_counts # update per_value_counts
@ -72,8 +72,13 @@ class CombinationCollector:
idx = (k, v) idx = (k, v)
self.per_value_counts[idx] = self.per_value_counts.get(idx, 0) + 1 self.per_value_counts[idx] = self.per_value_counts.get(idx, 0) + 1
def all_combinations(self, *, filter: typing.Callable[[MatrixElement], bool] | None = None, **overrides): def all_combinations(
""" Adds all combinations in the submatrix defined by `overrides`. """ self,
*,
filter: typing.Callable[[MatrixElement], bool] | None = None,
**overrides,
):
"""Adds all combinations in the submatrix defined by `overrides`."""
matrix = self._make_submatrix(**overrides) matrix = self._make_submatrix(**overrides)
keys = tuple(matrix.keys()) keys = tuple(matrix.keys())
for combination in itertools.product(*matrix.values()): for combination in itertools.product(*matrix.values()):
@ -82,9 +87,17 @@ class CombinationCollector:
continue continue
self._add_combination(cand) self._add_combination(cand)
def sample_combinations(self, *, rgen: random.Random, min_samples_per_value: int = 1, def sample_combinations(
filter: typing.Callable[[MatrixElement], bool] | None = None, **overrides): self,
""" Adds samples from the submatrix defined by `overrides`, ensuring each individual value appears at least n times. """ *,
rgen: random.Random,
min_samples_per_value: int = 1,
filter: typing.Callable[[MatrixElement], bool] | None = None,
**overrides,
):
"""Adds samples from the submatrix defined by `overrides`,
ensuring each individual value appears at least n times.
"""
matrix = self._make_submatrix(**overrides) matrix = self._make_submatrix(**overrides)
missing: dict[tuple[str, typing.Any], int] = {} missing: dict[tuple[str, typing.Any], int] = {}
for key, options in matrix.items(): for key, options in matrix.items():
@ -109,5 +122,3 @@ class CombinationCollector:
remaining = min_samples_per_value - self.per_value_counts.get(idx, 0) remaining = min_samples_per_value - self.per_value_counts.get(idx, 0)
if remaining > 0: if remaining > 0:
missing[idx] = remaining missing[idx] = remaining

View File

@ -39,6 +39,7 @@ jobs:
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
runs-on: ubuntu-24.04
steps: steps:
- run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}"
generate-matrix: generate-matrix:

View File

@ -38,6 +38,7 @@ jobs:
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
runs-on: ubuntu-24.04
steps: steps:
- run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}"
generate-matrix: generate-matrix:

View File

@ -39,6 +39,7 @@ jobs:
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
runs-on: ubuntu-24.04
steps: steps:
- run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}"
generate-matrix: generate-matrix:

View File

@ -43,6 +43,7 @@ jobs:
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }} group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true cancel-in-progress: true
runs-on: ubuntu-24.04
steps: steps:
- run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}"
generate-matrix: generate-matrix: