Skip to content

Commit 298c61e

Browse files
authored
feat: Correct behavior of matrix fallback priority, error on duplicate matrix selectors. (#110)
1 parent 8455d42 commit 298c61e

File tree

6 files changed

+87
-12
lines changed

6 files changed

+87
-12
lines changed

src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,20 @@ def make_dependency_files(
389389
if file_type not in specific_entry.output_types:
390390
continue
391391

392-
found = False
392+
# Ensure that all specific matrices are unique
393+
num_matrices = len(specific_entry.matrices)
394+
num_unique = len(
395+
{
396+
frozenset(specific_matrices_entry.matrix.items())
397+
for specific_matrices_entry in specific_entry.matrices
398+
}
399+
)
400+
if num_matrices != num_unique:
401+
err = f"All matrix entries must be unique. Found duplicates in '{include}':"
402+
for specific_matrices_entry in specific_entry.matrices:
403+
err += f"\n - {specific_matrices_entry.matrix}"
404+
raise ValueError(err)
405+
393406
fallback_entry = None
394407
for specific_matrices_entry in specific_entry.matrices:
395408
# An empty `specific_matrices_entry["matrix"]` is
@@ -403,18 +416,12 @@ def make_dependency_files(
403416
continue
404417

405418
if should_use_specific_entry(matrix_combo, specific_matrices_entry.matrix):
406-
# Raise an error if multiple specific entries
407-
# (not including the fallback_entry) match a
408-
# requested matrix combination.
409-
if found:
410-
raise ValueError(f"Found multiple matches for matrix {matrix_combo}")
411-
found = True
412419
# A package list may be empty as a way to
413420
# indicate that for some matrix elements no
414421
# packages should be installed.
415422
dependencies.extend(specific_matrices_entry.packages or [])
416-
417-
if not found:
423+
break
424+
else:
418425
if fallback_entry:
419426
dependencies.extend(fallback_entry.packages)
420427
else:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
files:
2+
all:
3+
output: conda
4+
conda_dir: output/actual
5+
matrix:
6+
cuda: ["11.5", "11.8"]
7+
includes:
8+
- cudatoolkit
9+
channels:
10+
- rapidsai
11+
- conda-forge
12+
dependencies:
13+
cudatoolkit:
14+
specific:
15+
- output_types: conda
16+
matrices:
17+
- matrix:
18+
cuda: "11.5"
19+
packages:
20+
- cudatoolkit=11.5
21+
- matrix:
22+
cuda: "11.5"
23+
packages:
24+
- cudatoolkit=11.5
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
files:
2+
all:
3+
output: conda
4+
conda_dir: output/actual
5+
matrix:
6+
cuda: ["11.5", "11.8"]
7+
includes:
8+
- cudatoolkit
9+
channels:
10+
- rapidsai
11+
- conda-forge
12+
dependencies:
13+
cudatoolkit:
14+
specific:
15+
- output_types: conda
16+
matrices:
17+
- matrix:
18+
cuda: "11.5"
19+
packages:
20+
- cudatoolkit=11.5
21+
- matrix:
22+
cuda: "11.*"
23+
packages:
24+
- cudatoolkit=11.*
25+
- matrix:
26+
packages:
27+
- cudatoolkit
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file is generated by `rapids-dependency-file-generator`.
2+
# To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.
3+
channels:
4+
- rapidsai
5+
- conda-forge
6+
dependencies:
7+
- cudatoolkit=11.5
8+
name: all_cuda-115
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# This file is generated by `rapids-dependency-file-generator`.
2+
# To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`.
3+
channels:
4+
- rapidsai
5+
- conda-forge
6+
dependencies:
7+
- cudatoolkit=11.*
8+
name: all_cuda-118

tests/test_examples.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515
# Erroneous examples raise runtime errors from the generator.
1616
_erroneous_examples = [
17+
"duplicate-specific-matrix-entries",
1718
"no-specific-match",
18-
"pyproject_matrix_multi",
19-
"pyproject_bad_key",
2019
"pyproject-no-extras",
21-
"requirements-pip-dict"
20+
"pyproject_bad_key",
21+
"pyproject_matrix_multi",
22+
"requirements-pip-dict",
2223
]
2324
EXAMPLE_FILES = [
2425
pth

0 commit comments

Comments
 (0)