Loader: Remove context argument from Loader.__init__() (#4602)

* Remove Loader `context` argument to __init__

* Add backwards compatibility for Loader.load by still setting `.fname` attr

* Refactor/remove usage of `self.fname` in loaders

* Fix some refactoring

* Fix some refactoring

* Hound

* Revert invalid refactor

* Fix refactor

* Fix playblast panel collection

* Refactor missing method

* Fix typo

* Use the correct `context`

---------

Co-authored-by: Toke Stuart Jepsen <tokejepsen@gmail.com>
Co-authored-by: Kayla Man <64118225+moonyuet@users.noreply.github.com>
Co-authored-by: Jakub Trllo <jakub.trllo@gmail.com>
This commit is contained in:
Roy Nieterau 2023-03-17 17:25:19 +01:00 committed by Jakub Trllo
parent 2fdb0ece6b
commit f58994d59c
99 changed files with 237 additions and 175 deletions

View file

@ -72,7 +72,7 @@ class LoadBackdropNodes(load.LoaderPlugin):
data_imprint.update({k: version_data[k]})
# getting file path
file = self.fname.replace("\\", "/")
file = self.filepath_from_context(context).replace("\\", "/")
# adding nodes to node graph
# just in case we are in group lets jump out of it

View file

@ -57,7 +57,7 @@ class AlembicCameraLoader(load.LoaderPlugin):
data_imprint.update({k: version_data[k]})
# getting file path
file = self.fname.replace("\\", "/")
file = self.filepath_from_context(context).replace("\\", "/")
with maintained_selection():
camera_node = nuke.createNode(

View file

@ -99,7 +99,8 @@ class LoadClip(plugin.NukeLoader):
representation = self._representation_with_hash_in_frame(
representation
)
filepath = get_representation_path(representation).replace("\\", "/")
filepath = self.filepath_from_context(context)
filepath = filepath.replace("\\", "/")
self.log.debug("_ filepath: {}".format(filepath))
start_at_workfile = options.get(
@ -154,7 +155,7 @@ class LoadClip(plugin.NukeLoader):
read_node["file"].setValue(filepath)
used_colorspace = self._set_colorspace(
read_node, version_data, representation["data"])
read_node, version_data, representation["data"], filepath)
self._set_range_to_node(read_node, first, last, start_at_workfile)
@ -306,8 +307,7 @@ class LoadClip(plugin.NukeLoader):
# we will switch off undo-ing
with viewer_update_and_undo_stop():
used_colorspace = self._set_colorspace(
read_node, version_data, representation["data"],
path=filepath)
read_node, version_data, representation["data"], filepath)
self._set_range_to_node(read_node, first, last, start_at_workfile)
@ -454,9 +454,9 @@ class LoadClip(plugin.NukeLoader):
return self.node_name_template.format(**name_data)
def _set_colorspace(self, node, version_data, repre_data, path=None):
def _set_colorspace(self, node, version_data, repre_data, path):
output_color = None
path = path or self.fname.replace("\\", "/")
path = path.replace("\\", "/")
# get colorspace
colorspace = repre_data.get("colorspace")
colorspace = colorspace or version_data.get("colorspace")

View file

@ -72,7 +72,7 @@ class LoadEffects(load.LoaderPlugin):
data_imprint.update({k: version_data[k]})
# getting file path
file = self.fname.replace("\\", "/")
file = self.filepath_from_context(context).replace("\\", "/")
# getting data from json file with unicode conversion
with open(file, "r") as f:

View file

@ -73,7 +73,7 @@ class LoadEffectsInputProcess(load.LoaderPlugin):
data_imprint.update({k: version_data[k]})
# getting file path
file = self.fname.replace("\\", "/")
file = self.filepath_from_context(context).replace("\\", "/")
# getting data from json file with unicode conversion
with open(file, "r") as f:

View file

@ -73,7 +73,7 @@ class LoadGizmo(load.LoaderPlugin):
data_imprint.update({k: version_data[k]})
# getting file path
file = self.fname.replace("\\", "/")
file = self.filepath_from_context(context).replace("\\", "/")
# adding nodes to node graph
# just in case we are in group lets jump out of it

View file

@ -75,7 +75,7 @@ class LoadGizmoInputProcess(load.LoaderPlugin):
data_imprint.update({k: version_data[k]})
# getting file path
file = self.fname.replace("\\", "/")
file = self.filepath_from_context(context).replace("\\", "/")
# adding nodes to node graph
# just in case we are in group lets jump out of it

View file

@ -86,7 +86,7 @@ class LoadImage(load.LoaderPlugin):
if namespace is None:
namespace = context['asset']['name']
file = self.fname
file = self.filepath_from_context(context)
if not file:
repr_id = context["representation"]["_id"]

View file

@ -18,8 +18,9 @@ class MatchmoveLoader(load.LoaderPlugin):
color = "orange"
def load(self, context, name, namespace, data):
if self.fname.lower().endswith(".py"):
exec(open(self.fname).read())
path = self.filepath_from_context(context)
if path.lower().endswith(".py"):
exec(open(path).read())
else:
msg = "Unsupported script type"

View file

@ -55,7 +55,7 @@ class AlembicModelLoader(load.LoaderPlugin):
data_imprint.update({k: version_data[k]})
# getting file path
file = self.fname.replace("\\", "/")
file = self.filepath_from_context(context).replace("\\", "/")
with maintained_selection():
model_node = nuke.createNode(

View file

@ -43,8 +43,8 @@ class LinkAsGroup(load.LoaderPlugin):
if namespace is None:
namespace = context['asset']['name']
file = self.fname.replace("\\", "/")
self.log.info("file: {}\n".format(self.fname))
file = self.filepath_from_context(context).replace("\\", "/")
self.log.info("file: {}\n".format(file))
precomp_name = context["representation"]["context"]["subset"]