offgrep 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {offgrep-0.1.0 → offgrep-0.1.1}/PKG-INFO +1 -1
- {offgrep-0.1.0 → offgrep-0.1.1}/pyproject.toml +1 -1
- {offgrep-0.1.0 → offgrep-0.1.1}/src/offgrep/__main__.py +4 -2
- {offgrep-0.1.0 → offgrep-0.1.1}/src/offgrep/ignore.py +12 -14
- {offgrep-0.1.0 → offgrep-0.1.1}/LICENSE +0 -0
- {offgrep-0.1.0 → offgrep-0.1.1}/README.md +0 -0
- {offgrep-0.1.0 → offgrep-0.1.1}/src/offgrep/__init__.py +0 -0
- {offgrep-0.1.0 → offgrep-0.1.1}/src/offgrep/commons.py +0 -0
- {offgrep-0.1.0 → offgrep-0.1.1}/src/offgrep/filesystem.py +0 -0
- {offgrep-0.1.0 → offgrep-0.1.1}/src/offgrep/git.py +0 -0
|
@@ -75,8 +75,10 @@ def find_in_files(
|
|
|
75
75
|
#
|
|
76
76
|
#
|
|
77
77
|
#
|
|
78
|
-
except UnicodeDecodeError
|
|
79
|
-
debug(
|
|
78
|
+
except UnicodeDecodeError:
|
|
79
|
+
debug(
|
|
80
|
+
"assuming binary file %s because of unicode decode error", single_file
|
|
81
|
+
)
|
|
80
82
|
except OSError as os_error:
|
|
81
83
|
error(str(os_error))
|
|
82
84
|
continue
|
|
@@ -8,7 +8,6 @@ from dataclasses import dataclass
|
|
|
8
8
|
from enum import StrEnum
|
|
9
9
|
from functools import lru_cache
|
|
10
10
|
from logging import debug, warning
|
|
11
|
-
from os.path import normcase
|
|
12
11
|
from pathlib import Path
|
|
13
12
|
from re import compile as re_compile, escape
|
|
14
13
|
from typing import Self
|
|
@@ -70,7 +69,7 @@ class CompiledPattern:
|
|
|
70
69
|
"""Pattern to match relative file paths"""
|
|
71
70
|
|
|
72
71
|
def __init__(
|
|
73
|
-
self, regex_pattern: str, negated: bool = False,
|
|
72
|
+
self, regex_pattern: str, negated: bool = False, case_sensitive: bool = True
|
|
74
73
|
) -> None:
|
|
75
74
|
"""compile the RE pattern
|
|
76
75
|
|
|
@@ -78,13 +77,13 @@ class CompiledPattern:
|
|
|
78
77
|
regex_pattern: the regular expression pattern
|
|
79
78
|
negated: Flag indicating whether the pattern excludes (`False`)
|
|
80
79
|
or re-includes a previously excluded path (`True`)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
case_sensitive: Flag indicating whether to use case sensitive
|
|
81
|
+
file name matching or not. Converts regex_pattern to lower case
|
|
82
|
+
if set `False`.
|
|
84
83
|
"""
|
|
85
84
|
self.negated = negated
|
|
86
|
-
self.regex_pattern =
|
|
87
|
-
self.
|
|
85
|
+
self.regex_pattern = regex_pattern.lower() if case_sensitive else regex_pattern
|
|
86
|
+
self.case_sensitive = case_sensitive
|
|
88
87
|
self._cre = re_compile(regex_pattern)
|
|
89
88
|
|
|
90
89
|
def matches(self, relative_path: str) -> bool:
|
|
@@ -96,14 +95,14 @@ class CompiledPattern:
|
|
|
96
95
|
Returns:
|
|
97
96
|
`True` if the path matches the pattern, `False` if not
|
|
98
97
|
"""
|
|
99
|
-
if self.
|
|
100
|
-
relative_path =
|
|
98
|
+
if self.case_sensitive:
|
|
99
|
+
relative_path = relative_path.lower()
|
|
101
100
|
#
|
|
102
101
|
return self._cre.match(relative_path) is not None
|
|
103
102
|
|
|
104
103
|
@classmethod
|
|
105
104
|
def from_gitignore_line(
|
|
106
|
-
cls, gitignore_line: str,
|
|
105
|
+
cls, gitignore_line: str, case_sensitive: bool = True
|
|
107
106
|
) -> Self:
|
|
108
107
|
"""Factory method: compiled pattern from a `.gitignore` entry
|
|
109
108
|
|
|
@@ -111,9 +110,8 @@ class CompiledPattern:
|
|
|
111
110
|
gitignore_line: a line from a `.gitignore` file
|
|
112
111
|
(or `$GIT_DIR/info/exclude`, or the file specified by the
|
|
113
112
|
`core.excludesFile` configuration directive)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
defaults (`True`), or to always match case sensitive (`False`)
|
|
113
|
+
case_sensitive: Flag indicating whether to use case sensitive
|
|
114
|
+
file name matching or not
|
|
117
115
|
|
|
118
116
|
Returns:
|
|
119
117
|
a new instance
|
|
@@ -135,7 +133,7 @@ class CompiledPattern:
|
|
|
135
133
|
return cls(
|
|
136
134
|
gitignore_pattern_to_full_regex(gitignore_line),
|
|
137
135
|
negated=_negated,
|
|
138
|
-
|
|
136
|
+
case_sensitive=case_sensitive,
|
|
139
137
|
)
|
|
140
138
|
|
|
141
139
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|