-
Notifications
You must be signed in to change notification settings - Fork 60
SG-44787 Validate previous published pipeline step when building new scene #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
carlos-villavicencio-adsk
wants to merge
6
commits into
master
from
ticket/SG-44787-validate-previous-step-published
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6592ef3
SG-44787 Validate previous pipeline step is published before building…
carlos-villavicencio-adsk 837a40f
SG-44787 Add tests for the pipeline step publish validation
carlos-villavicencio-adsk fffdb16
SG-44787 Limit the previous-step publish check to Maya
carlos-villavicencio-adsk 4e67fcd
SG-44787 Fix pipeline_step_dependencies example to use real Step names
carlos-villavicencio-adsk b7f6be1
SG-44787 Default pipeline_step_dependencies to Model for Rig and Texture
carlos-villavicencio-adsk 8a051d8
Update message box to use hosts dialog
carlos-villavicencio-adsk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,167 @@ | ||
| # Copyright (c) 2026 Shotgun Software Inc. | ||
| # | ||
| # CONFIDENTIAL AND PROPRIETARY | ||
| # | ||
| # This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit | ||
| # Source Code License included in this distribution package. See LICENSE. | ||
| # By accessing, using, copying or modifying this work you indicate your | ||
| # agreement to the Shotgun Pipeline Toolkit Source Code License. All rights | ||
| # not expressly granted therein are reserved by Shotgun Software Inc. | ||
|
|
||
| """Pipeline step validation helpers for Flow Asset Management. | ||
|
|
||
| Building a new scene for a downstream department only makes sense once the | ||
| upstream department has published its workfile, because that publish is what | ||
| gets referenced into the new scene. | ||
| """ | ||
|
|
||
| from __future__ import annotations # needed for Houdini support | ||
|
|
||
| from typing import Dict, Optional | ||
|
|
||
| import sgtk | ||
| from sgtk.flowam.create import ASSET_FOLDER, ASSET_TYPE, SHOT_TYPE | ||
| from tank_vendor.flow_integration_sdk import exceptions, objects, schema | ||
|
|
||
| logger = sgtk.platform.get_logger(__name__) | ||
|
|
||
|
|
||
| def get_upstream_step( | ||
| pipeline_step: str, step_dependencies: Dict[str, str] | ||
| ) -> Optional[str]: | ||
| """Return the pipeline step that must be published before *pipeline_step*. | ||
|
|
||
| :param pipeline_step: Name of the step a new scene is being built for. | ||
| :param step_dependencies: Mapping of step name to upstream step name, as | ||
| provided by the ``pipeline_step_dependencies`` app setting. | ||
| :returns: Upstream step name, or ``None`` when the step has no configured | ||
| upstream requirement. | ||
| """ | ||
| if not pipeline_step or not step_dependencies: | ||
| return None | ||
|
|
||
| return step_dependencies.get(pipeline_step) or None | ||
|
|
||
|
|
||
| def find_unpublished_upstream_step( | ||
| am_project_id: str, | ||
| sg_entity_type: str, | ||
| sg_entity_name: str, | ||
| sg_pipeline_step: str, | ||
| workfile_type: str, | ||
| step_dependencies: Dict[str, str], | ||
| ) -> Optional[str]: | ||
| """Return the upstream pipeline step that still needs to be published. | ||
|
|
||
| :param am_project_id: Id of the Flow AM project holding the asset. | ||
| :param sg_entity_type: FPTR entity type of the asset, e.g. ``"Asset"``. | ||
| :param sg_entity_name: FPTR entity name of the asset. | ||
| :param sg_pipeline_step: Step the new scene is being built for. | ||
| :param workfile_type: Schema type name of the workfile to look for, e.g. | ||
| ``"type.workfile.maya"`` from ``FlowHost.WORKFILE_TYPE``. | ||
| :param step_dependencies: Mapping of step name to upstream step name. | ||
| :returns: Name of the upstream step when it is configured but has no | ||
| published workfile, otherwise ``None``. | ||
| """ | ||
| upstream_step = get_upstream_step(sg_pipeline_step, step_dependencies) | ||
| if not upstream_step: | ||
| return None | ||
|
|
||
| if has_published_workfile( | ||
| am_project_id=am_project_id, | ||
| pipeline_step=upstream_step, | ||
| sg_entity_name=sg_entity_name, | ||
| sg_entity_type=sg_entity_type, | ||
| workfile_type=workfile_type, | ||
| ): | ||
| return None | ||
|
|
||
| return upstream_step | ||
|
|
||
|
|
||
| def has_published_workfile( | ||
| am_project_id: str, | ||
| pipeline_step: str, | ||
| sg_entity_name: str, | ||
| sg_entity_type: str, | ||
| workfile_type: str, | ||
| ) -> bool: | ||
| """Return ``True`` when *pipeline_step* has a published workfile for the asset. | ||
|
|
||
| A workfile asset only exists in Flow AM once it has been published: | ||
| ``sandbox.create_asset_in_sandbox()`` writes a local draft and defers the | ||
| Flow AM asset creation to publish time. Finding a workfile-typed child is | ||
| therefore enough to prove the step was published, whereas the hierarchy | ||
| enclosing it may well exist for a step nobody has published yet. | ||
|
|
||
| When the answer cannot be determined this returns ``True``, so a transient | ||
| Flow AM error never blocks a build behind a misleading "not published" | ||
| message. | ||
|
|
||
| :param am_project_id: Id of the Flow AM project holding the asset. | ||
| :param pipeline_step: Step to look for a published workfile under. | ||
| :param sg_entity_name: FPTR entity name of the asset. | ||
| :param sg_entity_type: FPTR entity type of the asset, e.g. ``"Asset"``. | ||
| :param workfile_type: Schema type name of the workfile to look for. | ||
| :returns: ``True`` when a published workfile exists or cannot be ruled out. | ||
| """ | ||
| root_folder_name = _get_root_folder_name(sg_entity_type) | ||
| if not root_folder_name: | ||
| logger.warning( | ||
| f'Cannot locate Flow AM assets for entity type "{sg_entity_type}". ' | ||
| f'Skipping the publish check for pipeline step "{pipeline_step}".' | ||
| ) | ||
| return True | ||
|
|
||
| workfile_type_id = schema.get_schema_id(workfile_type) | ||
| if not workfile_type_id: | ||
| # An unresolved type id would disable the type filter in find_children() | ||
| # and match every child, so skip the check rather than trust it. | ||
| logger.warning( | ||
| f'Could not resolve the schema id for workfile type "{workfile_type}". ' | ||
| f'Skipping the publish check for pipeline step "{pipeline_step}".' | ||
| ) | ||
| return True | ||
|
|
||
| try: | ||
| node = objects.FlowProject(am_project_id) | ||
| # Walk down to the "root asset" grouping the workfiles of this step: | ||
| # Assets/<entity>/<step>/<entity>. See get_or_create_workfile_parent() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if this Assets/// hierarchy would be changed after Federation change? @yungsiow |
||
| # in tk-core's tank/flowam/create.py for the hierarchy this mirrors. | ||
| for name in ( | ||
| root_folder_name, | ||
| sg_entity_name, | ||
| pipeline_step, | ||
| sg_entity_name, | ||
| ): | ||
| node = node.find_child(name) | ||
| if node is None: | ||
| return False | ||
|
|
||
| return bool(node.find_children(type_id=workfile_type_id)) | ||
| except exceptions.FlowError as exc: | ||
| logger.warning( | ||
| f'Could not verify whether pipeline step "{pipeline_step}" has a ' | ||
| f'published workfile for "{sg_entity_name}". Allowing the build to ' | ||
| f"proceed. ({exc})" | ||
| ) | ||
| return True | ||
|
|
||
|
|
||
| def _get_root_folder_name(sg_entity_type: str) -> Optional[str]: | ||
| """Return the name of the top-level folder holding assets of *sg_entity_type*. | ||
|
|
||
| Mirrors ``get_or_create_root_folder()`` in tk-core's ``tank/flowam/create.py``, | ||
| where the two folder names are asymmetric: assets live under ``ASSET_FOLDER`` | ||
| ("Assets") while shots live under a folder named after ``SHOT_TYPE`` ("Shot"). | ||
|
|
||
| :param sg_entity_type: FPTR entity type of the asset. | ||
| :returns: Folder name, or ``None`` when the entity type has no such folder. | ||
| """ | ||
| if sg_entity_type == ASSET_TYPE: | ||
| return ASSET_FOLDER | ||
|
|
||
| if sg_entity_type == SHOT_TYPE: | ||
| return SHOT_TYPE | ||
|
|
||
| return None | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.