mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
Support pathspec v1 (#10951)
Co-authored-by: Saugat Pachhai (सौगात) <[email protected]>
This commit is contained in:
co-authored by
Saugat Pachhai
parent
1e8962bf0c
commit
c6c680d2b2
+18
-3
@@ -5,7 +5,15 @@ from collections.abc import Iterable, Iterator
|
|||||||
from itertools import chain, groupby, takewhile
|
from itertools import chain, groupby, takewhile
|
||||||
from typing import TYPE_CHECKING, Any, Literal, NamedTuple, Optional, Union, overload
|
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 pathspec.util import normalize_file
|
||||||
from pygtrie import Trie
|
from pygtrie import Trie
|
||||||
|
|
||||||
@@ -34,7 +42,14 @@ class DvcIgnorePatterns(DvcIgnore):
|
|||||||
def __init__(
|
def __init__(
|
||||||
self, pattern_list: Iterable[Union[PatternInfo, str]], dirname: str, sep: str
|
self, pattern_list: Iterable[Union[PatternInfo, str]], dirname: str, sep: str
|
||||||
) -> None:
|
) -> 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_infos = [
|
||||||
pattern if isinstance(pattern, PatternInfo) else PatternInfo(pattern, "")
|
pattern if isinstance(pattern, PatternInfo) else PatternInfo(pattern, "")
|
||||||
@@ -48,7 +63,7 @@ class DvcIgnorePatterns(DvcIgnore):
|
|||||||
|
|
||||||
regex_pattern_list: list[tuple[str, bool, bool, PatternInfo]] = []
|
regex_pattern_list: list[tuple[str, bool, bool, PatternInfo]] = []
|
||||||
for count, pattern_info in enumerate(pattern_infos):
|
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:
|
if regex is not None and ignore is not None:
|
||||||
self.pattern_list.append(pattern_info)
|
self.pattern_list.append(pattern_info)
|
||||||
regex = regex.replace(f"<{_DIR_MARK}>", f"<{_DIR_MARK}{count}>")
|
regex = regex.replace(f"<{_DIR_MARK}>", f"<{_DIR_MARK}{count}>")
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ dependencies = [
|
|||||||
"networkx>=2.5",
|
"networkx>=2.5",
|
||||||
"omegaconf",
|
"omegaconf",
|
||||||
"packaging>=19",
|
"packaging>=19",
|
||||||
"pathspec>=0.10.3,<1",
|
"pathspec>=0.10.3,<2",
|
||||||
"platformdirs<5,>=3.1.1",
|
"platformdirs<5,>=3.1.1",
|
||||||
"psutil>=5.8",
|
"psutil>=5.8",
|
||||||
"pydot>=1.2.4",
|
"pydot>=1.2.4",
|
||||||
|
|||||||
Reference in New Issue
Block a user