Skip to content

Commit

Permalink
Address feedback from PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
robin-ynput committed Dec 3, 2024
1 parent 648c2c5 commit 0672f5c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 24 deletions.
57 changes: 38 additions & 19 deletions client/ayon_core/pipeline/create/creator_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,17 +833,15 @@ def get_pre_create_attr_defs(self):
"""
return self.pre_create_attr_defs

def apply_staging_dir(self, instance):
"""Apply staging dir with persistence to instance's transient data.
Method is called on instance creation and on instance update.
def get_staging_dir(self, instance):
"""Return the staging dir and persistence from instance.
Args:
instance (CreatedInstance): Instance for which should be staging
dir applied.
dir gathered.
Returns:
Optional[str]: Staging dir path or None if not applied.
Optional[namedtuple]: Staging dir path and persistence or None
"""
create_ctx = self.create_context
product_name = instance.get("productName")
Expand All @@ -852,25 +850,32 @@ def apply_staging_dir(self, instance):

# this can only work if product name and folder path are available
if not product_name or not folder_path:
return

version = instance.get("version")
if version is not None:
template_data = {"version": version}
else:
template_data = {}
return None

# TODO: confirm feature
publish_settings = self.project_settings["core"]["publish"]
follow_workfile_version = (
publish_settings
["CollectAnatomyInstanceData"]
["follow_workfile_version"]
)
if follow_workfile_version:

# Gather version number provided from the instance.
version = instance.get("version")

# If follow workfile, gather version from workfile path.
if version is None and follow_workfile_version:
current_workfile = self.create_context.get_current_workfile_path()
workfile_version = get_version_from_path(current_workfile)
template_data = {"version": int(workfile_version)}
version = int(workfile_version)

# Fill-up version with next version available.
elif version is None:
versions = self.get_next_versions_for_instances(
[instance]
)
version, = tuple(versions.values())

template_data = {"version": version}

staging_dir_info = get_staging_dir_info(
create_ctx.get_current_project_entity(),
Expand All @@ -886,12 +891,26 @@ def apply_staging_dir(self, instance):
template_data=template_data,
)

if not staging_dir_info:
return None
return staging_dir_info or None

def apply_staging_dir(self, instance):
"""Apply staging dir with persistence to instance's transient data.
Method is called on instance creation and on instance update.
staging_dir_path = staging_dir_info.dir
Args:
instance (CreatedInstance): Instance for which should be staging
dir applied.
Returns:
Optional[str]: Staging dir path or None if not applied.
"""
staging_dir_info = self.get_staging_dir(instance)
if staging_dir_info is None:
return None

# path might be already created by get_staging_dir_info
staging_dir_path = staging_dir_info.directory
os.makedirs(staging_dir_path, exist_ok=True)

instance.transient_data.update({
Expand Down
2 changes: 1 addition & 1 deletion client/ayon_core/pipeline/publish/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def get_instance_staging_dir(instance):
always_return_path=True,
)

staging_dir_path = staging_dir_info.dir
staging_dir_path = staging_dir_info.directory

# path might be already created by get_staging_dir_info
os.makedirs(staging_dir_path, exist_ok=True)
Expand Down
9 changes: 5 additions & 4 deletions client/ayon_core/pipeline/staging_dir.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple
from dataclasses import dataclass

from ayon_core.lib import Logger, filter_profiles, StringTemplate
from ayon_core.lib import Logger, filter_profiles
from ayon_core.settings import get_project_settings

from .template_data import get_template_data
Expand Down Expand Up @@ -42,7 +42,7 @@ def get_staging_dir_config(
Dict or None: Data with directory template and is_persistent or None
Raises:
ValueError - if misconfigured template should be used
KeyError - if misconfigured template should be used
"""
settings = project_settings or get_project_settings(project_name)
Expand Down Expand Up @@ -129,12 +129,12 @@ def get_staging_dir_info(
If `prefix` or `suffix` is not set, default values will be used.
Arguments:
host_name (str): Name of host.
project_entity (Dict[str, Any]): Project entity.
folder_entity (Optional[Dict[str, Any]]): Folder entity.
task_entity (Optional[Dict[str, Any]]): Task entity.
product_type (str): Type of product.
product_name (str): Name of product.
host_name (str): Name of host.
anatomy (Optional[Anatomy]): Anatomy object.
project_settings (Optional[Dict[str, Any]]): Prepared project settings.
template_data (Optional[Dict[str, Any]]): Additional data for
Expand Down Expand Up @@ -184,6 +184,7 @@ def get_staging_dir_info(
# add additional template formatting data
if template_data:
ctx_data.update(template_data)

task_name = task_type = None
if task_entity:
task_name = task_entity["name"]
Expand Down

0 comments on commit 0672f5c

Please sign in to comment.