diff --git a/.flake8 b/.flake8 index 4592939f..14040456 100644 --- a/.flake8 +++ b/.flake8 @@ -7,3 +7,6 @@ ignore = E712, # line break before binary operator W503 +per-file-ignores = + # flake8 is just plain wrong here, contradicting black + .github/generate-job-matrix.py:E225,E231 diff --git a/.github/generate-job-matrix.py b/.github/generate-job-matrix.py index b2465d05..9ba3b8f3 100644 --- a/.github/generate-job-matrix.py +++ b/.github/generate-job-matrix.py @@ -1,13 +1,11 @@ import argparse import json -import typing -import itertools import random -import dataclasses +import typing 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: 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( name=f"Clang-{version} ({platform})", os=None, # replaced below @@ -84,10 +84,17 @@ def make_msvc_config(release: str, version: int) -> Configuration: return ret -configs = {c.name: c for c in [make_gcc_config(ver) for ver in [12, 13, 14]] - + [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)]} +configs = { + c.name: c + for c in [make_gcc_config(ver) for ver in [12, 13, 14]] + + [ + 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( config=list(configs.values()), @@ -118,10 +125,18 @@ def main(): case "all": collector.all_combinations() 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( 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) case "clang-tidy": @@ -136,24 +151,29 @@ def main(): raise KeyError(f"Unsupported preset {args.preset!r}") if not collector.combinations: - raise ValueError(f"No combination has been produced") + raise ValueError("No combination has been produced") data = sorted(collector.combinations) 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: match dbg: case "yaml": import yaml + json_data = json.loads(json.dumps(data, default=dataclass_to_json)) print(yaml.safe_dump(json_data)) case "json": print(json.dumps(data, default=dataclass_to_json, indent=4)) case "combinations": 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": print(f"Total combinations {len(data)}") for (k, v), n in sorted(collector.per_value_counts.items()): diff --git a/.github/job_matrix.py b/.github/job_matrix.py index 9065f389..eb956268 100644 --- a/.github/job_matrix.py +++ b/.github/job_matrix.py @@ -1,10 +1,7 @@ -import argparse -import json -import typing +import dataclasses import itertools import random -import dataclasses -from types import SimpleNamespace +import typing from dataclasses import dataclass @@ -29,6 +26,7 @@ class Configuration: def __str__(self): return self.name + @dataclass(frozen=True, order=True) class MatrixElement: config: Configuration @@ -39,21 +37,21 @@ class MatrixElement: def dataclass_to_json(obj): - """ Convert dataclasses to something json-serialisable """ + """Convert dataclasses to something json-serialisable""" if dataclasses.is_dataclass(obj): return dataclasses.asdict(obj) raise TypeError(f"Unknown object of type {type(obj).__name__}") 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]]): self.full_matrix = full_matrix 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 - v in options} + self.per_value_counts: dict[tuple[str, typing.Any], int] = { + (k, v): 0 for k, options in full_matrix.items() for v in options + } def _make_submatrix(self, **overrides): new_matrix = dict(self.full_matrix) @@ -64,7 +62,9 @@ class CombinationCollector: return new_matrix 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 self.combinations.add(e) # update per_value_counts @@ -72,8 +72,13 @@ class CombinationCollector: idx = (k, v) 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): - """ Adds all combinations in the submatrix defined by `overrides`. """ + def all_combinations( + self, + *, + filter: typing.Callable[[MatrixElement], bool] | None = None, + **overrides, + ): + """Adds all combinations in the submatrix defined by `overrides`.""" matrix = self._make_submatrix(**overrides) keys = tuple(matrix.keys()) for combination in itertools.product(*matrix.values()): @@ -82,9 +87,17 @@ class CombinationCollector: continue self._add_combination(cand) - def sample_combinations(self, *, 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. """ + def sample_combinations( + self, + *, + 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) missing: dict[tuple[str, typing.Any], int] = {} for key, options in matrix.items(): @@ -109,5 +122,3 @@ class CombinationCollector: remaining = min_samples_per_value - self.per_value_counts.get(idx, 0) if remaining > 0: missing[idx] = remaining - - diff --git a/.github/workflows/ci-clang-tidy.yml b/.github/workflows/ci-clang-tidy.yml index ddf7f23f..402455a1 100644 --- a/.github/workflows/ci-clang-tidy.yml +++ b/.github/workflows/ci-clang-tidy.yml @@ -39,6 +39,7 @@ jobs: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + runs-on: ubuntu-24.04 steps: - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" generate-matrix: diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index f5377fc2..f80f7776 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -38,6 +38,7 @@ jobs: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + runs-on: ubuntu-24.04 steps: - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" generate-matrix: diff --git a/.github/workflows/ci-freestanding.yml b/.github/workflows/ci-freestanding.yml index 5ce2662c..2b2f97da 100644 --- a/.github/workflows/ci-freestanding.yml +++ b/.github/workflows/ci-freestanding.yml @@ -39,6 +39,7 @@ jobs: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + runs-on: ubuntu-24.04 steps: - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" generate-matrix: diff --git a/.github/workflows/ci-test-package-cmake.yml b/.github/workflows/ci-test-package-cmake.yml index 1644c495..bb1e9609 100644 --- a/.github/workflows/ci-test-package-cmake.yml +++ b/.github/workflows/ci-test-package-cmake.yml @@ -43,6 +43,7 @@ jobs: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true + runs-on: ubuntu-24.04 steps: - run: echo "Cancelling all previous runs of ${{ github.workflow }}-${{ github.ref }}" generate-matrix: