Skip to content

Commit

Permalink
yield_sequences_in_list: use unique key for single files with no fram…
Browse files Browse the repository at this point in the history
…e to prevent name collision with same basename using frames (refs #135)
  • Loading branch information
justinfx committed Oct 30, 2024
1 parent e75c898 commit f96f3ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/fileseq/filesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,9 @@ def yield_sequences_in_list(
Yields:
:obj:`FileSequence`:
"""
seqs: dict[tuple[str, str, str, int], set[str]] = {}
seqs: dict[tuple[str, str, str, int, int], set[str]] = {}
variant_seq = 0
variant_single = 1
if allow_subframes:
_check = cls.DISK_SUB_RE.match
else:
Expand All @@ -875,7 +877,7 @@ def yield_sequences_in_list(
except decimal.DecimalException:
continue
_, _, subframe = frame.partition(".")
key = (dirname, basename, ext, len(subframe))
key = (dirname, basename, ext, len(subframe), variant_seq)
seqs.setdefault(key, frames).add(frame)

else:
Expand All @@ -885,9 +887,9 @@ def yield_sequences_in_list(
continue
if frame:
_, _, subframe = frame.partition(".")
key = (dirname, basename, ext, len(subframe))
key = (dirname, basename, ext, len(subframe), variant_seq)
else:
key = (dirname, basename, ext, 0)
key = (dirname, basename, ext, 0, variant_single)
seqs.setdefault(key, set())
if frame:
seqs[key].add(frame)
Expand Down Expand Up @@ -933,7 +935,7 @@ def frames_to_seq(frames: typing.Iterable[str], pad_length: int, decimal_places:
finish_new_seq(seq)
return seq

for (dirname, basename, ext, decimal_places), frames in seqs.items():
for (dirname, basename, ext, decimal_places, *_), frames in seqs.items():
# Short-circuit logic if we do not have multiple frames, since we
# only need to build and return a single simple sequence
if not frames:
Expand Down
16 changes: 16 additions & 0 deletions test/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,22 @@ def test_yield_sequences_in_list_pad_style(self):
self.assertEqual(fileseq.PAD_STYLE_HASH1, actual.padStyle())
self.assertEqual(4, actual.zfill())

def test_yield_sequences_in_list_frame_no_frame(self):
paths = [
'frame_no_frame/file02.jpg',
'frame_no_frame/file.jpg',
'frame_no_frame/name.jpg',
]

expects = [
'frame_no_frame/file2@@.jpg',
'frame_no_frame/file.jpg',
'frame_no_frame/name.jpg',
]
actual = {str(fs) for fs in FileSequence.yield_sequences_in_list(paths)}
for expect in expects:
self.assertIn(expect, actual)

def testIgnoreFrameSetStrings(self):
for char in "xy:,".split():
fs = FileSequence("/path/to/file{0}1-1x1#.exr".format(char))
Expand Down

0 comments on commit f96f3ba

Please sign in to comment.