-
-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implementation of glob * typing, count and remove * count lines * Add tests * tests * Refactor iter * docs * docs and refactor * polish * doc fix * doc * doc fix * fix and docs * version bump
- Loading branch information
1 parent
2f305b8
commit 9e4d4b9
Showing
17 changed files
with
525 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
.. _globbing: | ||
|
||
Globbing | ||
======== | ||
|
||
Globbing is the process of matching paths according to the rules used | ||
by the Unix shell. | ||
|
||
Generally speaking, you can think of a glob pattern as a path containing | ||
one or more wildcard patterns, separated by forward slashes. | ||
|
||
|
||
Matching Files and Directories | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
In a glob pattern, A ``*`` means match anything text in a filename. A ``?`` | ||
matches any single character. A ``**`` matches any number of subdirectories, | ||
making the glob *recusrive*. If the glob pattern ends in a ``/``, it will | ||
only match directory paths, otherwise it will match files and directories. | ||
|
||
.. note:: | ||
A recursive glob requires that PyFilesystem scan a lot of files, | ||
and can potentially be slow for large (or network based) filesystems. | ||
|
||
Here's a summary of glob patterns: | ||
|
||
``*`` | ||
Matches all files in the current directory. | ||
``*.py`` | ||
Matches all .py file in the current directory. | ||
``*.py?`` | ||
Matches all .py files and .pyi, .pyc etc in the currenct directory. | ||
``project/*.py`` | ||
Matches all .py files in a directory called ``project``. | ||
``*/*.py`` | ||
Matches all .py files in any sub directory. | ||
``**/*.py`` | ||
Recursively matches all .py files. | ||
``**/.git/`` | ||
Recursively matches all the git directories. | ||
|
||
|
||
Interface | ||
~~~~~~~~~ | ||
|
||
PyFilesystem supports globbing via the ``glob`` attribute on every FS | ||
instance, which is an instance of :class:`~fs.glob.BoundGlobber`. Here's | ||
how you might use it to find all the Python files in your filesystem:: | ||
|
||
for match in my_fs.glob("**/*.py"): | ||
print(f"{match.path} is {match.info.size} bytes long") | ||
|
||
Calling ``.glob`` with a pattern will return an iterator of | ||
:class:`~fs.glob.GlobMatch` named tuples for each matching file or | ||
directory. A glob match contains two attributes; ``path`` which is the | ||
full path in the filesystem, and ``info`` which is an | ||
:class:`fs.info.Info` info object for the matched resource. | ||
|
||
|
||
Batch Methods | ||
~~~~~~~~~~~~~ | ||
|
||
In addition to iterating over the results, you can also call methods on | ||
the :class:`~fs.glob.Globber` which apply to every matched path. | ||
|
||
For instance, here is how you can use glob to remove all ``.pyc`` files | ||
from a project directory:: | ||
|
||
>>> import fs | ||
>>> fs.open_fs('~/projects/my_project').glob('**/*.pyc').remove() | ||
29 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ Contents: | |
info.rst | ||
openers.rst | ||
walking.rst | ||
globbing.rst | ||
builtin.rst | ||
implementers.rst | ||
extension.rst | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fs.glob | ||
======= | ||
|
||
.. automodule:: fs.glob | ||
:members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""Version, used in module and setup.py. | ||
""" | ||
__version__ = "2.0.27" | ||
__version__ = "2.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.