From 86a1357033c18a82f76385df8ae8531ae446f48e Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 12 May 2023 18:23:38 +0200 Subject: [PATCH] OP-1066 - sanitize version RR expect version in format 3.157 instead proper 3.15.7-nightly.2 --- .../publish/create_publish_royalrender_job.py | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/openpype/modules/royalrender/plugins/publish/create_publish_royalrender_job.py b/openpype/modules/royalrender/plugins/publish/create_publish_royalrender_job.py index c652509373..6eb8f2649e 100644 --- a/openpype/modules/royalrender/plugins/publish/create_publish_royalrender_job.py +++ b/openpype/modules/royalrender/plugins/publish/create_publish_royalrender_job.py @@ -3,6 +3,7 @@ import os import attr import json +import re import pyblish.api @@ -229,7 +230,7 @@ class CreatePublishRoyalRenderJob(pyblish.api.InstancePlugin): SeqEnd=1, SeqStep=1, SeqFileOffset=0, - Version=os.environ.get("OPENPYPE_VERSION"), + Version=self._sanitize_version(os.environ.get("OPENPYPE_VERSION")), SceneName=abs_metadata_path, # command line arguments CustomAddCmdFlags=" ".join(args), @@ -256,3 +257,26 @@ class CreatePublishRoyalRenderJob(pyblish.api.InstancePlugin): 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"(?P0|[1-9]\d*)" + r"\.(?P0|[1-9]\d*)" + r"\.(?P0|[1-9]\d*)" + r"(?:-(?P[a-zA-Z\d\-.]*))?" + r"(?:\+(?P[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)