From 88e4a02081f8d16003a91b981dfdc8cabc0bc395 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Sun, 30 Apr 2023 14:59:44 +0200 Subject: [PATCH 1/2] Skip cleanup if there's only one single file Fixes https://projects.blender.org/blender/blender-addons/issues/104573 Before this change we tried to cleanup a list consisting of a single file only. Then, since that single file had the same prefix as itself, we removed it from the list. With this change in place, we skip cleanup if there's only one single file. --- node_wrangler/utils/paths.py | 2 +- node_wrangler/utils/paths_test.py | 32 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/node_wrangler/utils/paths.py b/node_wrangler/utils/paths.py index 67f68dc85..18c8d84e5 100644 --- a/node_wrangler/utils/paths.py +++ b/node_wrangler/utils/paths.py @@ -103,7 +103,7 @@ def files_to_clean_file_names_for_sockets(files, sockets): socket_tags = socket[1] all_tags.update(socket_tags) - while True: + while names_to_tag_lists and len(names_to_tag_lists) > 1: something_changed = False # Common prefixes / suffixes provide zero information about what file diff --git a/node_wrangler/utils/paths_test.py b/node_wrangler/utils/paths_test.py index 130cf7b31..8ee3ceb0a 100755 --- a/node_wrangler/utils/paths_test.py +++ b/node_wrangler/utils/paths_test.py @@ -255,6 +255,38 @@ class TestPutFileNamesInSockets(unittest.TestCase): }, ) + def test_single_file_good(self): + """Regression test for https://projects.blender.org/blender/blender-addons/issues/104573""" + + files = [ + MockFile("banana-color.webp"), + ] + sockets = sockets_fixture() + match_files_to_socket_names(files, sockets) + + assert_sockets( + self, + sockets, + { + "Base Color": "banana-color.webp", + }, + ) + + def test_single_file_bad(self): + """Regression test for https://projects.blender.org/blender/blender-addons/issues/104573""" + + files = [ + MockFile("README-banana.txt"), + ] + sockets = sockets_fixture() + match_files_to_socket_names(files, sockets) + + assert_sockets( + self, + sockets, + {}, + ) + if __name__ == "__main__": unittest.main(verbosity=2) -- 2.30.2 From daee55f8fcda9c3560de1b30bfb0856b1d06f09f Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Mon, 26 Jun 2023 19:46:37 +0200 Subject: [PATCH 2/2] Handle review comment The dict cannot be None, and thus the first check is redundant. --- node_wrangler/utils/paths.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_wrangler/utils/paths.py b/node_wrangler/utils/paths.py index 18c8d84e5..7e75ef0b2 100644 --- a/node_wrangler/utils/paths.py +++ b/node_wrangler/utils/paths.py @@ -103,7 +103,7 @@ def files_to_clean_file_names_for_sockets(files, sockets): socket_tags = socket[1] all_tags.update(socket_tags) - while names_to_tag_lists and len(names_to_tag_lists) > 1: + while len(names_to_tag_lists) > 1: something_changed = False # Common prefixes / suffixes provide zero information about what file -- 2.30.2