From 709d663870bb703d644ab0fdd8afc08da6c260c8 Mon Sep 17 00:00:00 2001 From: Kayla Man Date: Wed, 22 Feb 2023 21:47:32 +0800 Subject: [PATCH] update docstring and style fix --- openpype/hosts/maya/api/lib.py | 58 ++++++++++++------- .../maya/plugins/publish/extract_look.py | 8 +-- .../publish/validate_look_color_space.py | 3 +- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/openpype/hosts/maya/api/lib.py b/openpype/hosts/maya/api/lib.py index 88d3701966..e369b46525 100644 --- a/openpype/hosts/maya/api/lib.py +++ b/openpype/hosts/maya/api/lib.py @@ -16,7 +16,15 @@ from six import string_types from maya import cmds, mel import maya.api.OpenMaya as om -from arnold import * # noqa +from arnold import ( + AiTextureGetBitDepth, + AiTextureGetFormat, + AiTextureInvalidate, + # types + AI_TYPE_BYTE, + AI_TYPE_INT, + AI_TYPE_UINT +) from openpype.client import ( get_project, @@ -3465,19 +3473,23 @@ def write_xgen_file(data, filepath): f.writelines(lines) -def imageInfo(filepath): - """Take reference from makeTx.py in Arnold - ImageInfo(filename): Get Image Information for colorspace - AiTextureGetFormat(filename): Get Texture Format - AiTextureGetBitDepth(filename): Get Texture Bit Depth +def image_info(file_path): + # type: (str) -> dict + """Based on tha texture path, get its bit depth and format information. + Take reference from makeTx.py in Arnold: + ImageInfo(filename): Get Image Information for colorspace + AiTextureGetFormat(filename): Get Texture Format + AiTextureGetBitDepth(filename): Get Texture bit depth + Args: + file_path (str): Path to the texture file. + Returns: + dict: Dictionary with the information about the texture file. """ - # Get Texture Information - img_info = {} - img_info['filename'] = filepath - if os.path.isfile(filepath): - img_info['bit_depth'] = AiTextureGetBitDepth(filepath) # noqa - img_info['format'] = AiTextureGetFormat(filepath) # noqa + img_info = {'filename': file_path} + if os.path.isfile(file_path): + img_info['bit_depth'] = AiTextureGetBitDepth(file_path) # noqa + img_info['format'] = AiTextureGetFormat(file_path) # noqa else: img_info['bit_depth'] = 8 img_info['format'] = "unknown" @@ -3485,21 +3497,25 @@ def imageInfo(filepath): def guess_colorspace(img_info): - ''' Take reference from makeTx.py - Guess the colorspace of the input image filename. - @return: a string suitable for the --colorconvert - option of maketx (linear, sRGB, Rec709) - ''' + # type: (dict) -> str + """Guess the colorspace of the input image filename. + Note: + Reference from makeTx.py + Args: + img_info (dict): Image info generated by :func:`image_info` + Returns: + str: color space name use in the `--colorconvert` + option of maketx. + """ try: if img_info['bit_depth'] <= 16: if img_info['format'] in (AI_TYPE_BYTE, AI_TYPE_INT, AI_TYPE_UINT): # noqa return 'sRGB' else: return 'linear' - # now discard the image file as AiTextureGetFormat has loaded it AiTextureInvalidate(img_info['filename']) # noqa except ValueError: - print('[maketx] Error: Could not guess' - 'colorspace for "%s"' % img_info['filename']) - return 'linear' + print(("[maketx] Error: Could not guess" + "colorspace for {}").format(img_info["filename"])) + return "linear" diff --git a/openpype/hosts/maya/plugins/publish/extract_look.py b/openpype/hosts/maya/plugins/publish/extract_look.py index 46f7b0e03d..d9c19c9139 100644 --- a/openpype/hosts/maya/plugins/publish/extract_look.py +++ b/openpype/hosts/maya/plugins/publish/extract_look.py @@ -16,7 +16,7 @@ import pyblish.api from openpype.lib import source_hash, run_subprocess from openpype.pipeline import legacy_io, publish from openpype.hosts.maya.api import lib -from openpype.hosts.maya.api.lib import imageInfo, guess_colorspace +from openpype.hosts.maya.api.lib import image_info, guess_colorspace # Modes for transfer COPY = 1 @@ -369,7 +369,7 @@ class ExtractLook(publish.Extractor): linearize = False # if OCIO color management enabled - # it wont take the condition of the files_metadata + # it won't take the condition of the files_metadata ocio_maya = cmds.colorManagementPrefs(q=True, cmConfigFileEnabled=True, @@ -542,14 +542,14 @@ class ExtractLook(publish.Extractor): color_space = cmds.getAttr(color_space_attr) except ValueError: # node doesn't have color space attribute - img_info = imageInfo(filepath) + img_info = image_info(filepath) color_space = guess_colorspace(img_info) self.log.info("tx: converting {0} -> {1}".format(color_space, render_colorspace)) # noqa additional_args.extend(["--colorconvert", color_space, render_colorspace]) else: - img_info = imageInfo(filepath) + img_info = image_info(filepath) color_space = guess_colorspace(img_info) if color_space == "sRGB": self.log.info("tx: converting sRGB -> linear") diff --git a/openpype/hosts/maya/plugins/publish/validate_look_color_space.py b/openpype/hosts/maya/plugins/publish/validate_look_color_space.py index b354d51fef..b1bdeb7541 100644 --- a/openpype/hosts/maya/plugins/publish/validate_look_color_space.py +++ b/openpype/hosts/maya/plugins/publish/validate_look_color_space.py @@ -2,6 +2,7 @@ from maya import cmds import pyblish.api from openpype.pipeline.publish import ValidateContentsOrder +from openpype.pipeline import PublishValidationError class ValidateMayaColorSpace(pyblish.api.InstancePlugin): @@ -22,4 +23,4 @@ class ValidateMayaColorSpace(pyblish.api.InstancePlugin): maketx = instance.data["maketx"] if ocio_maya and maketx: - raise RuntimeError("Maya is color managed and maketx option is on. OpenPype doesn't support this combination yet.") # noqa + raise PublishValidationError("Maya is color managed and maketx option is on. OpenPype doesn't support this combination yet.") # noqa