diff --git a/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py b/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py index 4fc186c..b201e36 100644 --- a/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py +++ b/src/rapids_dependency_file_generator/_rapids_dependency_file_generator.py @@ -389,7 +389,20 @@ def make_dependency_files( if file_type not in specific_entry.output_types: continue - found = False + # Ensure that all specific matrices are unique + num_matrices = len(specific_entry.matrices) + num_unique = len( + { + frozenset(specific_matrices_entry.matrix.items()) + for specific_matrices_entry in specific_entry.matrices + } + ) + if num_matrices != num_unique: + err = f"All matrix entries must be unique. Found duplicates in '{include}':" + for specific_matrices_entry in specific_entry.matrices: + err += f"\n - {specific_matrices_entry.matrix}" + raise ValueError(err) + fallback_entry = None for specific_matrices_entry in specific_entry.matrices: # An empty `specific_matrices_entry["matrix"]` is @@ -403,18 +416,12 @@ def make_dependency_files( continue if should_use_specific_entry(matrix_combo, specific_matrices_entry.matrix): - # Raise an error if multiple specific entries - # (not including the fallback_entry) match a - # requested matrix combination. - if found: - raise ValueError(f"Found multiple matches for matrix {matrix_combo}") - found = True # A package list may be empty as a way to # indicate that for some matrix elements no # packages should be installed. dependencies.extend(specific_matrices_entry.packages or []) - - if not found: + break + else: if fallback_entry: dependencies.extend(fallback_entry.packages) else: diff --git a/tests/examples/duplicate-specific-matrix-entries/dependencies.yaml b/tests/examples/duplicate-specific-matrix-entries/dependencies.yaml new file mode 100644 index 0000000..54a262f --- /dev/null +++ b/tests/examples/duplicate-specific-matrix-entries/dependencies.yaml @@ -0,0 +1,24 @@ +files: + all: + output: conda + conda_dir: output/actual + matrix: + cuda: ["11.5", "11.8"] + includes: + - cudatoolkit +channels: + - rapidsai + - conda-forge +dependencies: + cudatoolkit: + specific: + - output_types: conda + matrices: + - matrix: + cuda: "11.5" + packages: + - cudatoolkit=11.5 + - matrix: + cuda: "11.5" + packages: + - cudatoolkit=11.5 diff --git a/tests/examples/specific-fallback-multiple-matches/dependencies.yaml b/tests/examples/specific-fallback-multiple-matches/dependencies.yaml new file mode 100644 index 0000000..0d33b4f --- /dev/null +++ b/tests/examples/specific-fallback-multiple-matches/dependencies.yaml @@ -0,0 +1,27 @@ +files: + all: + output: conda + conda_dir: output/actual + matrix: + cuda: ["11.5", "11.8"] + includes: + - cudatoolkit +channels: + - rapidsai + - conda-forge +dependencies: + cudatoolkit: + specific: + - output_types: conda + matrices: + - matrix: + cuda: "11.5" + packages: + - cudatoolkit=11.5 + - matrix: + cuda: "11.*" + packages: + - cudatoolkit=11.* + - matrix: + packages: + - cudatoolkit diff --git a/tests/examples/specific-fallback-multiple-matches/output/expected/all_cuda-115.yaml b/tests/examples/specific-fallback-multiple-matches/output/expected/all_cuda-115.yaml new file mode 100644 index 0000000..f9ab85d --- /dev/null +++ b/tests/examples/specific-fallback-multiple-matches/output/expected/all_cuda-115.yaml @@ -0,0 +1,8 @@ +# This file is generated by `rapids-dependency-file-generator`. +# To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`. +channels: +- rapidsai +- conda-forge +dependencies: +- cudatoolkit=11.5 +name: all_cuda-115 diff --git a/tests/examples/specific-fallback-multiple-matches/output/expected/all_cuda-118.yaml b/tests/examples/specific-fallback-multiple-matches/output/expected/all_cuda-118.yaml new file mode 100644 index 0000000..f9f9290 --- /dev/null +++ b/tests/examples/specific-fallback-multiple-matches/output/expected/all_cuda-118.yaml @@ -0,0 +1,8 @@ +# This file is generated by `rapids-dependency-file-generator`. +# To make changes, edit ../../dependencies.yaml and run `rapids-dependency-file-generator`. +channels: +- rapidsai +- conda-forge +dependencies: +- cudatoolkit=11.* +name: all_cuda-118 diff --git a/tests/test_examples.py b/tests/test_examples.py index c47ca35..2c5294d 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -14,11 +14,12 @@ # Erroneous examples raise runtime errors from the generator. _erroneous_examples = [ + "duplicate-specific-matrix-entries", "no-specific-match", - "pyproject_matrix_multi", - "pyproject_bad_key", "pyproject-no-extras", - "requirements-pip-dict" + "pyproject_bad_key", + "pyproject_matrix_multi", + "requirements-pip-dict", ] EXAMPLE_FILES = [ pth