Skip to content

Commit

Permalink
ensure that we have an import_std configuration in the test-set; also…
Browse files Browse the repository at this point in the history
…, update flake8
  • Loading branch information
burnpanck committed Nov 13, 2024
1 parent b35e241 commit e019166
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
3 changes: 0 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,3 @@ 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
12 changes: 10 additions & 2 deletions .github/generate-job-matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ def main():
e.formatting == "std::format" and not e.config.std_format_support
),
)
if args.preset:
# whatever the preset; we always want to have a test that does import_std;
# that requires a very specific configuration
collector.sample_combinations(
rgen=rgen,
min_samples_per_value=1,
formatting="std::format",
contracts="none",
config=configs["Clang-18 (x86-64)"],
)
match args.preset:
case None:
pass
Expand Down Expand Up @@ -194,8 +204,6 @@ def main():
)
case "counts":
print(f"Total combinations {len(data)}")
for (k, v), n in sorted(collector.per_value_counts.items()):
print(f" {k}={v}: {n}")
case "none":
pass
case _:
Expand Down
44 changes: 29 additions & 15 deletions .github/job_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ def __init__(
self.full_matrix = full_matrix
self.hard_excludes = hard_excludes
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
}

def _make_submatrix(self, **overrides):
new_matrix = dict(self.full_matrix)
Expand All @@ -80,12 +77,9 @@ def _add_combination(self, e: MatrixElement):
if e in self.combinations or (
self.hard_excludes is not None and self.hard_excludes(e)
):
return
return False
self.combinations.add(e)
# update per_value_counts
for k, v in vars(e).items():
idx = (k, v)
self.per_value_counts[idx] = self.per_value_counts.get(idx, 0) + 1
return True

def all_combinations(
self,
Expand Down Expand Up @@ -118,7 +112,17 @@ def sample_combinations(
for key, options in matrix.items():
for value in options:
idx = (key, value)
missing[idx] = min_samples_per_value - self.per_value_counts.get(idx, 0)
missing[idx] = min_samples_per_value
for e in self.combinations:
for k, v in vars(e).items():
if v not in matrix[k]:
break
else:
# this combination is in the submatrix
for k, v in vars(e).items():
if v in matrix[k]:
missing[k, v] -= 1
n_failed_tries = 0
while missing:
(force_key, force_option), remaining = next(iter(missing.items()))
if remaining <= 0:
Expand All @@ -128,12 +132,22 @@ def sample_combinations(
for key, options in matrix.items():
choice[key] = force_option if key == force_key else rgen.choice(options)
cand = MatrixElement(**choice)
if filter and not filter(cand):
if filter is None or filter(cand):
added = self._add_combination(cand)
else:
added = False
if added:
n_failed_tries = 0
else:
n_failed_tries += 1
if n_failed_tries > 100:
raise RuntimeError(
"Unable to reach the requested minimum number of samples,"
f" still missing the following\n{missing}"
)
continue
self._add_combination(cand)
for idx in choice.items():
if missing.pop(idx, 0) <= 0:
remaining = missing.pop(idx, 0) - 1
if remaining <= 0:
continue
remaining = min_samples_per_value - self.per_value_counts.get(idx, 0)
if remaining > 0:
missing[idx] = remaining
missing[idx] = remaining
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
- id: isort
args: [--profile, black, --multi-line, "3"]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 7.1.0
hooks:
- id: flake8

Expand Down

0 comments on commit e019166

Please sign in to comment.