Support pathspec v1 (#10951)

Co-authored-by: Saugat Pachhai (सौगात) <[email protected]>
This commit is contained in:
Caleb P. Burns
2026-01-31 11:12:13 +05:45
committed by GitHub
co-authored by Saugat Pachhai
parent 1e8962bf0c
commit c6c680d2b2
2 changed files with 19 additions and 4 deletions
+18 -3
View File
@@ -5,7 +5,15 @@ from collections.abc import Iterable, Iterator
from itertools import chain, groupby, takewhile
from typing import TYPE_CHECKING, Any, Literal, NamedTuple, Optional, Union, overload
from pathspec.patterns import GitWildMatchPattern
try:
from pathspec.patterns.gitignore.spec import ( # type: ignore[import-not-found]
GitIgnoreSpecPattern,
)
except ImportError: # pathspec<1
from pathspec.patterns import (
GitWildMatchPattern as GitIgnoreSpecPattern,
)
from pathspec.util import normalize_file
from pygtrie import Trie
@@ -34,7 +42,14 @@ class DvcIgnorePatterns(DvcIgnore):
def __init__(
self, pattern_list: Iterable[Union[PatternInfo, str]], dirname: str, sep: str
) -> None:
from pathspec.patterns.gitwildmatch import _DIR_MARK
try:
from pathspec.patterns.gitignore.spec import ( # type: ignore[import-not-found]
_DIR_MARK,
)
except ImportError: # pathspec<1
from pathspec.patterns.gitwildmatch import ( # type: ignore[attr-defined, no-redef]
_DIR_MARK,
)
pattern_infos = [
pattern if isinstance(pattern, PatternInfo) else PatternInfo(pattern, "")
@@ -48,7 +63,7 @@ class DvcIgnorePatterns(DvcIgnore):
regex_pattern_list: list[tuple[str, bool, bool, PatternInfo]] = []
for count, pattern_info in enumerate(pattern_infos):
regex, ignore = GitWildMatchPattern.pattern_to_regex(pattern_info.patterns)
regex, ignore = GitIgnoreSpecPattern.pattern_to_regex(pattern_info.patterns)
if regex is not None and ignore is not None:
self.pattern_list.append(pattern_info)
regex = regex.replace(f"<{_DIR_MARK}>", f"<{_DIR_MARK}{count}>")
+1 -1
View File
@@ -59,7 +59,7 @@ dependencies = [
"networkx>=2.5",
"omegaconf",
"packaging>=19",
"pathspec>=0.10.3,<1",
"pathspec>=0.10.3,<2",
"platformdirs<5,>=3.1.1",
"psutil>=5.8",
"pydot>=1.2.4",