Skip to content

Commit

Permalink
Use regex to search for CUDA suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleFromNVIDIA committed May 28, 2024
1 parent dab4d78 commit 36f2881
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rapids_pre_commit_hooks/alpha_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from functools import reduce

import yaml
Expand Down Expand Up @@ -58,14 +59,17 @@
"requirements",
}

CUDA_SUFFIX_REGEX = re.compile(r"^(?P<package>.*)-cu[0-9]{2}$")


def node_has_type(node, tag_type):
return node.tag == f"tag:yaml.org,2002:{tag_type}"


def is_rapids_cuda_suffixed_package(name):
return any(
name.startswith(f"{package}-cu") for package in RAPIDS_CUDA_SUFFIXED_PACKAGES
(match := CUDA_SUFFIX_REGEX.search(name)) and match.group("package") == package
for package in RAPIDS_CUDA_SUFFIXED_PACKAGES
)


Expand Down
30 changes: 30 additions & 0 deletions test/rapids_pre_commit_hooks/test_alpha_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,36 @@
from rapids_pre_commit_hooks import alpha_spec, lint


@pytest.mark.parametrize(
["name", "is_suffixed"],
[
*chain(
*(
[
(f"{p}-cu11", True),
(f"{p}-cu12", True),
(f"{p}-cuda", False),
]
for p in alpha_spec.RAPIDS_CUDA_SUFFIXED_PACKAGES
)
),
*chain(
*(
[
(f"{p}-cu11", False),
(f"{p}-cu12", False),
(f"{p}-cuda", False),
]
for p in alpha_spec.RAPIDS_ALPHA_SPEC_PACKAGES
- alpha_spec.RAPIDS_CUDA_SUFFIXED_PACKAGES
)
),
],
)
def test_is_rapids_cuda_suffixed_package(name, is_suffixed):
assert alpha_spec.is_rapids_cuda_suffixed_package(name) == is_suffixed


@pytest.mark.parametrize(
["package", "content", "mode", "replacement"],
[
Expand Down

0 comments on commit 36f2881

Please sign in to comment.