Skip to content

Commit 9bd55a7

Browse files
authored
Merge pull request #62 from facelessuser/win-case
Windows case sensitivity flag
2 parents 34c6145 + a6e78d3 commit 9bd55a7

File tree

13 files changed

+349
-64
lines changed

13 files changed

+349
-64
lines changed

docs/src/markdown/changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 4.3.0
4+
5+
- **NEW**: Add `CASE` flag which allows for case sensitive paths on Linux, macOS, and Windows. Windows drive letters and UNC `//host-name/share-name/` portion are still treated insensitively, but all directories will be treated with case sensitivity.
6+
- **NEW**: With the recent addition of `CASE` and `FORCEUNIX`, `FORCECASE` is no longer needed. Deprecate `FORCECASE` which will be removed at some future point.
7+
38
## 4.2.0
49

510
- **NEW**: Drop Python 3.4 support.

docs/src/markdown/fnmatch.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,25 @@ def translate(patterns, *, flags=0):
138138

139139
`FORCECASE` forces case sensitivity. `FORCECASE` has higher priority than [`IGNORECASE`](#fnmatchignorecase).
140140

141-
On Windows, this will force names to be treated like Linux/Unix names, and slashes will not be normalized. It is recommended to use [`FORCEUNIX`](#fnmatchforceunix) if the desire is to force Linux/Unix style logic. It is more intuitive when reading the code and can allow combinations with `IGNORECASE` if a case insensitive Linux/Unix style is preferred. Currently, Windows is the only system that is treated case insensitively by default.
141+
On Windows, this will force names to be treated like Linux/Unix names, and slashes will not be normalized.
142+
143+
!!! warning "Deprecated 4.3.0"
144+
`FORCECASE` has been deprecated as of 4.3.0.
145+
146+
It is recommended to use [`FORCEUNIX`](#fnmatchforceunix) if the desire is to force Linux/Unix style logic. It is more intuitive when reading the code and can allow combinations with `IGNORECASE` if a case insensitive Linux/Unix style is preferred. Currently, Windows is the only system that is treated case insensitively by default.
147+
148+
If you'd like to force case sensitivity, even on Windows, it is recommended to use [`CASE`](#fnmatchcase). `CASE` can also be paired with the [`FORCEWIN`](#fnmatchforceunix) flag if desired.
149+
150+
#### `fnmatch.CASE, fnmatch.C` {: #fnmatchcase}
151+
152+
`CASE` forces case sensitivity. `CASE` has higher priority than [`IGNORECASE`](#fnmatchignorecase).
153+
154+
!!! new "New 4.3.0"
155+
`CASE` is new in 4.3.0.
142156

143157
#### `fnmatch.IGNORECASE, fnmatch.I` {: #fnmatchignorecase}
144158

145-
`IGNORECASE` forces case insensitivity. [`FORCECASE`](#fnmatchforcecase) has higher priority than `IGNORECASE`.
159+
`IGNORECASE` forces case insensitivity. [`CASE`](#fnmatchcase) has higher priority than `IGNORECASE`.
146160

147161
#### `fnmatch.RAWCHARS, fnmatch.R` {: #fnmatchrawchars}
148162

@@ -154,13 +168,13 @@ On Windows, this will force names to be treated like Linux/Unix names, and slash
154168

155169
If it is desired, you can force exclusion patterns, when no inclusion pattern is provided, to assume all files match unless the file matches the excluded pattern. This is done with the [`NEGATEALL`](#fnmatchnegateall) flag.
156170

157-
If used with the extended glob feature, patterns like `!(inverse|pattern)` will be mistakenly parsed as an exclusion pattern instead of as an inverse extended glob group. See [`MINUSNEGATE`](#fnmatchminusgate) for an alternative syntax that plays nice with extended glob.
171+
If used with the extended match feature, patterns like `!(inverse|pattern)` will be mistakenly parsed as an exclusion pattern instead of as an inverse extended glob group. See [`MINUSNEGATE`](#fnmatchminusgate) for an alternative syntax that plays nice with extended glob.
158172

159173
!!! warning "Changes 4.0"
160174
In 4.0, `NEGATE` now requires a non-exclusion pattern to be paired with it or it will match nothing. If you really
161175
need something similar to the old behavior, that would assume a default inclusion pattern, you can use the [`NEGATEALL`](#fnmatchnegateall).
162176

163-
#### `fnmatch.NEGATEALL, glob.A` {: #fnmatchnegateall}
177+
#### `fnmatch.NEGATEALL, fnmatch.A` {: #fnmatchnegateall}
164178

165179
`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 `*`.
166180

@@ -172,7 +186,7 @@ When `MINUSNEGATE` is used with [`NEGATE`](#fnmatchnegate), exclusion patterns a
172186

173187
#### `fnmatch.DOTMATCH, fnmatch.D` {: #fnmatchdotmatch}
174188

175-
By default, [`glob`](#fnmatchfnmatch) and related functions will not match file or directory names that start with dot `.` unless matched with a literal dot. `DOTMATCH` allows the meta characters (such as `*`) to match dots like any other character. Dots will not be matched in `[]`, `*`, or `?`.
189+
By default, [`fnmatch`](#fnmatchfnmatch) and related functions will not match file or directory names that start with dot `.` unless matched with a literal dot. `DOTMATCH` allows the meta characters (such as `*`) to match dots like any other character. Dots will not be matched in `[]`, `*`, or `?`.
176190

177191
#### `fnmatch.EXTMATCH, fnmatch.E` {: #fnmatchextmatch}
178192

@@ -202,8 +216,6 @@ True
202216

203217
`FORCEWIN` will force Windows name and case logic to be used on Linux/Unix systems. It will also cause slashes to be normalized. This is great if you need to match Windows specific names on a Linux/Unix system.
204218

205-
When using `FORCEWIN`, [`FORCECASE`](#fnmatchforcecase) will be ignored as paths on Windows are not case sensitive.
206-
207219
If `FORCEWIN` is used along side [`FORCEUNIX`](#fnmatchforceunix), both will be ignored.
208220

209221
!!! new "New 4.2.0"

docs/src/markdown/glob.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ Pattern | Meaning
3838

3939
- Meta characters have no effect when inside a UNC path: `\\\\Server?\\mount*\\`.
4040

41-
- If [`FORCECASE`](#globforcecase) or [`FORCEUNIX`](#globforceunix) are applied on a Windows system, match and filter commands that do not touch the file system will not have slashes normalized. In addition, drive letters will also not be handled. Essentially, paths will be treated as if on Linux/Unix. Commands on Windows that do touch the file system will ignore `FORCECASE` and `FORCEUNIX`. [`glob`](#globglob) and [`iglob`](#globiglob) will ignore `FORCECASE` on Windows. [`globmatch`](#globglobmatch) and [`globfilter`](#globglobfilter), will also ignore `FORCECASE` if the [`REALPATH`](#globrealpath) flag is enabled.
41+
- If [`FORCEUNIX`](#globforceunix) is applied on a Windows system, match and filter commands that do not touch the file system will not have slashes normalized. In addition, drive letters will also not be handled. Essentially, paths will be treated as if on Linux/Unix. Commands that do touch the file system ([`glob`](#globglob) and [`iglob`](#globiglob)) will ignore `FORCEUNIX` and [`FORCEWIN`](#globforcewin). [`globmatch`](#globglobmatch) and [`globfilter`](#globglobfilter), will also ignore `FORCEUNIX` and `FORCEWIN` if the [`REALPATH`](#globrealpath) flag is enabled.
4242

43-
The reverse applies when [`FORCEWIN`](#globforcewin) is used on a Linux/Unix system.
43+
[`FORCEWIN`](#globforcewin) will do the opposite on a Linux/Unix system, and will force non-Windows logic on a Windows system. Like with `FORCEUNIX`, it only applies to commands that don't touch the file system.
4444

4545
- By default, file and directory names starting with `.` are only matched with literal `.`. The patterns `*`, `**`, `?`, and `[]` will not match a leading `.`. To alter this behavior, you can use the [`DOTGLOB`](#globdotglob) flag, but even with `DOTGLOB` these special tokens will not match a special directory (`.` or `..`). But when a literal `.` is used at the start of the filename, for instance in the pattern `.*`, `.` and `..` can potentially be matched.
4646

@@ -289,11 +289,26 @@ True
289289

290290
On Windows, `FORCECASE` will also force paths to be treated like Linux/Unix paths in [`globmatch`](#globglobmatch) and [`globfilter`](#globfilter), but only when [`REALPATH`](#globrealpath) is not enabled. `iglob`, `glob`, and cases when `REALPATH` is enabled must normalize paths and use Windows logic as these operations are performed on the current file system of the host machine. File system operations should not enable `FORCECASE` on Windows as it provides no meaningful results. But, if you wish to evaluate Linux/Unix paths on a Windows machine, without touching the file system, then `FORCECASE` might be useful.
291291

292-
It is recommended to use [`FORCEUNIX`](#globforceunix) if the desire is to force Linux/Unix style logic. It is more intuitive when reading the code and can allow combinations with `IGNORECASE` if a case insensitive Linux/Unix style is preferred. Currently, Windows is the only system that is treated case insensitively by default.
292+
!!! warning "Deprecated 4.3.0"
293+
294+
`FORCECASE` is deprecated in 4.3.0.
295+
296+
It is recommended to use [`FORCEUNIX`](#globforceunix) if the desire is to force Linux/Unix style logic. It is more intuitive when reading the code and can allow combinations with `IGNORECASE` if a case insensitive Linux/Unix style is preferred.
297+
298+
If you'd like to force case sensitivity, even on Windows, it is recommended to use [`CASE`](#globcase). `CASE` can also be paired with the [`FORCEWIN`](#globforceunix) flag if desired.
299+
300+
#### `glob.CASE, glob.C` {: #globcase}
301+
302+
`CASE` forces case sensitivity. `CASE` has higher priority than [`IGNORECASE`](#globignorecase).
303+
304+
On Windows, drive letters (`C:`) and UNC host/share (`//host/share`) portions of a path will still be treated case insensitively, but the rest of the path will have case sensitive logic applied.
305+
306+
!!! new "New 4.3.0"
307+
`CASE` is new in 4.3.0.
293308

294309
#### `glob.IGNORECASE, glob.I` {: #globignorecase}
295310

296-
`IGNORECASE` forces case insensitivity. [`FORCECASE`](#globforcecase) has higher priority than `IGNORECASE`.
311+
`IGNORECASE` forces case insensitivity. [`CASE`](#globcase) has higher priority than `IGNORECASE`.
297312

298313
#### `glob.RAWCHARS, glob.R` {: #globrawchars}
299314

@@ -339,7 +354,7 @@ When `MINUSNEGATE` is used with [`NEGATE`](#globnegate), exclusion patterns are
339354

340355
In the past, only `glob` and `iglob` operated on the filesystem, but with `REALPATH`, other functions will now operate on the filesystem as well: `globmatch` and `globfilter`.
341356

342-
Traditionally, functions such as `globmatch` would simply match a path with regular expression and return the result. It was not concerned with whether the path existed or not. It didn't care if it was even valid for the operating system as `FORCECASE` would force Linux/Unix path logic on Windows.
357+
Normally, functions such as `globmatch` would simply match a path with regular expression and return the result. The functions were not concerned with whether the path existed or not. It didn't care if it was even valid for the operating system.
343358

344359
`REALPATH` forces `globmatch` and `globfilter` to treat the string path as a real file path for the given system it is running on. It will augment the patterns used to match files and enable additional logic that the path must meet in order to match:
345360

@@ -348,6 +363,8 @@ Traditionally, functions such as `globmatch` would simply match a path with regu
348363
- When presented with a pattern where the match must be a directory, but the file path being compared doesn't indicate the file is a directory with a trailing slash, the command will look at the filesystem to determine if it is a directory.
349364
- Paths must match in relation to the current working directory unless the pattern is constructed in a way to indicates an absolute path.
350365

366+
Since `REALPATH` causes the file system to be referenced when matching a path, flags such as [`FORCEUNIX`](#globforceunix) and [`FORCEWIN`](#globforcewin) are not allowed with this flag and will be ignored.
367+
351368
!!! new "NEW 3.0"
352369
`REALPATH` was added in 3.0.
353370

@@ -437,8 +454,6 @@ from wcmatch import glob
437454

438455
`FORCEWIN` will force Windows path and case logic to be used on Linux/Unix systems. It will also cause slashes to be normalized and Windows drive syntax to be handled special. This is great if you need to match Windows specific paths on a Linux/Unix system. This will only work on commands that do not access the file system: `translate`, `globmatch`, `globfilter`, etc. These flags will not work with `glob` or `iglob`. It also will not work when using the [`REALPATH`](#globrealpath) flag with things like `globmatch` and `globfilter`.
439456

440-
When using `FORCEWIN`, [`FORCECASE`](#globforcecase) will be ignored as paths on Windows are not case sensitive.
441-
442457
If `FORCEWIN` is used along side [`FORCEUNIX`](#globforceunix), both will be ignored.
443458

444459
!!! new "New 4.2.0"

docs/src/markdown/wcmatch.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,22 @@ is called on every new `match` call.
279279

280280
`FORCECASE` does not apply to Windows systems.
281281

282+
!!! warning "Deprecated 4.3.0"
283+
284+
`FORCECASE` is deprecated in 4.3.0.
285+
286+
If you'd like to force case sensitivity, even on Windows, it is recommended to use [`CASE`](#wcmatchcase).
287+
288+
#### `wcmatch.CASE, wcmatch.C` {: #wcmatchcase}
289+
290+
`CASE` forces case sensitivity. `CASE` has higher priority than [`IGNORECASE`](#wcmatchignorecase).
291+
292+
!!! new "New 4.3.0"
293+
`CASE` is new in 4.3.0.
294+
282295
#### `wcmatch.IGNORECASE, wcmatch.I` {: #wcmatchignorecase}
283296

284-
`IGNORECASE` forces case insensitive searches. `FORCECASE` has higher priority than [`IGNORECASE`](#wcmatchignorecase).
297+
`IGNORECASE` forces case insensitive searches. [`CASE`](#wcmatchcase) has higher priority than `IGNORECASE`.
285298

286299
#### `wcmatch.RAWCHARS, wcmatch.R` {: #wcmatchrawchars}
287300

0 commit comments

Comments
 (0)