Skip to content

Commit

Permalink
fix regex to handle parsing multi-component file extensions with sing…
Browse files Browse the repository at this point in the history
…le character components ("file.1.a.ext") (fixes #120)
  • Loading branch information
justinfx committed Jun 1, 2023
1 parent fbd2abd commit 2434ea2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/fileseq/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ def __eq__(self, other):
# Regular expression pattern for matching file names on disk.
DISK_PATTERN = r"""
\A
((?:.*[/\\])?) # dirname
(.*?) # basename
(-?\d+)? # frame
( # ext
(?:\.\w*[a-zA-Z]\w)* # optional leading alnum ext prefix (.foo.1bar)
(?:\.[^.]+)? # ext suffix
((?:.*[/\\])?) # dirname
(.*?) # basename
(-?\d+)? # frame
( # ext
(?:\.\w*[a-zA-Z]\w?)* # optional leading alnum ext prefix (.foo.1bar)
(?:\.[^.]+)? # ext suffix
)
\Z
"""
Expand All @@ -169,12 +169,12 @@ def __eq__(self, other):
# Regular expression pattern for matching file names on disk allowing subframes.
DISK_SUB_PATTERN = r"""
\A
((?:.*[/\\])?) # dirname
(.*?) # basename
(-?\d+(?:\.\d+)?)? # frame
( # ext
(?:\.\w*[a-zA-Z]\w)* # optional leading alnum ext prefix (.foo.1bar)
(?:\.[^.]+)? # ext suffix
((?:.*[/\\])?) # dirname
(.*?) # basename
(-?\d+(?:\.\d+)?)? # frame
( # ext
(?:\.\w*[a-zA-Z]\w?)* # optional leading alnum ext prefix (.foo.1bar)
(?:\.[^.]+)? # ext suffix
)
\Z
"""
Expand Down
Empty file added test/complex_ext/1.a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added test/complex_ext/2.a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added test/complex_ext/3.a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added test/complex_ext/file.5.a.ext
Empty file.
Empty file added test/complex_ext/file.6.a.ext
Empty file.
Empty file added test/complex_ext/file.7.a.ext
Empty file.
4 changes: 4 additions & 0 deletions test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,8 @@ def testFindSequenceOnDisk(self):
("subframe_seq/baz.#.0000.exr", "subframe_seq/baz.1-4#.0000.exr"),
("subframe_seq/baz.0001.#.exr", "subframe_seq/baz.0001.0-7500x2500#.exr"),
("subframe_seq/baz.0001.0000.exr", "subframe_seq/baz.0001.0-7500x2500#.exr"),
("complex_ext/@.a.jpg", "complex_ext/1-3@.a.jpg"),
("complex_ext/file.@.a.ext", "complex_ext/file.5-7@.a.ext"),
]

for pattern, expected in tests:
Expand Down Expand Up @@ -1703,6 +1705,8 @@ def testStrictPadding(self):
("seq/big.#@.ext", None),
("multi_range/file_@@.0001.exr", None),
("multi_range/file_#.0001.exr", "multi_range/file_3-5#.0001.exr"),
("complex_ext/#.a.jpg", None),
("complex_ext/@.a.jpg", "complex_ext/1-3@.a.jpg"),
]

for pattern, expected in tests:
Expand Down

0 comments on commit 2434ea2

Please sign in to comment.