Skip to content

Commit

Permalink
(backport) yield_sequences_in_list: use unique key for single files w…
Browse files Browse the repository at this point in the history
…ith no frame to prevent name collision with same basename using frames (refs #135)
  • Loading branch information
justinfx committed Nov 4, 2024
1 parent 584ee22 commit 04da940
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/fileseq/filesequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,8 @@ def yield_sequences_in_list(
:obj:`FileSequence`:
"""
seqs = {}
variant_seq = 0
variant_single = 1
if allow_subframes:
_check = cls.DISK_SUB_RE.match
else:
Expand All @@ -839,7 +841,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 @@ -849,9 +851,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 @@ -896,7 +898,8 @@ def frames_to_seq(frames, pad_length, decimal_places):
finish_new_seq(seq)
return seq

for (dirname, basename, ext, decimal_places), frames in iteritems(seqs):
for parts, frames in iteritems(seqs):
(dirname, basename, ext, decimal_places) = parts[:4]
# 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 @@ -1361,6 +1361,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 04da940

Please sign in to comment.