Change assertions to KnownPublishError

This commit is contained in:
Roy Nieterau 2023-04-05 23:26:54 +02:00
parent 096f913fe6
commit 7dc6158fb8

View file

@ -3,6 +3,7 @@ import pyblish.api
from openpype.lib import get_version_from_path
from openpype.tests.lib import is_in_tests
from openpype.pipeline import KnownPublishError
class CollectSceneVersion(pyblish.api.ContextPlugin):
@ -38,18 +39,24 @@ class CollectSceneVersion(pyblish.api.ContextPlugin):
if (
os.environ.get("HEADLESS_PUBLISH")
and not is_in_tests()
and context.data["hostName"] in self.skip_hosts_headless_publish):
and context.data["hostName"] in self.skip_hosts_headless_publish
):
self.log.debug("Skipping for headless publishing")
return
assert context.data.get('currentFile'), "Cannot get current file"
if not context.data.get('currentFile'):
raise KnownPublishError("Cannot get current workfile path. "
"Make sure your scene is saved.")
filename = os.path.basename(context.data.get('currentFile'))
if '<shell>' in filename:
return
version = get_version_from_path(filename)
assert version, "Cannot determine version"
if version is None:
raise KnownPublishError("Unable to retrieve version number from "
"filename: {}".format(filename))
rootVersion = int(version)
context.data['version'] = rootVersion