Skip to content

Commit

Permalink
Merge pull request #55 from facelessuser/prep-4.0.0
Browse files Browse the repository at this point in the history
Prep 4.0.0
  • Loading branch information
facelessuser authored May 4, 2019
2 parents 3782995 + a959e54 commit 15a785c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
5 changes: 2 additions & 3 deletions docs/src/markdown/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

- **NEW**: Deprecated `WcMatch` class methods `kill` and `reset`. `WcMatch` should be broken with a simple `break` statement instead.
- **NEW**: Add a new flag `MARK` to force `glob` to return directories with a trailing slash.
- **NEW**: Add `MATCHBASE` that causes `glob` and `WcMatch`, when the pattern has no slashes in it, to seek for any file anywhere in the tree with a matching basename.
- **NEW**: Add `MATCHBASE` that causes glob glob related functions and `WcMatch`, when the pattern has no slashes in it, to seek for any file anywhere in the tree with a matching basename.
- **NEW**: Add `NODIR` that causes `glob` matchers and crawlers to only match and return files.
- **NEW**: Exclusion patterns (enabled with `NEGATE`) now always enable `DOTALL` in the exclusion patterns. They also will match symlinks in `**` patterns. Only non `NEGATE` patterns that are paired with a `NEGATE` pattern are subject to symlinks and dot rules. Exclusion patterns themselves allow dots and symlinks to make filtering easier.
- **NEW**: Exclusion patterns no longer provide a default regular pattern if one is not applied. Exclusion patterns are
meant to filter the results of normal patterns. You can either use the `SPLIT` flag and provide a pattern with your default ('default_pattern|!exclusion'), or feed in a list of multiple patterns instead of a single string (`['default_pattern', '!exclusion']`). If you really need the old behavior, you can use the `NEGATEALL` flag which will provide a default inclusion pattern that matches all files.
- **NEW**: Exclusion patterns no longer provide a default inclusion pattern if one is not specified. Exclusion patterns are meant to filter the results of inclusion patterns. You can either use the `SPLIT` flag and provide an inclusion pattern with your default ('default_pattern|!exclusion'), or feed in a list of multiple patterns instead of a single string (`['inclusion', '!exclusion']`). If you really need the old behavior, you can use the `NEGATEALL` flag which will provide a default inclusion pattern that matches all files.
- **NEW**: Translate now outputs exclusion patterns so that if they match, the file is excluded. This is opposite logic to how it used to be, but is more efficient.
- **FIX**: An empty pattern in `glob` should not match slashes.

Expand Down
22 changes: 9 additions & 13 deletions docs/src/markdown/fnmatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,27 @@ When applying multiple patterns, a file matches if it matches any of the pattern
True
```

Exclusion patterns are allowed as well.
Exclusion patterns are allowed as well. When exclusion patterns are used in conjunction with inclusion patterns, a file will be considered matched if one of the inclusion patterns match **and** none of the exclusion patterns match. If an exclusion pattern is given without any inclusion patterns, the pattern will match nothing. Exclusion patterns are meant to filter other patterns, not match anything by themselves.

```pycon3
>>> from wcmatch import fnmatch
>>> fnmatch.fnmatch('test.py', r'*|!*.py', flags=fnmatch.NEGATE | fnamtch.SPLIT)
False
>>> fnmatch.fnmatch('test.txt', r'*|!*.py', flags=fnmatch.NEGATE | fnamtch.SPLIT)
True
```

When exclusion patterns are used in conjunction with other patterns, a file will be considered matched if one of the regular patterns match **and** none of the exclusion patterns match. If an exclusion pattern is given without any regular patterns, the pattern will match nothing. Exclusion patterns are meant to filter other patterns, not match anything by themselves.

```pycon3
>>> from wcmatch import fnmatch
>>> fnmatch.fnmatch('test.txt', [r'*.txt', r'!avoid.txt'], flags=fnmatch.NEGATE)
True
>>> fnmatch.fnmatch('avoid.txt', [r'*.txt', r'!avoid.txt'], flags=fnmatch.NEGATE)
False
```

As mentioned, exclusion patterns need to be applied to a non-exclusion pattern to work, but if it is desired, you can force exclusion patterns to assume all files match unless excluded with the [`NEGATEALL`](#fnmatchnegateall) flag. Essentially, it means if you use a pattern such as `!*.md`, it will assume two pattern were given: `*` and `!*.md`.
As mentioned, exclusion patterns need to be applied to a inclusion pattern to work, but if it is desired, you can force exclusion patterns to assume all files should be filtered with the exclusion pattern(s) with the [`NEGATEALL`](#fnmatchnegateall) flag. Essentially, it means if you use a pattern such as `!*.md`, it will assume two pattern were given: `*` and `!*.md`.

```pycon3
>>> from wcmatch import fnmatch
>>> fnmatch.fnmatch('test.py', r'!*.py', flags=fnmatch.NEGATE | fnamtch.SPLIT)
>>> fnmatch.fnmatch('test.py', r'!*.py', flags=fnmatch.NEGATE | fnamtch.NEGATEALL)
False
>>> fnmatch.fnmatch('test.txt', r'!*.py', flags=fnmatch.NEGATE | fnamtch.SPLIT)
>>> fnmatch.fnmatch('test.txt', r'!*.py', flags=fnmatch.NEGATE | fnamtch.NEGATEALL)
True
```

Expand Down Expand Up @@ -125,7 +119,7 @@ def fnsplit(pattern, *, flags=0):
def translate(patterns, *, flags=0):
```

`translate` takes a file pattern (or list of patterns) and returns two lists: one for normal patterns and one for exclusion patterns. The lists contain the regular expressions used for matching the given patterns. It should be noted that a file is considered matched if it matches at least one regular pattern and matches **none** of the exclusion patterns.
`translate` takes a file pattern (or list of patterns) and returns two lists: one for inclusion patterns and one for exclusion patterns. The lists contain the regular expressions used for matching the given patterns. It should be noted that a file is considered matched if it matches at least one inclusion pattern and matches **none** of the exclusion patterns.

```pycon3
>>> from wcmatch import translate
Expand Down Expand Up @@ -164,9 +158,11 @@ If used with the extended glob feature, patterns like `!(inverse|pattern)` will
In 4.0, `NEGATE` now requires a non-exclusion pattern to be paired with it or it will match nothing. If you really
need something similar to the old behavior, that would assume a default inclusion pattern, you can use the [`NEGATEALL`](#fnmatchnegateall).

#### `glob.NEGATEALL, glob.A`
#### `fnmatch.NEGATEALL, glob.A` {: #fnmatchnegateall}

`NEGATEALL` can force exclusion patterns, when no inclusion pattern is provided, to assume all files match unless the file matches the excluded pattern. Essentially, it means if you use a pattern such as `!*.md`, it will assume two patterns were given: `*` and `!*.md`, where `!*.md` is applied to the results of `*`.

`NEGATEALL` can force exclusion patterns, when no inclusion pattern is provided, to assume all files match unless the file matches the excluded pattern. Essentially, it means if you use a pattern such as `!*.md`, it will assume a pattern of `*|!*.md` (assuming the use of the [`SPLIT`](#fnmatchsplit) flag).
Dot files will not be returned unless [`DOTMATCH`](#fnmatchdotmatch).

#### `fnmatch.MINUSNEGATE, fnmatch.M` {: #fnmatchminusnegate}

Expand Down
22 changes: 9 additions & 13 deletions docs/src/markdown/glob.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,33 +130,27 @@ When applying multiple patterns, a file path matches if it matches any of the pa
True
```

Exclusion patterns are allowed as well.
Exclusion patterns are allowed as well. When exclusion patterns are used in conjunction with other patterns, a path will be considered matched if one of the positive patterns match **and** none of the exclusion patterns match. If an exclusion pattern is given without any inclusion patterns, the pattern will match nothing. Exclusion patterns are meant to filter other patterns, not match anything by themselves.

```pycon3
>>> from wcmatch import glob
>>> glob.globmatch('some/path/test.py', r'**|!**/*.txt', flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT)
True
>>> glob.globmatch('some/path/test.txt', r'**|!**/*.txt', flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT)
False
```

When exclusion patterns are used in conjunction with other patterns, a path will be considered matched if one of the positive patterns match **and** none of the exclusion patterns match. If an exclusion pattern is given without any regular patterns, the pattern will match nothing. Exclusion patterns are meant to filter other patterns, not match anything by themselves.

```pycon3
>>> from wcmatch import glob
>>> glob.globmatch('some/path/test.txt', [r'*/*/*.txt', r'!*/*/avoid.txt'], flags=glob.NEGATE)
True
>>> glob.globmatch('some/path/avoid.txt', [r'*/*/*.txt', r'!*/*/avoid.txt'], flags=glob.NEGATE)
False
```

As mentioned, exclusion patterns need to be applied to a non-exclusion pattern to work, but if it is desired, you can force exclusion patterns to assume all files match unless excluded with the [`NEGATEALL`](#globnegateall) flag. Essentially, it means if you use a pattern such as `!*.md`, it means if you use a pattern such as `!*.md`, it will assume two pattern were given: `*` and `!*.md` (where `**` is specifically treated as if `GLOBSTAR` was enabled).
As mentioned, exclusion patterns need to be applied to a inclusion pattern to work, but if it is desired, you can force exclusion patterns to assume all files should be filtered with the exclusion pattern(s) with the [`NEGATEALL`](#globnegateall) flag. Essentially, it means if you use a pattern such as `!*.md`, it means if you use a pattern such as `!*.md`, it will assume two pattern were given: `*` and `!*.md` (where `**` is specifically treated as if `GLOBSTAR` was enabled).

```pycon3
>>> from wcmatch import glob
>>> glob.globmatch('some/path/test.py', r'!**/*.txt', flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT)
>>> glob.globmatch('some/path/test.py', r'!**/*.txt', flags=glob.NEGATE | glob.GLOBSTAR | glob.NEGATEALL)
True
>>> glob.globmatch('some/path/test.txt', r'!**/*.txt', flags=glob.NEGATE | glob.GLOBSTAR | glob.SPLIT)
>>> glob.globmatch('some/path/test.txt', r'!**/*.txt', flags=glob.NEGATE | glob.GLOBSTAR | glob.NEGATEALL)
False
```

Expand Down Expand Up @@ -227,7 +221,7 @@ def globsplit(pattern, *, flags=0):
def translate(patterns, *, flags=0):
```

`translate` takes a file pattern (or list of patterns) and returns two lists: one for normal patterns and one for exclusion patterns. The lists contain the regular expressions used for matching the given patterns. It should be noted that a file is considered matched if it matches at least one regular pattern and matches **none** of the exclusion patterns.
`translate` takes a file pattern (or list of patterns) and returns two lists: one for inclusion patterns and one for exclusion patterns. The lists contain the regular expressions used for matching the given patterns. It should be noted that a file is considered matched if it matches at least one inclusion pattern and matches **none** of the exclusion patterns.

```pycon3
>>> from wcmatch import glob
Expand Down Expand Up @@ -306,9 +300,11 @@ If used with the extended glob feature, patterns like `!(inverse|pattern)` will
In 4.0, `NEGATE` now requires a non-exclusion pattern to be paired with it or it will match nothing. If you really
need something similar to the old behavior, that would assume a default inclusion pattern, you can use the [`NEGATEALL`](#globnegateall).

#### `glob.NEGATEALL, glob.A`
#### `glob.NEGATEALL, glob.A` {: #globnegateall}

`NEGATEALL` can force exclusion patterns, when no inclusion pattern is provided, to assume all files match unless the file matches the excluded pattern. Essentially, it means if you use a pattern such as `!*.md`, it will assume two patterns were given: `**` and `!*.md`, where `!*.md` is applied to the results of `**`, and `**` is specifically treated as if [`GLOBSTAR`](#globglobstar) was enabled.

`NEGATEALL` can force exclusion patterns, when no inclusion pattern is provided, to assume all files match unless the file matches the excluded pattern. Essentially, it means if you use a pattern such as `!*.md`, it will assume a pattern of `*|!*.md` (assuming the use of the [`SPLIT`](#globsplit) flag).
Dot files will not be returned unless [`DOTGLOB`](#globdotglob) is enabled. Symlinks will also be ignored in the return unless [`FOLLOW`](#globfollow) is enabled.

#### `glob.MINUSNEGATE, glob.M` {: #globminusnegate}

Expand Down
2 changes: 1 addition & 1 deletion wcmatch/__meta__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,5 @@ def parse_version(ver, pre=False):
return Version(major, minor, micro, release, pre, post, dev)


__version_info__ = Version(4, 0, 0, ".dev")
__version_info__ = Version(4, 0, 0, "final")
__version__ = __version_info__._get_canonical()

0 comments on commit 15a785c

Please sign in to comment.