diff --git a/.github/merge_rules.json b/.github/merge_rules.json index d3cc1a68d87f..937ffb3d9004 100644 --- a/.github/merge_rules.json +++ b/.github/merge_rules.json @@ -100,12 +100,12 @@ "patterns": [ "aten/src/ATen/native/cuda/linalg/**", "aten/src/ATen/LinalgBackend.h", - "aten/src/ATen/native/**/*LinearAlgebra*", + "aten/src/ATen/native/**LinearAlgebra*", "docs/source/linalg.rst", "torch/linalg/**", "torch/_linalg_utils.py", - "torch/**/python_linalg_functions.*", - "torch/**/linalg.h", + "torch/**python_linalg_functions.*", + "torch/**linalg.h", "tools/autograd/templates/python_linalg_functions.cpp", "test/test_linalg.py" ], @@ -126,7 +126,7 @@ "docs/source/fft.rst", "torch/fft/**", "torch/csrc/api/include/torch/fft.h", - "torch/**/python_fft_functions.*", + "torch/**python_fft_functions.*", "tools/autograd/templates/python_fft_functions.cpp", "test/cpp/api/fft.cpp" ], @@ -143,18 +143,18 @@ "benchmarks/sparse", "c10/util/sparse_bitset.h", "docs/source/sparse.rst", - "torch/**/sparse/**", - "torch/**/*sparse*", + "torch/**sparse/**", + "torch/**sparse*", "torch/optim/sparse*", "torch/ao/nn/sparse/**", - "torch/utils/benchmark/**/*sparse*", + "torch/utils/benchmark/**sparse*", "aten/src/ATen/native/ao_sparse/**", "aten/src/ATen/native/sparse/**", - "aten/src/ATen/**/*Sparse*", + "aten/src/ATen/**Sparse*", "aten/src/ATen/*Sparse*", "torch/_masked/**", "test/*_masked*", - "test/**/*sparse*" + "test/**sparse*" ], "approved_by": ["nikitaved", "cpuhrsch", "pearu", "IvanYashchuk"], "mandatory_checks_name": [ diff --git a/.github/scripts/gitutils.py b/.github/scripts/gitutils.py index 4c43fc251fb1..aa64fe15387e 100644 --- a/.github/scripts/gitutils.py +++ b/.github/scripts/gitutils.py @@ -305,8 +305,8 @@ def patterns_to_regex(allowed_patterns: List[str]) -> Any: """ pattern is glob-like, i.e. the only special sequences it has are: - ? - matches single character - - * - matches any non-folder separator characters - - ** - matches any characters + - * - matches any non-folder separator characters or no character + - ** - matches any characters or no character Assuming that patterns are free of braces and backslashes the only character that needs to be escaped are dot and plus """ @@ -324,9 +324,9 @@ def patterns_to_regex(allowed_patterns: List[str]) -> Any: elif c == "*": if pattern_.peek() == "*": next(pattern_) - rc += ".+" + rc += ".*" else: - rc += "[^/]+" + rc += "[^/]*" else: rc += c rc += ")" diff --git a/.github/scripts/test_gitutils.py b/.github/scripts/test_gitutils.py index 80a6e148e1ee..78696771d993 100644 --- a/.github/scripts/test_gitutils.py +++ b/.github/scripts/test_gitutils.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -from gitutils import PeekableIterator +from gitutils import PeekableIterator, patterns_to_regex from unittest import TestCase, main class TestPeekableIterator(TestCase): @@ -22,6 +22,18 @@ class TestPeekableIterator(TestCase): self.assertTrue(iter_.peek() is None) +class TestPattern(TestCase): + def test_double_asterisks(self) -> None: + allowed_patterns = [ + "aten/src/ATen/native/**LinearAlgebra*", + ] + patterns_re = patterns_to_regex(allowed_patterns) + fnames = [ + "aten/src/ATen/native/LinearAlgebra.cpp", + "aten/src/ATen/native/cpu/LinearAlgebraKernel.cpp"] + for filename in fnames: + self.assertTrue(patterns_re.match(filename)) + if __name__ == '__main__': main()