From 3b8ef68c5c88defbcaca64df2920b50503630e14 Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:19:26 +0100 Subject: [PATCH 1/9] Add test_4_normalizing_pathlib_paths --- pathspec/tests/test_util.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pathspec/tests/test_util.py b/pathspec/tests/test_util.py index cf01aa6..95289cd 100644 --- a/pathspec/tests/test_util.py +++ b/pathspec/tests/test_util.py @@ -10,7 +10,7 @@ import tempfile import unittest -from pathspec.util import iter_tree_entries, iter_tree_files, RecursionError +from pathspec.util import iter_tree_entries, iter_tree_files, RecursionError, normalize_file class IterTreeTest(unittest.TestCase): @@ -367,3 +367,12 @@ def test_3_entries(self): 'Dir/Inner/f', 'Empty', ]))) + + def test_4_normalizing_pathlib_paths(self): + """ + Tests passing pathlib.Path as argument. + """ + from pathlib import Path + first_spec = normalize_file([Path('a.txt')]) + second_spec = normalize_file(['a.txt']) + self.assertNotEqual(first_spec, second_spec) From 56a87d8b4d44c079bb17fa7190d8baccafabbc8c Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:26:28 +0100 Subject: [PATCH 2/9] Make normalize_file stringify --- pathspec/util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pathspec/util.py b/pathspec/util.py index 9a34e76..33c4dd3 100644 --- a/pathspec/util.py +++ b/pathspec/util.py @@ -262,7 +262,7 @@ def normalize_file(file, separators=None): """ Normalizes the file path to use the POSIX path separator (i.e., ``'/'``). - *file* (:class:`str`) is the file path. + *file* (:class:`str` or :class: `Path`) is the file path. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. @@ -276,7 +276,7 @@ def normalize_file(file, separators=None): # Normalize path separators. if separators is None: separators = NORMALIZE_PATH_SEPS - norm_file = file + norm_file = str(file) for sep in separators: norm_file = norm_file.replace(sep, posixpath.sep) From 0a9fd62841fc862b80be512f0b0e181898f94b07 Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:35:06 +0100 Subject: [PATCH 3/9] Update docstrings --- pathspec/pathspec.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pathspec/pathspec.py b/pathspec/pathspec.py index 0a24364..1e602a9 100644 --- a/pathspec/pathspec.py +++ b/pathspec/pathspec.py @@ -78,8 +78,8 @@ def match_file(self, file, separators=None): """ Matches the file to this path-spec. - *file* (:class:`str`) is the file path to be matched against - :attr:`self.patterns `. + *file* (:class:`str` or :class: `Path`) is the file path to be + matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`) optionally contains the path separators to normalize. See @@ -94,9 +94,9 @@ def match_files(self, files, separators=None): """ Matches the files to this path-spec. - *files* (:class:`~collections.abc.Iterable` of :class:`str`) contains - the file paths to be matched against :attr:`self.patterns - `. + *files* (:class:`~collections.abc.Iterable` of + (:class:`str` or :class: `Path`)) contains the file paths to be + matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to @@ -119,7 +119,8 @@ def match_tree_files(self, root, on_error=None, follow_links=None): Walks the specified root path for all files and matches them to this path-spec. - *root* (:class:`str`) is the root directory to search for files. + *root* (:class:`str` or :class: `Path`) 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 @@ -132,6 +133,7 @@ def match_tree_files(self, root, on_error=None, follow_links=None): Returns the matched files (:class:`~collections.abc.Iterable` of :class:`str`). """ + root = str(root) # stringify pathlib.Path files = util.iter_tree_files(root, on_error=on_error, follow_links=follow_links) return self.match_files(files) From 0c370ad6f00a218d4cec64f47d67d802a9f24905 Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:41:20 +0100 Subject: [PATCH 4/9] Add skipIf to test_4_normalizing_pathlib_paths --- pathspec/tests/test_util.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pathspec/tests/test_util.py b/pathspec/tests/test_util.py index 95289cd..5c23637 100644 --- a/pathspec/tests/test_util.py +++ b/pathspec/tests/test_util.py @@ -7,6 +7,7 @@ import os import os.path import shutil +import sys import tempfile import unittest @@ -368,6 +369,7 @@ def test_3_entries(self): 'Empty', ]))) + @unittest.skipIf(sys.version_info < (3, 4), "pathlib entered stdlib in Python 3.4") def test_4_normalizing_pathlib_paths(self): """ Tests passing pathlib.Path as argument. @@ -375,4 +377,4 @@ def test_4_normalizing_pathlib_paths(self): from pathlib import Path first_spec = normalize_file([Path('a.txt')]) second_spec = normalize_file(['a.txt']) - self.assertNotEqual(first_spec, second_spec) + self.assertEqual(first_spec, second_spec) From ef9b0a2aa6c557211ff91ee142237a4162ee3e59 Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:46:57 +0100 Subject: [PATCH 5/9] Update docstrings --- pathspec/util.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pathspec/util.py b/pathspec/util.py index 33c4dd3..22352c3 100644 --- a/pathspec/util.py +++ b/pathspec/util.py @@ -262,7 +262,7 @@ def normalize_file(file, separators=None): """ Normalizes the file path to use the POSIX path separator (i.e., ``'/'``). - *file* (:class:`str` or :class: `Path`) is the file path. + *file* (:class:`str`; or :class: `Path`) is the file path. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. @@ -276,7 +276,7 @@ def normalize_file(file, separators=None): # Normalize path separators. if separators is None: separators = NORMALIZE_PATH_SEPS - norm_file = str(file) + norm_file = str(file) # stringify pathlib.Path for sep in separators: norm_file = norm_file.replace(sep, posixpath.sep) @@ -290,8 +290,8 @@ def normalize_files(files, separators=None): """ Normalizes the file paths to use the POSIX path separator. - *files* (:class:`~collections.abc.Iterable` of :class:`str`) contains - the file paths to be normalized. + *files* (:class:`~collections.abc.Iterable` of :class:`str`; + or :class: `Path`) contains the file paths to be normalized. *separators* (:class:`~collections.abc.Collection` of :class:`str`; or :data:`None`) optionally contains the path separators to normalize. From e6dafafcd97684ca1b529c8ab7badc5bad3dc72e Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:51:20 +0100 Subject: [PATCH 6/9] Pass correct args to normalize_file in tests --- pathspec/tests/test_util.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pathspec/tests/test_util.py b/pathspec/tests/test_util.py index 5c23637..84ee031 100644 --- a/pathspec/tests/test_util.py +++ b/pathspec/tests/test_util.py @@ -375,6 +375,6 @@ def test_4_normalizing_pathlib_paths(self): Tests passing pathlib.Path as argument. """ from pathlib import Path - first_spec = normalize_file([Path('a.txt')]) - second_spec = normalize_file(['a.txt']) + first_spec = normalize_file(Path('a.txt')) + second_spec = normalize_file('a.txt') self.assertEqual(first_spec, second_spec) From 8096d1265513568443207c770ad7e6aff8d74926 Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:51:34 +0100 Subject: [PATCH 7/9] Add pykong to contributors --- pathspec/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pathspec/__init__.py b/pathspec/__init__.py index dd0f69e..88324be 100644 --- a/pathspec/__init__.py +++ b/pathspec/__init__.py @@ -47,6 +47,7 @@ "jdufresne ", "groodt ", "ftrofin ", + "pykong " ] __email__ = "cpburnz@gmail.com" __license__ = "MPL 2.0" From 2d14cd7c1fad5dc7fec11bc7ec4191d007aab3cd Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Wed, 26 Feb 2020 11:58:38 +0100 Subject: [PATCH 8/9] Update docstrings --- pathspec/pathspec.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pathspec/pathspec.py b/pathspec/pathspec.py index 1e602a9..09d81b7 100644 --- a/pathspec/pathspec.py +++ b/pathspec/pathspec.py @@ -78,7 +78,7 @@ def match_file(self, file, separators=None): """ Matches the file to this path-spec. - *file* (:class:`str` or :class: `Path`) is the file path to be + *file* (:class:`str`; or :class: `Path`) is the file path to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`) @@ -95,7 +95,7 @@ def match_files(self, files, separators=None): Matches the files to this path-spec. *files* (:class:`~collections.abc.Iterable` of - (:class:`str` or :class: `Path`)) contains the file paths to be + (:class:`str`; or :class: `Path`)) contains the file paths to be matched against :attr:`self.patterns `. *separators* (:class:`~collections.abc.Collection` of :class:`str`; @@ -119,7 +119,7 @@ def match_tree_files(self, root, on_error=None, follow_links=None): Walks the specified root path for all files and matches them to this path-spec. - *root* (:class:`str` or :class: `Path`) is the root directory to + *root* (:class:`str`; or :class: `Path`) is the root directory to search for files. *on_error* (:class:`~collections.abc.Callable` or :data:`None`) From 77521fe5c728d4b5b55b11c221263610fc211c9f Mon Sep 17 00:00:00 2001 From: Ben Felder Date: Thu, 27 Feb 2020 18:14:02 +0100 Subject: [PATCH 9/9] Revert changes in accordance with PR review --- pathspec/pathspec.py | 1 - pathspec/tests/test_util.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pathspec/pathspec.py b/pathspec/pathspec.py index 09d81b7..cb6f767 100644 --- a/pathspec/pathspec.py +++ b/pathspec/pathspec.py @@ -133,7 +133,6 @@ def match_tree_files(self, root, on_error=None, follow_links=None): Returns the matched files (:class:`~collections.abc.Iterable` of :class:`str`). """ - root = str(root) # stringify pathlib.Path files = util.iter_tree_files(root, on_error=on_error, follow_links=follow_links) return self.match_files(files) diff --git a/pathspec/tests/test_util.py b/pathspec/tests/test_util.py index 84ee031..943bde2 100644 --- a/pathspec/tests/test_util.py +++ b/pathspec/tests/test_util.py @@ -370,7 +370,7 @@ def test_3_entries(self): ]))) @unittest.skipIf(sys.version_info < (3, 4), "pathlib entered stdlib in Python 3.4") - def test_4_normalizing_pathlib_paths(self): + def test_4_normalizing_pathlib_path(self): """ Tests passing pathlib.Path as argument. """