55from itertools import chain , groupby , takewhile
66from typing import TYPE_CHECKING , Any , Literal , NamedTuple , Optional , Union , overload
77
8- from pathspec .patterns import GitWildMatchPattern
8+ try :
9+ from pathspec .patterns .gitignore .spec import ( # type: ignore[import-not-found]
10+ GitIgnoreSpecPattern ,
11+ )
12+ except ImportError : # pathspec<1
13+ from pathspec .patterns import (
14+ GitWildMatchPattern as GitIgnoreSpecPattern ,
15+ )
16+
917from pathspec .util import normalize_file
1018from pygtrie import Trie
1119
@@ -34,7 +42,14 @@ class DvcIgnorePatterns(DvcIgnore):
3442 def __init__ (
3543 self , pattern_list : Iterable [Union [PatternInfo , str ]], dirname : str , sep : str
3644 ) -> None :
37- from pathspec .patterns .gitwildmatch import _DIR_MARK
45+ try :
46+ from pathspec .patterns .gitignore .spec import ( # type: ignore[import-not-found]
47+ _DIR_MARK ,
48+ )
49+ except ImportError : # pathspec<1
50+ from pathspec .patterns .gitwildmatch import ( # type: ignore[attr-defined, no-redef]
51+ _DIR_MARK ,
52+ )
3853
3954 pattern_infos = [
4055 pattern if isinstance (pattern , PatternInfo ) else PatternInfo (pattern , "" )
@@ -48,7 +63,7 @@ def __init__(
4863
4964 regex_pattern_list : list [tuple [str , bool , bool , PatternInfo ]] = []
5065 for count , pattern_info in enumerate (pattern_infos ):
51- regex , ignore = GitWildMatchPattern .pattern_to_regex (pattern_info .patterns )
66+ regex , ignore = GitIgnoreSpecPattern .pattern_to_regex (pattern_info .patterns )
5267 if regex is not None and ignore is not None :
5368 self .pattern_list .append (pattern_info )
5469 regex = regex .replace (f"<{ _DIR_MARK } >" , f"<{ _DIR_MARK } { count } >" )
0 commit comments