Skip to content

Commit c6c680d

Browse files
cpburnzskshetry
andauthored
Support pathspec v1 (#10951)
Co-authored-by: Saugat Pachhai (सौगात) <suagatchhetri@outlook.com>
1 parent 1e8962b commit c6c680d

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

dvc/ignore.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
from itertools import chain, groupby, takewhile
66
from 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+
917
from pathspec.util import normalize_file
1018
from 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}>")

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dependencies = [
5959
"networkx>=2.5",
6060
"omegaconf",
6161
"packaging>=19",
62-
"pathspec>=0.10.3,<1",
62+
"pathspec>=0.10.3,<2",
6363
"platformdirs<5,>=3.1.1",
6464
"psutil>=5.8",
6565
"pydot>=1.2.4",

0 commit comments

Comments
 (0)