Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #6160 from ynput/enhancement/OP-7687_Environments-…
Browse files Browse the repository at this point in the history
…in-RoyalRender
  • Loading branch information
mkolar authored Apr 30, 2024
2 parents 3e02224 + 57b1b1f commit 4bb1959
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 326 deletions.
88 changes: 20 additions & 68 deletions openpype/modules/royalrender/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
RRJob,
RREnvList,
get_rr_platform,
SubmitterParameter
)
from openpype.pipeline import OpenPypePyblishPluginMixin
from openpype.pipeline.publish import KnownPublishError
Expand Down Expand Up @@ -110,7 +111,7 @@ def process(self, instance):
if not self._rr_root:
raise KnownPublishError(
("Missing RoyalRender root. "
"You need to configure RoyalRender module."))
"Admin needs to configure RoyalRender module in Settings ."))

self.rr_api = rrApi(self._rr_root)

Expand Down Expand Up @@ -175,6 +176,19 @@ def get_job(self, instance, script_path, render_path, node_name):
instance, render_path, start_frame, end_frame)
instance.data["expectedFiles"].extend(expected_files)

submitter_parameters = []

anatomy_data = instance.context.data["anatomyData"]
environment = RREnvList({
"AVALON_PROJECT": anatomy_data["project"]["name"],
"AVALON_ASSET": instance.context.data["asset"],
"AVALON_TASK": anatomy_data["task"]["name"],
"AVALON_APP_NAME": instance.context.data.get("appName"),
"AYON_RENDER_JOB": "1",
"AYON_BUNDLE_NAME": os.environ["AYON_BUNDLE_NAME"]
})

render_dir = render_dir.replace("\\", "/")
job = RRJob(
Software="",
Renderer="",
Expand All @@ -185,7 +199,7 @@ def get_job(self, instance, script_path, render_path, node_name):
Version=0,
SceneName=script_path,
IsActive=True,
ImageDir=render_dir.replace("\\", "/"),
ImageDir=render_dir,
ImageFilename=file_name,
ImageExtension=file_ext,
ImagePreNumberLetter="",
Expand All @@ -197,7 +211,10 @@ def get_job(self, instance, script_path, render_path, node_name):
CompanyProjectName=instance.context.data["projectName"],
ImageWidth=instance.data["resolutionWidth"],
ImageHeight=instance.data["resolutionHeight"],
CustomAttributes=custom_attributes
CustomAttributes=custom_attributes,
SubmitterParameters=submitter_parameters,
rrEnvList=environment.serialize(),
rrEnvFile=os.path.join(render_dir, "rrEnv.rrEenv"),
)

return job
Expand Down Expand Up @@ -307,68 +324,3 @@ def pad_file_name(self, path, first_frame):
path = path.replace(first_frame, "#" * padding)

return path

def inject_environment(self, instance, job):
# type: (pyblish.api.Instance, RRJob) -> RRJob
"""Inject environment variables for RR submission.
This function mimics the behaviour of the Deadline
integration. It is just temporary solution until proper
runtime environment injection is implemented in RR.
Args:
instance (pyblish.api.Instance): Publishing instance
job (RRJob): RRJob instance to be injected.
Returns:
RRJob: Injected RRJob instance.
Throws:
RuntimeError: If any of the required env vars is missing.
"""

temp_file_name = "{}_{}.json".format(
datetime.utcnow().strftime('%Y%m%d%H%M%S%f'),
str(uuid.uuid1())
)

export_url = os.path.join(tempfile.gettempdir(), temp_file_name)
print(">>> Temporary path: {}".format(export_url))

args = [
"--headless",
"extractenvironments",
export_url
]

anatomy_data = instance.context.data["anatomyData"]

add_kwargs = {
"project": anatomy_data["project"]["name"],
"asset": instance.context.data["asset"],
"task": anatomy_data["task"]["name"],
"app": instance.context.data.get("appName"),
"envgroup": "farm"
}

if os.getenv('IS_TEST'):
args.append("--automatic-tests")

if not all(add_kwargs.values()):
raise RuntimeError((
"Missing required env vars: AVALON_PROJECT, AVALON_ASSET,"
" AVALON_TASK, AVALON_APP_NAME"
))

for key, value in add_kwargs.items():
args.extend([f"--{key}", value])
self.log.debug("Executing: {}".format(" ".join(args)))
run_openpype_process(*args, logger=self.log)

self.log.debug("Loading file ...")
with open(export_url) as fp:
contents = json.load(fp)

job.rrEnvList = RREnvList(contents).serialize()
return job
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ def process(self, instance):
job = self.get_job(instance, self.scene_path, first_file_path,
layer_name)
job = self.update_job_with_host_specific(instance, job)
job = self.inject_environment(instance, job)

instance.data["rrJobs"].append(job)
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def process(self, instance):
jobs = self.create_jobs(instance)
for job in jobs:
job = self.update_job_with_host_specific(instance, job)
job = self.inject_environment(instance, job)

instance.data["rrJobs"].append(job)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CreatePublishRoyalRenderJob(pyblish.api.InstancePlugin,
"AVALON_APP_NAME",
"OPENPYPE_USERNAME",
"OPENPYPE_SG_USER",
"OPENPYPE_MONGO"
"AYON_BUNDLE_NAME"
]
priority = 50

Expand Down Expand Up @@ -231,13 +231,13 @@ def get_job(self, instance, instances):
]

job = RRJob(
Software="OpenPype",
Software="AYON",
Renderer="Once",
SeqStart=1,
SeqEnd=1,
SeqStep=1,
SeqFileOffset=0,
Version=self._sanitize_version(os.environ.get("OPENPYPE_VERSION")),
Version=os.environ["AYON_BUNDLE_NAME"],
SceneName=abs_metadata_path,
# command line arguments
CustomAddCmdFlags=" ".join(args),
Expand All @@ -264,26 +264,3 @@ def get_job(self, instance, instances):
job.WaitForPreIDs += jobs_pre_ids

return job

def _sanitize_version(self, version):
"""Returns version in format MAJOR.MINORPATCH
3.15.7-nightly.2 >> 3.157
"""
VERSION_REGEX = re.compile(
r"(?P<major>0|[1-9]\d*)"
r"\.(?P<minor>0|[1-9]\d*)"
r"\.(?P<patch>0|[1-9]\d*)"
r"(?:-(?P<prerelease>[a-zA-Z\d\-.]*))?"
r"(?:\+(?P<buildmetadata>[a-zA-Z\d\-.]*))?"
)

valid_parts = VERSION_REGEX.findall(version)
if len(valid_parts) != 1:
# Return invalid version with filled 'origin' attribute
return version

# Unpack found version
major, minor, patch, pre, post = valid_parts[0]

return "{}.{}{}".format(major, minor, patch)
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def create_file(self, name, ext, contents=None):
return temp.name

def get_submission_parameters(self):
return [SubmitterParameter("RequiredMemory", "0")]
return [SubmitterParameter("RequiredMemory", "0"),
SubmitterParameter("PPAyoninjectenvvar", "1~1")]

@staticmethod
def _resolve_rr_path(context, rr_path_name):
Expand Down
8 changes: 8 additions & 0 deletions openpype/modules/royalrender/royal_render_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import os
import openpype.modules
from openpype.modules import OpenPypeModule, IPluginPaths
from openpype import AYON_SERVER_ENABLED
from openpype.lib import Logger



class RoyalRenderModule(OpenPypeModule, IPluginPaths):
Expand Down Expand Up @@ -31,6 +34,11 @@ def initialize(self, module_settings):
self.enabled = rr_settings["enabled"]
self.rr_paths = rr_settings.get("rr_paths")

# Ayon only
if not AYON_SERVER_ENABLED:
self.log.info("RoyalRender is not implemented for Openpype")
self.enabled = False

@staticmethod
def get_plugin_paths():
# type: () -> dict
Expand Down
1 change: 1 addition & 0 deletions openpype/modules/royalrender/rr_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class RRJob(object):
# Environment
# only used in RR 8.3 and newer
rrEnvList = attr.ib(default=None, type=str) # type: str
rrEnvFile = attr.ib(default=None, type=str) # type: str


class SubmitterParameter:
Expand Down
Loading

0 comments on commit 4bb1959

Please sign in to comment.