diff --git a/client/ayon_core/plugins/publish/integrate_traits.py b/client/ayon_core/plugins/publish/integrate_traits.py index de1bd5fc16..72a7ddd479 100644 --- a/client/ayon_core/plugins/publish/integrate_traits.py +++ b/client/ayon_core/plugins/publish/integrate_traits.py @@ -918,8 +918,7 @@ class IntegrateTraits(pyblish.api.InstancePlugin): template_item.template_data["frame"] = frame template_item.template_data["ext"] = ( - file_loc.file_path.suffix - ) + file_loc.file_path.suffix.lstrip(".")) template_filled = path_template_object.format_strict( template_item.template_data ) @@ -1026,7 +1025,7 @@ class IntegrateTraits(pyblish.api.InstancePlugin): template_item.template_object["path"] ) template_item.template_data["ext"] = ( - representation.get_trait(FileLocation).file_path.suffix.rstrip(".") + representation.get_trait(FileLocation).file_path.suffix.lstrip(".") ) template_item.template_data.pop("frame", None) with contextlib.suppress(MissingTraitError): @@ -1110,10 +1109,17 @@ class IntegrateTraits(pyblish.api.InstancePlugin): path (Path): Destination url of published file. anatomy (Anatomy): Project anatomy part from instance. + Raises: + PublishError: If file does not exist. + Returns: dict[str, Any]: Representation file info dictionary. """ + if not path.exists(): + msg = f"File '{path}' does not exist." + raise PublishError(msg) + return { "id": create_entity_id(), "name": path.name, @@ -1131,6 +1137,9 @@ class IntegrateTraits(pyblish.api.InstancePlugin): ) -> list[dict[str, str]]: """Get legacy files for a given representation. + This expects the file to exist - it must run after the transfer + is done. + Returns: list: List of legacy files. diff --git a/tests/client/ayon_core/plugins/publish/test_integrate_traits.py b/tests/client/ayon_core/plugins/publish/test_integrate_traits.py index 252556fe29..98f02bdff6 100644 --- a/tests/client/ayon_core/plugins/publish/test_integrate_traits.py +++ b/tests/client/ayon_core/plugins/publish/test_integrate_traits.py @@ -12,6 +12,11 @@ import pytest from ayon_api.operations import ( OperationsSession, ) + +from ayon_core.lib.file_transaction import ( + FileTransaction, +) + from ayon_core.pipeline.anatomy import Anatomy from ayon_core.pipeline.traits import ( Bundle, @@ -30,9 +35,20 @@ from ayon_core.pipeline.version_start import get_versioning_start # Tagged, # TemplatePath, -from ayon_core.plugins.publish.integrate_traits import IntegrateTraits +from ayon_core.plugins.publish.integrate_traits import ( + IntegrateTraits, + TransferItem, +) + from ayon_core.settings import get_project_settings +from ayon_api.operations import ( + OperationsSession, + new_product_entity, + new_representation_entity, + new_version_entity, +) + if TYPE_CHECKING: import pytest_ayon @@ -315,6 +331,9 @@ def test_get_transfers_from_representation( mock_context: pyblish.api.Context) -> None: """Test get_transfers_from_representation. + This tests getting actual transfers from the representations and + also the legacy files. + Todo: This test will benefit massively from a proper mocking of the context. We need to parametrize the test with different representations and test the output of the function. @@ -332,4 +351,22 @@ def test_get_transfers_from_representation( assert len(transfers) == 22 for transfer in transfers: - ... + assert transfer.checksum == TransferItem.get_checksum( + transfer.source) + + file_transactions = FileTransaction( + # Enforce unique transfers + allow_queue_replacements=False) + + for transfer in transfers: + file_transactions.add( + transfer.source.as_posix(), + transfer.destination.as_posix(), + mode=FileTransaction.MODE_COPY, + ) + + file_transactions.process() + + for representation in representations: + files = integrator._get_legacy_files_for_representation( # noqa: SLF001 + transfers, representation, anatomy=instance.data["anatomy"])