Projects
openEuler:Mainline
python-pathspec
Sign Up
Log In
Username
Password
We truncated the diff of some files because they were too big. If you want to see the full diff for every file,
click here
.
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 10
View file
_service:tar_scm:python-pathspec.spec
Changed
@@ -1,11 +1,11 @@ %global _empty_manifest_terminate_build 0 Name: python-pathspec -Version: 0.11.1 +Version: 0.11.2 Release: 1 Summary: Utility library for gitignore style pattern matching of file paths. License: MPL-2.0 URL: https://github.com/cpburnz/python-pathspec -Source0: https://files.pythonhosted.org/packages/95/60/d93628975242cc515ab2b8f5b2fc831d8be2eff32f5a1be4776d49305d13/pathspec-0.11.1.tar.gz +Source0: https://files.pythonhosted.org/packages/a0/2a/bd167cdf116d4f3539caaa4c332752aac0b3a0cc0174cdb302ee68933e81/pathspec-0.11.2.tar.gz BuildArch: noarch %description @@ -73,6 +73,9 @@ %{_docdir}/* %changelog +* Tue Aug 01 2023 niuyaru <niuyaru@kylinos.cn> - 0.11.2-1 +- Update package to version 0.11.2 + * Tue Mar 28 2023 wangjunqi <wangjunqi@kylinos.cn> - 0.11.1-1 - Update package to version 0.11.1
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/CHANGES.rst -> _service:tar_scm:pathspec-0.11.2.tar.gz/CHANGES.rst
Changed
@@ -3,6 +3,25 @@ ============== +0.11.2 (2023-07-28) +------------------- + +New features: + +- `Issue #80`_: match_files with negated path spec. `pathspec.PathSpec.match_*()` now have a `negate` parameter to make using *.gitignore* logic easier and more efficient. + +Bug fixes: + +- `Pull #76`_: Add edge case: patterns that end with an escaped space +- `Issue #77`_/`Pull #78`_: Negate with caret symbol as with the exclamation mark. + + +.. _`Pull #76`: https://github.com/cpburnz/python-pathspec/pull/76 +.. _`Issue #77`: https://github.com/cpburnz/python-pathspec/issues/77 +.. _`Pull #78`: https://github.com/cpburnz/python-pathspec/pull/78/ +.. _`Issue #80`: https://github.com/cpburnz/python-pathspec/issues/80 + + 0.11.1 (2023-03-14) ------------------- @@ -15,11 +34,11 @@ - `Pull #75`_: Fix partially unknown PathLike type. - Convert `os.PathLike` to a string properly using `os.fspath`. + .. _`Issue #74`: https://github.com/cpburnz/python-pathspec/issues/74 .. _`Pull #75`: https://github.com/cpburnz/python-pathspec/pull/75 - 0.11.0 (2023-01-24) -------------------
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/PKG-INFO -> _service:tar_scm:pathspec-0.11.2.tar.gz/PKG-INFO
Changed
@@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: pathspec -Version: 0.11.1 +Version: 0.11.2 Summary: Utility library for gitignore style pattern matching of file paths. Author-email: "Caleb P. Burns" <cpburnz@gmail.com> Requires-Python: >=3.7 @@ -196,6 +196,25 @@ ============== +0.11.2 (2023-07-28) +------------------- + +New features: + +- `Issue #80`_: match_files with negated path spec. `pathspec.PathSpec.match_*()` now have a `negate` parameter to make using *.gitignore* logic easier and more efficient. + +Bug fixes: + +- `Pull #76`_: Add edge case: patterns that end with an escaped space +- `Issue #77`_/`Pull #78`_: Negate with caret symbol as with the exclamation mark. + + +.. _`Pull #76`: https://github.com/cpburnz/python-pathspec/pull/76 +.. _`Issue #77`: https://github.com/cpburnz/python-pathspec/issues/77 +.. _`Pull #78`: https://github.com/cpburnz/python-pathspec/pull/78/ +.. _`Issue #80`: https://github.com/cpburnz/python-pathspec/issues/80 + + 0.11.1 (2023-03-14) ------------------- @@ -208,11 +227,11 @@ - `Pull #75`_: Fix partially unknown PathLike type. - Convert `os.PathLike` to a string properly using `os.fspath`. + .. _`Issue #74`: https://github.com/cpburnz/python-pathspec/issues/74 .. _`Pull #75`: https://github.com/cpburnz/python-pathspec/pull/75 - 0.11.0 (2023-01-24) -------------------
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/README-dist.rst -> _service:tar_scm:pathspec-0.11.2.tar.gz/README-dist.rst
Changed
@@ -170,6 +170,25 @@ ============== +0.11.2 (2023-07-28) +------------------- + +New features: + +- `Issue #80`_: match_files with negated path spec. `pathspec.PathSpec.match_*()` now have a `negate` parameter to make using *.gitignore* logic easier and more efficient. + +Bug fixes: + +- `Pull #76`_: Add edge case: patterns that end with an escaped space +- `Issue #77`_/`Pull #78`_: Negate with caret symbol as with the exclamation mark. + + +.. _`Pull #76`: https://github.com/cpburnz/python-pathspec/pull/76 +.. _`Issue #77`: https://github.com/cpburnz/python-pathspec/issues/77 +.. _`Pull #78`: https://github.com/cpburnz/python-pathspec/pull/78/ +.. _`Issue #80`: https://github.com/cpburnz/python-pathspec/issues/80 + + 0.11.1 (2023-03-14) ------------------- @@ -182,11 +201,11 @@ - `Pull #75`_: Fix partially unknown PathLike type. - Convert `os.PathLike` to a string properly using `os.fspath`. + .. _`Issue #74`: https://github.com/cpburnz/python-pathspec/issues/74 .. _`Pull #75`: https://github.com/cpburnz/python-pathspec/pull/75 - 0.11.0 (2023-01-24) -------------------
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/pathspec/_meta.py -> _service:tar_scm:pathspec-0.11.2.tar.gz/pathspec/_meta.py
Changed
@@ -50,6 +50,8 @@ "Avasam <https://github.com/Avasam>", "yschroeder <https://github.com/yschroeder>", "axesider <https://github.com/axesider>", + "tomruk <https://github.com/tomruk>", + "oprypin <https://github.com/oprypin>", __license__ = "MPL 2.0" -__version__ = "0.11.1" +__version__ = "0.11.2"
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/pathspec/pathspec.py -> _service:tar_scm:pathspec-0.11.2.tar.gz/pathspec/pathspec.py
Changed
@@ -1,15 +1,11 @@ """ -This module provides an object oriented interface for pattern matching -of files. +This module provides an object oriented interface for pattern matching of files. """ -import sys from collections.abc import ( Collection as CollectionType) from itertools import ( zip_longest) -from os import ( - PathLike) from typing import ( AnyStr, Callable, @@ -107,15 +103,15 @@ """ Compiles the pattern lines. - *pattern_factory* can be either the name of a registered pattern - factory (:class:`str`), or a :class:`~collections.abc.Callable` used - to compile patterns. It must accept an uncompiled pattern (:class:`str`) - and return the compiled pattern (:class:`.Pattern`). + *pattern_factory* can be either the name of a registered pattern factory + (:class:`str`), or a :class:`~collections.abc.Callable` used to compile + patterns. It must accept an uncompiled pattern (:class:`str`) and return the + compiled pattern (:class:`.Pattern`). - *lines* (:class:`~collections.abc.Iterable`) yields each uncompiled - pattern (:class:`str`). This simply has to yield each line so it can - be a :class:`io.TextIOBase` (e.g., from :func:`open` or - :class:`io.StringIO`) or the result from :meth:`str.splitlines`. + *lines* (:class:`~collections.abc.Iterable`) yields each uncompiled pattern + (:class:`str`). This simply has to yield each line so that it can be a + :class:`io.TextIOBase` (e.g., from :func:`open` or :class:`io.StringIO`) or + the result from :meth:`str.splitlines`. Returns the :class:`PathSpec` instance. """ @@ -135,6 +131,8 @@ self, entries: IterableTreeEntry, separators: OptionalCollectionstr = None, + *, + negate: Optionalbool = None, ) -> IteratorTreeEntry: """ Matches the entries to this path-spec. @@ -142,10 +140,14 @@ *entries* (:class:`~collections.abc.Iterable` of :class:`~util.TreeEntry`) contains the entries to be matched against :attr:`self.patterns <PathSpec.patterns>`. - *separators* (:class:`~collections.abc.Collection` of :class:`str`; - or :data:`None`) optionally contains the path separators to - normalize. See :func:`~pathspec.util.normalize_file` for more - information. + *separators* (:class:`~collections.abc.Collection` of :class:`str`; or + :data:`None`) optionally contains the path separators to normalize. See + :func:`~pathspec.util.normalize_file` for more information. + + *negate* (:class:`bool` or :data:`None`) is whether to negate the match + results of the patterns. If :data:`True`, a pattern matching a file will + exclude the file rather than include it. Default is :data:`None` for + :data:`False`. Returns the matched entries (:class:`~collections.abc.Iterator` of :class:`~util.TreeEntry`). @@ -156,12 +158,17 @@ use_patterns = _filter_patterns(self.patterns) for entry in entries: norm_file = normalize_file(entry.path, separators) - if self._match_file(use_patterns, norm_file): + is_match = self._match_file(use_patterns, norm_file) + + if negate: + is_match = not is_match + + if is_match: yield entry - # Match files using the `match_file()` utility function. Subclasses - # may override this method as an instance method. It does not have to - # be a static method. + # Match files using the `match_file()` utility function. Subclasses may + # override this method as an instance method. It does not have to be a static + # method. _match_file = staticmethod(match_file) def match_file( @@ -188,6 +195,8 @@ self, files: IterableStrPath, separators: OptionalCollectionstr = None, + *, + negate: Optionalbool = None, ) -> IteratorStrPath: """ Matches the files to this path-spec. @@ -196,10 +205,14 @@ :class:`os.PathLikestr`) contains the file paths to be matched against :attr:`self.patterns <PathSpec.patterns>`. - *separators* (:class:`~collections.abc.Collection` of :class:`str`; - or :data:`None`) optionally contains the path separators to - normalize. See :func:`~pathspec.util.normalize_file` for more - information. + *separators* (:class:`~collections.abc.Collection` of :class:`str`; or + :data:`None`) optionally contains the path separators to normalize. See + :func:`~pathspec.util.normalize_file` for more information. + + *negate* (:class:`bool` or :data:`None`) is whether to negate the match + results of the patterns. If :data:`True`, a pattern matching a file will + exclude the file rather than include it. Default is :data:`None` for + :data:`False`. Returns the matched files (:class:`~collections.abc.Iterator` of :class:`str` or :class:`os.PathLikestr`). @@ -210,7 +223,12 @@ use_patterns = _filter_patterns(self.patterns) for orig_file in files: norm_file = normalize_file(orig_file, separators) - if self._match_file(use_patterns, norm_file): + is_match = self._match_file(use_patterns, norm_file) + + if negate: + is_match = not is_match + + if is_match: yield orig_file def match_tree_entries( @@ -218,55 +236,69 @@ root: StrPath, on_error: OptionalCallable = None, follow_links: Optionalbool = None, + *, + negate: Optionalbool = None, ) -> IteratorTreeEntry: """ Walks the specified root path for all files and matches them to this path-spec. - *root* (:class:`str` or :class:`os.PathLikestr`) is the root directory - to search. + *root* (:class:`str` or :class:`os.PathLikestr`) is the root directory to + search. - *on_error* (:class:`~collections.abc.Callable` or :data:`None`) - optionally is the error handler for file-system exceptions. See + *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally + is the error handler for file-system exceptions. See :func:`~pathspec.util.iter_tree_entries` for more information. - *follow_links* (:class:`bool` or :data:`None`) optionally is whether - to walk symbolic links that resolve to directories. See + *follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk + symbolic links that resolve to directories. See :func:`~pathspec.util.iter_tree_files` for more information. + *negate* (:class:`bool` or :data:`None`) is whether to negate the match + results of the patterns. If :data:`True`, a pattern matching a file will + exclude the file rather than include it. Default is :data:`None` for + :data:`False`. + Returns the matched files (:class:`~collections.abc.Iterator` of :class:`.TreeEntry`). """ entries = util.iter_tree_entries(root, on_error=on_error, follow_links=follow_links) - yield from self.match_entries(entries) + yield from self.match_entries(entries, negate=negate) def match_tree_files( self, root: StrPath, on_error: OptionalCallable = None, follow_links: Optionalbool = None, + *, + negate: Optionalbool = None, ) -> Iteratorstr: """ Walks the specified root path for all files and matches them to this path-spec. - *root* (:class:`str` or :class:`os.PathLikestr`) is the root directory - to search for files. + *root* (:class:`str` or :class:`os.PathLikestr`) is the root directory to + search for files. - *on_error* (:class:`~collections.abc.Callable` or :data:`None`) - optionally is the error handler for file-system exceptions. See + *on_error* (:class:`~collections.abc.Callable` or :data:`None`) optionally + is the error handler for file-system exceptions. See :func:`~pathspec.util.iter_tree_files` for more information. - *follow_links* (:class:`bool` or :data:`None`) optionally is whether - to walk symbolic links that resolve to directories. See + *follow_links* (:class:`bool` or :data:`None`) optionally is whether to walk + symbolic links that resolve to directories. See
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/pathspec/patterns/gitwildmatch.py -> _service:tar_scm:pathspec-0.11.2.tar.gz/pathspec/patterns/gitwildmatch.py
Changed
@@ -68,7 +68,14 @@ raise TypeError(f"pattern:{pattern!r} is not a unicode or byte string.") original_pattern = pattern - pattern = pattern.strip() + + if pattern.endswith('\\ '): + # EDGE CASE: Spaces can be escaped with backslash. + # If a pattern that ends with backslash followed by a space, + # only strip from left. + pattern = pattern.lstrip() + else: + pattern = pattern.strip() if pattern.startswith('#'): # A pattern starting with a hash ('#') serves as a comment @@ -283,13 +290,16 @@ # - "-" matches '' and '-'. # - "!a-" matches any character except '', 'a' and '-'. j = i - # Pass brack expression negation. - if j < end and patternj == '!': + + # Pass bracket expression negation. + if j < end and (patternj == '!' or patternj == '^'): j += 1 + # Pass first closing bracket if it is at the beginning of the # expression. if j < end and patternj == '': j += 1 + # Find closing bracket. Stop once we reach the end or find it. while j < end and patternj != '': j += 1 @@ -306,16 +316,17 @@ expr = '' if patterni == '!': - # Braket expression needs to be negated. + # Bracket expression needs to be negated. expr += '^' i += 1 elif patterni == '^': # POSIX declares that the regex bracket expression negation # "^..." is undefined in a glob pattern. Python's # `fnmatch.translate()` escapes the caret ('^') as a - # literal. To maintain consistency with undefined behavior, - # I am escaping the '^' as well. - expr += '\\^' + # literal. Git supports the using a caret for negation. + # Maintain consistency with Git because that is the expected + # behavior. + expr += '^' i += 1 # Build regex bracket expression. Escape slashes so they are
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/tests/test_gitwildmatch.py -> _service:tar_scm:pathspec-0.11.2.tar.gz/tests/test_gitwildmatch.py
Changed
@@ -773,3 +773,41 @@ self.assertEqual(results, { 'anydir/file.txt', }) + + def test_13_issue_77_regex(self): + """ + Test the resulting regex for regex bracket expression negation. + """ + regex, include = GitWildMatchPattern.pattern_to_regex('a^bc') + self.assertTrue(include) + + equiv_regex, include = GitWildMatchPattern.pattern_to_regex('a!bc') + self.assertTrue(include) + + self.assertEqual(regex, equiv_regex) + + def test_13_negate_with_caret(self): + """ + Test negation using the caret symbol (^) + """ + pattern = GitWildMatchPattern("a^gyc") + results = set(filter(pattern.match_file, + "agc", + "ayc", + "abc", + "adc", + )) + self.assertEqual(results, {"abc", "adc"}) + + def test_13_negate_with_exclamation_mark(self): + """ + Test negation using the exclamation mark (!) + """ + pattern = GitWildMatchPattern("a!gyc") + results = set(filter(pattern.match_file, + "agc", + "ayc", + "abc", + "adc", + )) + self.assertEqual(results, {"abc", "adc"})
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/tests/test_pathspec.py -> _service:tar_scm:pathspec-0.11.2.tar.gz/tests/test_pathspec.py
Changed
@@ -15,6 +15,7 @@ PathSpec) from pathspec.util import ( iter_tree_entries) +from pathspec.patterns.gitwildmatch import GitWildMatchPatternError from tests.util import ( make_dirs, make_files, @@ -119,6 +120,32 @@ './src/test2/c/c.txt', }) + def test_01_empty_path(self): + """ + Tests that patterns that end with an escaped space will be treated properly. + """ + spec = PathSpec.from_lines('gitwildmatch', + '\\ ', + 'abc\\ ' + ) + test_files = + ' ', + ' ', + 'abc ', + 'somefile', + + results = list(filter(spec.match_file, test_files)) + self.assertEqual(results, + ' ', + 'abc ' + ) + + # An escape with double spaces is invalid. + # Disallow it. Better to be safe than sorry. + self.assertRaises(GitWildMatchPatternError, lambda: PathSpec.from_lines('gitwildmatch', + '\\ ' + )) + def test_01_match_files(self): """ Tests that matching files one at a time yields the same results as @@ -552,3 +579,53 @@ 'important/d.log', 'important/e.txt', }) + + def test_09_issue_80_a(self): + """ + Test negating patterns. + """ + spec = PathSpec.from_lines('gitwildmatch', + 'build', + '*.log', + '.*', + '!.gitignore', + ) + files = { + '.c-tmp', + '.gitignore', + 'a.log', + 'b.txt', + 'build/d.log', + 'build/trace.bin', + 'trace.c', + } + keeps = set(spec.match_files(files, negate=True)) + self.assertEqual(keeps, { + '.gitignore', + 'b.txt', + 'trace.c', + }) + + def test_09_issue_80_b(self): + """ + Test negating patterns. + """ + spec = PathSpec.from_lines('gitwildmatch', + 'build', + '*.log', + '.*', + '!.gitignore', + ) + files = { + '.c-tmp', + '.gitignore', + 'a.log', + 'b.txt', + 'build/d.log', + 'build/trace.bin', + 'trace.c', + } + keeps = set(spec.match_files(files, negate=True)) + ignores = set(spec.match_files(files)) + self.assertEqual(files - ignores, keeps) + self.assertEqual(files - keeps, ignores)
View file
_service:tar_scm:pathspec-0.11.1.tar.gz/tox.ini -> _service:tar_scm:pathspec-0.11.2.tar.gz/tox.ini
Changed
@@ -1,5 +1,5 @@ tox -envlist = py37, py38, py39, py310, py311, pypy3 +envlist = py37, py38, py39, py310, py311, py312, pypy3 isolated_build = True testenv
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2