Skip to content

Commit

Permalink
Fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
cpburnz committed Aug 14, 2018
1 parent 0298026 commit 3506c3c
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 40 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Change History
==============


0.5.7 (TBD)
-----------

- -Issue #21`_: Fix collections deprecation warning.

.. _`Issue #21`: https://github.com/cpburnz/python-path-specification/issues/21


0.5.6 (2018-04-06)
------------------

Expand Down
5 changes: 3 additions & 2 deletions pathspec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
"adrienverge <https://github.com/adrienverge>",
"AndersBlomdell <https://github.com/AndersBlomdell>",
"highb <https://github.com/highb>",
"thmxv <https://github.com/thmxv>"
]
__email__ = "cpburnz@gmail.com"
__license__ = "MPL 2.0"
__project__ = "pathspec"
__status__ = "Development"
__updated__ = "2018-04-06"
__version__ = "0.5.6"
__updated__ = "2018-08-14"
__version__ = "0.5.7.dev1"

from .pathspec import PathSpec
from .pattern import Pattern, RegexPattern
Expand Down
7 changes: 7 additions & 0 deletions pathspec/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ def iterkeys(mapping):

def iterkeys(mapping):
return mapping.keys()

try:
# Python 3.3+
import collections.abc as collections_abc
except ImportError:
# Python 2.6 - 3.2
import collections as collections_abc
28 changes: 13 additions & 15 deletions pathspec/pathspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
of files.
"""

import collections

from . import util
from .compat import iterkeys, izip_longest, string_types, unicode
from .compat import collections_abc, iterkeys, izip_longest, string_types, unicode


class PathSpec(object):
Expand All @@ -20,13 +18,13 @@ def __init__(self, patterns):
"""
Initializes the :class:`PathSpec` instance.
*patterns* (:class:`~collections.Container` or :class:`~collections.Iterable`)
*patterns* (:class:`~collections_abc.Container` or :class:`~collections_abc.Iterable`)
yields each compiled pattern (:class:`.Pattern`).
"""

self.patterns = patterns if isinstance(patterns, collections.Container) else list(patterns)
self.patterns = patterns if isinstance(patterns, collections_abc.Container) else list(patterns)
"""
*patterns* (:class:`~collections.Container` of :class:`.Pattern`)
*patterns* (:class:`~collections_abc.Container` of :class:`.Pattern`)
contains the compiled patterns.
"""

Expand Down Expand Up @@ -54,11 +52,11 @@ def from_lines(cls, pattern_factory, lines):
Compiles the pattern lines.
*pattern_factory* can be either the name of a registered pattern
factory (:class:`str`), or a :class:`~collections.Callable` used to
compile patterns. It must accept an uncompiled pattern (:class:`str`)
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.Iterable`) yields each uncompiled
*lines* (:class:`~collections_abc.Iterable`) yields each uncompiled
pattern (:class:`str`). This simply has to yield each line so it can
be a :class:`file` (e.g., from :func:`open` or :class:`io.StringIO`)
or the result from :meth:`str.splitlines`.
Expand All @@ -83,7 +81,7 @@ def match_file(self, file, separators=None):
*file* (:class:`str`) is the file path to be matched against
:attr:`self.patterns <PathSpec.patterns>`.
*separators* (:class:`~collections.Container` of :class:`str`)
*separators* (:class:`~collections_abc.Container` of :class:`str`)
optionally contains the path separators to normalize. See
:func:`~pathspec.util.normalize_file` for more information.
Expand All @@ -96,15 +94,15 @@ def match_files(self, files, separators=None):
"""
Matches the files to this path-spec.
*files* (:class:`~collections.Iterable` of :class:`str`) contains
the file paths to be matched against :attr:`self.patterns
*files* (:class:`~collections_abc.Iterable` of :class:`str`)
contains the file paths to be matched against :attr:`self.patterns
<PathSpec.patterns>`.
*separators* (:class:`~collections.Container` of :class:`str`)
*separators* (:class:`~collections_abc.Container` of :class:`str`)
optionally contains the path separators to normalize. See
:func:`~pathspec.util.normalize_file` for more information.
Returns the matched files (:class:`~collections.Iterable` of
Returns the matched files (:class:`~collections_abc.Iterable` of
:class:`str`).
"""
if isinstance(files, (bytes, unicode)):
Expand All @@ -122,7 +120,7 @@ def match_tree(self, root):
*root* (:class:`str`) is the root directory to search for files.
Returns the matched files (:class:`~collections.Iterable` of
Returns the matched files (:class:`~collections_abc.Iterable` of
:class:`str`).
"""
files = util.iter_tree(root)
Expand Down
41 changes: 20 additions & 21 deletions pathspec/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
This module provides utility methods for dealing with path-specs.
"""

import collections
import os
import os.path
import posixpath
import stat

from .compat import string_types
from .compat import collections_abc, string_types

NORMALIZE_PATH_SEPS = [sep for sep in [os.sep, os.altsep] if sep and sep != posixpath.sep]
"""
Expand All @@ -33,8 +32,8 @@ def iter_tree(root):
Raises :exc:`RecursionError` if recursion is detected.
Returns an :class:`~collections.Iterable` yielding the path to each
file (:class:`str`) relative to *root*.
Returns an :class:`~collections_abc.Iterable` yielding the path to
each file (:class:`str`) relative to *root*.
"""
for file_rel in _iter_tree_next(os.path.abspath(root), '', {}):
yield file_rel
Expand Down Expand Up @@ -91,7 +90,7 @@ def lookup_pattern(name):
*name* (:class:`str`) is the name of the pattern factory.
Returns the registered pattern factory (:class:`~collections.Callable`).
Returns the registered pattern factory (:class:`~collections_abc.Callable`).
If no pattern factory is registered, raises :exc:`KeyError`.
"""
return _registered_patterns[name]
Expand All @@ -100,7 +99,7 @@ def match_file(patterns, file):
"""
Matches the file to the patterns.
*patterns* (:class:`~collections.Iterable` of :class:`~pathspec.pattern.Pattern`)
*patterns* (:class:`~collections_abc.Iterable` of :class:`~pathspec.pattern.Pattern`)
contains the patterns to use.
*file* (:class:`str`) is the normalized file path to be matched
Expand All @@ -119,15 +118,15 @@ def match_files(patterns, files):
"""
Matches the files to the patterns.
*patterns* (:class:`~collections.Iterable` of :class:`~pathspec.pattern.Pattern`)
*patterns* (:class:`~collections_abc.Iterable` of :class:`~pathspec.pattern.Pattern`)
contains the patterns to use.
*files* (:class:`~collections.Iterable` of :class:`str`) contains the
normalized file paths to be matched against *patterns*.
*files* (:class:`~collections_abc.Iterable` of :class:`str`) contains
the normalized file paths to be matched against *patterns*.
Returns the matched files (:class:`set` of :class:`str`).
"""
all_files = files if isinstance(files, collections.Container) else list(files)
all_files = files if isinstance(files, collections_abc.Container) else list(files)
return_files = set()
for pattern in patterns:
if pattern.include is not None:
Expand All @@ -144,7 +143,7 @@ def normalize_file(file, separators=None):
*file* (:class:`str`) is the file path.
*separators* (:class:`~collections.Container` of :class:`str`)
*separators* (:class:`~collections_abc.Container` of :class:`str`)
optionally contains the path separators to normalize. This does not
need to include the POSIX path separator (``'/'``), but including it
will not affect the results. Default is :data:`None` for :data:`NORMALIZE_PATH_SEPS`.
Expand All @@ -170,10 +169,10 @@ def normalize_files(files, separators=None):
"""
Normalizes the file paths to use the POSIX path separator.
*files* (:class:`~collections.Iterable` of :class:`str`) contains the
file paths to be normalized.
*files* (:class:`~collections_abc.Iterable` of :class:`str`) contains
the file paths to be normalized.
*separators* (:class:`~collections.Container` of :class:`str`)
*separators* (:class:`~collections_abc.Container` of :class:`str`)
optionally contains the path separators to normalize. See :func:`normalize_file`
for more information.
Expand All @@ -192,9 +191,9 @@ def register_pattern(name, pattern_factory, override=None):
*name* (:class:`str`) is the name to register the pattern factory
under.
*pattern_factory* (:class:`~collections.Callable`) is used to compile
patterns. It must accept an uncompiled pattern (:class:`str`) and
return the compiled pattern (:class:`.Pattern`).
*pattern_factory* (:class:`~collections_abc.Callable`) is used to
compile patterns. It must accept an uncompiled pattern (:class:`str`)
and return the compiled pattern (:class:`.Pattern`).
*override* (:class:`bool`) optionally is whether to allow overriding
an already registered pattern under the same name (:data:`True`),
Expand Down Expand Up @@ -222,8 +221,8 @@ def __init__(self, name, pattern_factory):
*name* (:class:`str`) is the name of the registered pattern.
*pattern_factory* (:class:`~collections.Callable`) is the registered
pattern factory.
*pattern_factory* (:class:`~collections_abc.Callable`) is the
registered pattern factory.
"""
super(AlreadyRegisteredError, self).__init__(name, pattern_factory)

Expand All @@ -247,8 +246,8 @@ def name(self):
@property
def pattern_factory(self):
"""
*pattern_factory* (:class:`~collections.Callable`) is the registered
pattern factory.
*pattern_factory* (:class:`~collections_abc.Callable`) is the
registered pattern factory.
"""
return self.args[1]

Expand Down
2 changes: 1 addition & 1 deletion pypi-upload.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
python setup.py sdist register upload
python setup.py sdist upload
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py33, py34, py35, py36, pypy, pypy3
envlist = py26, py27, py33, py34, py35, py36, py37, pypy, pypy3

[testenv]
commands = python setup.py test
Expand Down

0 comments on commit 3506c3c

Please sign in to comment.