Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions dvc/ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
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

Expand Down Expand Up @@ -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, "")
Expand All @@ -48,7 +63,7 @@ def __init__(

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}>")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading