| 1 |
Metadata-Version: 2.1 |
| 2 |
Name: pathspec |
| 3 |
Version: 0.9.0 |
| 4 |
Summary: Utility library for gitignore style pattern matching of file paths. |
| 5 |
Home-page: https://github.com/cpburnz/python-path-specification |
| 6 |
Author: Caleb P. Burns |
| 7 |
Author-email: [email protected] |
| 8 |
License: MPL 2.0 |
| 9 |
Platform: UNKNOWN |
| 10 |
Classifier: Development Status :: 4 - Beta |
| 11 |
Classifier: Intended Audience :: Developers |
| 12 |
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0) |
| 13 |
Classifier: Operating System :: OS Independent |
| 14 |
Classifier: Programming Language :: Python |
| 15 |
Classifier: Programming Language :: Python :: 2 |
| 16 |
Classifier: Programming Language :: Python :: 2.7 |
| 17 |
Classifier: Programming Language :: Python :: 3 |
| 18 |
Classifier: Programming Language :: Python :: 3.5 |
| 19 |
Classifier: Programming Language :: Python :: 3.6 |
| 20 |
Classifier: Programming Language :: Python :: 3.7 |
| 21 |
Classifier: Programming Language :: Python :: 3.8 |
| 22 |
Classifier: Programming Language :: Python :: 3.9 |
| 23 |
Classifier: Programming Language :: Python :: Implementation :: CPython |
| 24 |
Classifier: Programming Language :: Python :: Implementation :: PyPy |
| 25 |
Classifier: Topic :: Software Development :: Libraries :: Python Modules |
| 26 |
Classifier: Topic :: Utilities |
| 27 |
Requires-Python: !=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7 |
| 28 |
Description-Content-Type: text/x-rst |
| 29 |
|
| 30 |
|
| 31 |
*pathspec*: Path Specification |
| 32 |
============================== |
| 33 |
|
| 34 |
*pathspec* is a utility library for pattern matching of file paths. So |
| 35 |
far this only includes Git's wildmatch pattern matching which itself is |
| 36 |
derived from Rsync's wildmatch. Git uses wildmatch for its `gitignore`_ |
| 37 |
files. |
| 38 |
|
| 39 |
.. _`gitignore`: http://git-scm.com/docs/gitignore |
| 40 |
|
| 41 |
|
| 42 |
Tutorial |
| 43 |
-------- |
| 44 |
|
| 45 |
Say you have a "Projects" directory and you want to back it up, but only |
| 46 |
certain files, and ignore others depending on certain conditions:: |
| 47 |
|
| 48 |
>>> import pathspec |
| 49 |
>>> # The gitignore-style patterns for files to select, but we're including |
| 50 |
>>> # instead of ignoring. |
| 51 |
>>> spec = """ |
| 52 |
... |
| 53 |
... # This is a comment because the line begins with a hash: "#" |
| 54 |
... |
| 55 |
... # Include several project directories (and all descendants) relative to |
| 56 |
... # the current directory. To reference a directory you must end with a |
| 57 |
... # slash: "/" |
| 58 |
... /project-a/ |
| 59 |
... /project-b/ |
| 60 |
... /project-c/ |
| 61 |
... |
| 62 |
... # Patterns can be negated by prefixing with exclamation mark: "!" |
| 63 |
... |
| 64 |
... # Ignore temporary files beginning or ending with "~" and ending with |
| 65 |
... # ".swp". |
| 66 |
... !~* |
| 67 |
... !*~ |
| 68 |
... !*.swp |
| 69 |
... |
| 70 |
... # These are python projects so ignore compiled python files from |
| 71 |
... # testing. |
| 72 |
... !*.pyc |
| 73 |
... |
| 74 |
... # Ignore the build directories but only directly under the project |
| 75 |
... # directories. |
| 76 |
... !/*/build/ |
| 77 |
... |
| 78 |
... """ |
| 79 |
|
| 80 |
We want to use the ``GitWildMatchPattern`` class to compile our patterns. The |
| 81 |
``PathSpec`` class provides an interface around pattern implementations:: |
| 82 |
|
| 83 |
>>> spec = pathspec.PathSpec.from_lines(pathspec.patterns.GitWildMatchPattern, spec.splitlines()) |
| 84 |
|
| 85 |
That may be a mouthful but it allows for additional patterns to be implemented |
| 86 |
in the future without them having to deal with anything but matching the paths |
| 87 |
sent to them. ``GitWildMatchPattern`` is the implementation of the actual |
| 88 |
pattern which internally gets converted into a regular expression. |
| 89 |
``PathSpec`` is a simple wrapper around a list of compiled patterns. |
| 90 |
|
| 91 |
To make things simpler, we can use the registered name for a pattern class |
| 92 |
instead of always having to provide a reference to the class itself. The |
| 93 |
``GitWildMatchPattern`` class is registered as **gitwildmatch**:: |
| 94 |
|
| 95 |
>>> spec = pathspec.PathSpec.from_lines('gitwildmatch', spec.splitlines()) |
| 96 |
|
| 97 |
If we wanted to manually compile the patterns we can just do the following:: |
| 98 |
|
| 99 |
>>> patterns = map(pathspec.patterns.GitWildMatchPattern, spec.splitlines()) |
| 100 |
>>> spec = PathSpec(patterns) |
| 101 |
|
| 102 |
``PathSpec.from_lines()`` is simply a class method which does just that. |
| 103 |
|
| 104 |
If you want to load the patterns from file, you can pass the file instance |
| 105 |
directly as well:: |
| 106 |
|
| 107 |
>>> with open('patterns.list', 'r') as fh: |
| 108 |
>>> spec = pathspec.PathSpec.from_lines('gitwildmatch', fh) |
| 109 |
|
| 110 |
You can perform matching on a whole directory tree with:: |
| 111 |
|
| 112 |
>>> matches = spec.match_tree('path/to/directory') |
| 113 |
|
| 114 |
Or you can perform matching on a specific set of file paths with:: |
| 115 |
|
| 116 |
>>> matches = spec.match_files(file_paths) |
| 117 |
|
| 118 |
Or check to see if an individual file matches:: |
| 119 |
|
| 120 |
>>> is_matched = spec.match_file(file_path) |
| 121 |
|
| 122 |
|
| 123 |
License |
| 124 |
------- |
| 125 |
|
| 126 |
*pathspec* is licensed under the `Mozilla Public License Version 2.0`_. See |
| 127 |
`LICENSE`_ or the `FAQ`_ for more information. |
| 128 |
|
| 129 |
In summary, you may use *pathspec* with any closed or open source project |
| 130 |
without affecting the license of the larger work so long as you: |
| 131 |
|
| 132 |
- give credit where credit is due, |
| 133 |
|
| 134 |
- and release any custom changes made to *pathspec*. |
| 135 |
|
| 136 |
.. _`Mozilla Public License Version 2.0`: http://www.mozilla.org/MPL/2.0 |
| 137 |
.. _`LICENSE`: LICENSE |
| 138 |
.. _`FAQ`: http://www.mozilla.org/MPL/2.0/FAQ.html |
| 139 |
|
| 140 |
|
| 141 |
Source |
| 142 |
------ |
| 143 |
|
| 144 |
The source code for *pathspec* is available from the GitHub repo |
| 145 |
`cpburnz/python-path-specification`_. |
| 146 |
|
| 147 |
.. _`cpburnz/python-path-specification`: https://github.com/cpburnz/python-path-specification |
| 148 |
|
| 149 |
|
| 150 |
Installation |
| 151 |
------------ |
| 152 |
|
| 153 |
*pathspec* requires the following packages: |
| 154 |
|
| 155 |
- `setuptools`_ |
| 156 |
|
| 157 |
*pathspec* can be installed from source with:: |
| 158 |
|
| 159 |
python setup.py install |
| 160 |
|
| 161 |
*pathspec* is also available for install through `PyPI`_:: |
| 162 |
|
| 163 |
pip install pathspec |
| 164 |
|
| 165 |
.. _`setuptools`: https://pypi.python.org/pypi/setuptools |
| 166 |
.. _`PyPI`: http://pypi.python.org/pypi/pathspec |
| 167 |
|
| 168 |
|
| 169 |
Documentation |
| 170 |
------------- |
| 171 |
|
| 172 |
Documentation for *pathspec* is available on `Read the Docs`_. |
| 173 |
|
| 174 |
.. _`Read the Docs`: http://python-path-specification.readthedocs.io |
| 175 |
|
| 176 |
|
| 177 |
Other Languages |
| 178 |
--------------- |
| 179 |
|
| 180 |
*pathspec* is also available as a `Ruby gem`_. |
| 181 |
|
| 182 |
.. _`Ruby gem`: https://github.com/highb/pathspec-ruby |
| 183 |
|
| 184 |
|
| 185 |
Change History |
| 186 |
============== |
| 187 |
|
| 188 |
0.9.0 (2021-07-17) |
| 189 |
------------------ |
| 190 |
|
| 191 |
- `Issue #44`_/`Issue #50`_: Raise `GitWildMatchPatternError` for invalid git patterns. |
| 192 |
- `Issue #45`_: Fix for duplicate leading double-asterisk, and edge cases. |
| 193 |
- `Issue #46`_: Fix matching absolute paths. |
| 194 |
- API change: `util.normalize_files()` now returns a `Dict[str, List[pathlike]]` instead of a `Dict[str, pathlike]`. |
| 195 |
- Added type hinting. |
| 196 |
|
| 197 |
.. _`Issue #44`: https://github.com/cpburnz/python-path-specification/issues/44 |
| 198 |
.. _`Issue #45`: https://github.com/cpburnz/python-path-specification/pull/45 |
| 199 |
.. _`Issue #46`: https://github.com/cpburnz/python-path-specification/issues/46 |
| 200 |
.. _`Issue #50`: https://github.com/cpburnz/python-path-specification/pull/50 |
| 201 |
|
| 202 |
|
| 203 |
0.8.1 (2020-11-07) |
| 204 |
------------------ |
| 205 |
|
| 206 |
- `Issue #43`_: Add support for addition operator. |
| 207 |
|
| 208 |
.. _`Issue #43`: https://github.com/cpburnz/python-path-specification/pull/43 |
| 209 |
|
| 210 |
|
| 211 |
0.8.0 (2020-04-09) |
| 212 |
------------------ |
| 213 |
|
| 214 |
- `Issue #30`_: Expose what patterns matched paths. Added `util.detailed_match_files()`. |
| 215 |
- `Issue #31`_: `match_tree()` doesn't return symlinks. |
| 216 |
- `Issue #34`_: Support `pathlib.Path`\ s. |
| 217 |
- Add `PathSpec.match_tree_entries` and `util.iter_tree_entries()` to support directories and symlinks. |
| 218 |
- API change: `match_tree()` has been renamed to `match_tree_files()`. The old name `match_tree()` is still available as an alias. |
| 219 |
- API change: `match_tree_files()` now returns symlinks. This is a bug fix but it will change the returned results. |
| 220 |
|
| 221 |
.. _`Issue #30`: https://github.com/cpburnz/python-path-specification/issues/30 |
| 222 |
.. _`Issue #31`: https://github.com/cpburnz/python-path-specification/issues/31 |
| 223 |
.. _`Issue #34`: https://github.com/cpburnz/python-path-specification/issues/34 |
| 224 |
|
| 225 |
|
| 226 |
0.7.0 (2019-12-27) |
| 227 |
------------------ |
| 228 |
|
| 229 |
- `Issue #28`_: Add support for Python 3.8, and drop Python 3.4. |
| 230 |
- `Issue #29`_: Publish bdist wheel. |
| 231 |
|
| 232 |
.. _`Issue #28`: https://github.com/cpburnz/python-path-specification/pull/28 |
| 233 |
.. _`Issue #29`: https://github.com/cpburnz/python-path-specification/pull/29 |
| 234 |
|
| 235 |
|
| 236 |
0.6.0 (2019-10-03) |
| 237 |
------------------ |
| 238 |
|
| 239 |
- `Issue #24`_: Drop support for Python 2.6, 3.2, and 3.3. |
| 240 |
- `Issue #25`_: Update README.rst. |
| 241 |
- `Issue #26`_: Method to escape gitwildmatch. |
| 242 |
|
| 243 |
.. _`Issue #24`: https://github.com/cpburnz/python-path-specification/pull/24 |
| 244 |
.. _`Issue #25`: https://github.com/cpburnz/python-path-specification/pull/25 |
| 245 |
.. _`Issue #26`: https://github.com/cpburnz/python-path-specification/pull/26 |
| 246 |
|
| 247 |
|
| 248 |
0.5.9 (2018-09-15) |
| 249 |
------------------ |
| 250 |
|
| 251 |
- Fixed file system error handling. |
| 252 |
|
| 253 |
|
| 254 |
0.5.8 (2018-09-15) |
| 255 |
------------------ |
| 256 |
|
| 257 |
- Improved type checking. |
| 258 |
- Created scripts to test Python 2.6 because Tox removed support for it. |
| 259 |
- Improved byte string handling in Python 3. |
| 260 |
- `Issue #22`_: Handle dangling symlinks. |
| 261 |
|
| 262 |
.. _`Issue #22`: https://github.com/cpburnz/python-path-specification/issues/22 |
| 263 |
|
| 264 |
|
| 265 |
0.5.7 (2018-08-14) |
| 266 |
------------------ |
| 267 |
|
| 268 |
- `Issue #21`_: Fix collections deprecation warning. |
| 269 |
|
| 270 |
.. _`Issue #21`: https://github.com/cpburnz/python-path-specification/issues/21 |
| 271 |
|
| 272 |
|
| 273 |
0.5.6 (2018-04-06) |
| 274 |
------------------ |
| 275 |
|
| 276 |
- Improved unit tests. |
| 277 |
- Improved type checking. |
| 278 |
- `Issue #20`_: Support current directory prefix. |
| 279 |
|
| 280 |
.. _`Issue #20`: https://github.com/cpburnz/python-path-specification/issues/20 |
| 281 |
|
| 282 |
|
| 283 |
0.5.5 (2017-09-09) |
| 284 |
------------------ |
| 285 |
|
| 286 |
- Add documentation link to README. |
| 287 |
|
| 288 |
|
| 289 |
0.5.4 (2017-09-09) |
| 290 |
------------------ |
| 291 |
|
| 292 |
- `Issue #17`_: Add link to Ruby implementation of *pathspec*. |
| 293 |
- Add sphinx documentation. |
| 294 |
|
| 295 |
.. _`Issue #17`: https://github.com/cpburnz/python-path-specification/pull/17 |
| 296 |
|
| 297 |
|
| 298 |
0.5.3 (2017-07-01) |
| 299 |
------------------ |
| 300 |
|
| 301 |
- `Issue #14`_: Fix byte strings for Python 3. |
| 302 |
- `Issue #15`_: Include "LICENSE" in source package. |
| 303 |
- `Issue #16`_: Support Python 2.6. |
| 304 |
|
| 305 |
.. _`Issue #14`: https://github.com/cpburnz/python-path-specification/issues/14 |
| 306 |
.. _`Issue #15`: https://github.com/cpburnz/python-path-specification/pull/15 |
| 307 |
.. _`Issue #16`: https://github.com/cpburnz/python-path-specification/issues/16 |
| 308 |
|
| 309 |
|
| 310 |
0.5.2 (2017-04-04) |
| 311 |
------------------ |
| 312 |
|
| 313 |
- Fixed change log. |
| 314 |
|
| 315 |
|
| 316 |
0.5.1 (2017-04-04) |
| 317 |
------------------ |
| 318 |
|
| 319 |
- `Issue #13`_: Add equality methods to `PathSpec` and `RegexPattern`. |
| 320 |
|
| 321 |
.. _`Issue #13`: https://github.com/cpburnz/python-path-specification/pull/13 |
| 322 |
|
| 323 |
|
| 324 |
0.5.0 (2016-08-22) |
| 325 |
------------------ |
| 326 |
|
| 327 |
- `Issue #12`_: Add `PathSpec.match_file()`. |
| 328 |
- Renamed `gitignore.GitIgnorePattern` to `patterns.gitwildmatch.GitWildMatchPattern`. |
| 329 |
- Deprecated `gitignore.GitIgnorePattern`. |
| 330 |
|
| 331 |
.. _`Issue #12`: https://github.com/cpburnz/python-path-specification/issues/12 |
| 332 |
|
| 333 |
|
| 334 |
0.4.0 (2016-07-15) |
| 335 |
------------------ |
| 336 |
|
| 337 |
- `Issue #11`_: Support converting patterns into regular expressions without compiling them. |
| 338 |
- API change: Subclasses of `RegexPattern` should implement `pattern_to_regex()`. |
| 339 |
|
| 340 |
.. _`Issue #11`: https://github.com/cpburnz/python-path-specification/issues/11 |
| 341 |
|
| 342 |
|
| 343 |
0.3.4 (2015-08-24) |
| 344 |
------------------ |
| 345 |
|
| 346 |
- `Issue #7`_: Fixed non-recursive links. |
| 347 |
- `Issue #8`_: Fixed edge cases in gitignore patterns. |
| 348 |
- `Issue #9`_: Fixed minor usage documentation. |
| 349 |
- Fixed recursion detection. |
| 350 |
- Fixed trivial incompatibility with Python 3.2. |
| 351 |
|
| 352 |
.. _`Issue #7`: https://github.com/cpburnz/python-path-specification/pull/7 |
| 353 |
.. _`Issue #8`: https://github.com/cpburnz/python-path-specification/pull/8 |
| 354 |
.. _`Issue #9`: https://github.com/cpburnz/python-path-specification/pull/9 |
| 355 |
|
| 356 |
|
| 357 |
0.3.3 (2014-11-21) |
| 358 |
------------------ |
| 359 |
|
| 360 |
- Improved documentation. |
| 361 |
|
| 362 |
|
| 363 |
0.3.2 (2014-11-08) |
| 364 |
------------------ |
| 365 |
|
| 366 |
- `Issue #5`_: Use tox for testing. |
| 367 |
- `Issue #6`_: Fixed matching Windows paths. |
| 368 |
- Improved documentation. |
| 369 |
- API change: `spec.match_tree()` and `spec.match_files()` now return iterators instead of sets. |
| 370 |
|
| 371 |
.. _`Issue #5`: https://github.com/cpburnz/python-path-specification/pull/5 |
| 372 |
.. _`Issue #6`: https://github.com/cpburnz/python-path-specification/issues/6 |
| 373 |
|
| 374 |
|
| 375 |
0.3.1 (2014-09-17) |
| 376 |
------------------ |
| 377 |
|
| 378 |
- Updated README. |
| 379 |
|
| 380 |
|
| 381 |
0.3.0 (2014-09-17) |
| 382 |
------------------ |
| 383 |
|
| 384 |
- `Issue #3`_: Fixed trailing slash in gitignore patterns. |
| 385 |
- `Issue #4`_: Fixed test for trailing slash in gitignore patterns. |
| 386 |
- Added registered patterns. |
| 387 |
|
| 388 |
.. _`Issue #3`: https://github.com/cpburnz/python-path-specification/pull/3 |
| 389 |
.. _`Issue #4`: https://github.com/cpburnz/python-path-specification/pull/4 |
| 390 |
|
| 391 |
|
| 392 |
0.2.2 (2013-12-17) |
| 393 |
------------------ |
| 394 |
|
| 395 |
- Fixed setup.py. |
| 396 |
|
| 397 |
|
| 398 |
0.2.1 (2013-12-17) |
| 399 |
------------------ |
| 400 |
|
| 401 |
- Added tests. |
| 402 |
- Fixed comment gitignore patterns. |
| 403 |
- Fixed relative path gitignore patterns. |
| 404 |
|
| 405 |
|
| 406 |
0.2.0 (2013-12-07) |
| 407 |
------------------ |
| 408 |
|
| 409 |
- Initial release. |
| 410 |
|
| 411 |
|