|
19 | 19 | from ..pipelineconfig import PipelineConfiguration |
20 | 20 | from .. import LogManager |
21 | 21 | from ..errors import TankError |
22 | | -from ..util.version import is_version_older |
| 22 | +from ..util.version import is_version_older, is_version_head |
| 23 | +from ..platform.errors import TankEngineInitError |
23 | 24 |
|
24 | 25 | log = LogManager.get_logger(__name__) |
25 | 26 |
|
@@ -921,39 +922,78 @@ def _start_engine(self, tk, engine_name, entity, progress_callback=None): |
921 | 922 |
|
922 | 923 | # perform absolute import to ensure we get the new swapped core. |
923 | 924 | import tank |
| 925 | + is_shotgun_engine = engine_name == constants.SHOTGUN_ENGINE_NAME |
924 | 926 |
|
925 | 927 | # handle legacy cases |
926 | | - if engine_name == constants.SHOTGUN_ENGINE_NAME and is_version_older(tk.version, "v0.18.77"): |
927 | | - |
928 | | - # bootstrapping into a shotgun engine with an older core |
929 | | - # we perform this special check to make sure that we correctly pick up |
930 | | - # the shotgun_xxx.yml environment files, even for older cores. |
931 | | - # new cores handles all this inside the tank.platform.start_shotgun_engine |
932 | | - # business logic. |
933 | | - log.debug( |
934 | | - "Target core version is %s. Starting shotgun engine via legacy pathway." % tk.version |
935 | | - ) |
936 | | - |
937 | | - if entity is None: |
938 | | - raise TankBootstrapError( |
939 | | - "Legacy shotgun environments do not support bootstrapping into a site context." |
940 | | - ) |
941 | | - |
942 | | - # start engine via legacy pathway |
943 | | - # note the local import due to core swapping. |
944 | | - from tank.platform import engine |
945 | | - engine = engine.start_shotgun_engine(tk, entity["type"], ctx) |
946 | | - |
| 928 | + if is_shotgun_engine and is_version_older(tk.version, "v0.18.77"): |
| 929 | + engine = self._legacy_start_shotgun_engine(tk, engine_name, entity, ctx) |
947 | 930 | else: |
948 | 931 | # no legacy cases |
949 | | - engine = tank.platform.start_engine(engine_name, tk, ctx) |
| 932 | + try: |
| 933 | + engine = tank.platform.start_engine(engine_name, tk, ctx) |
| 934 | + except TankEngineInitError as exc: |
| 935 | + # It's possible that a tk-core is being used that didn't come from |
| 936 | + # the app_store. This might be the case where a site config has been |
| 937 | + # locked off, and populated with a tk-core cloned from Github. In that |
| 938 | + # case, it'll have "HEAD" as its version. In that situation, we don't |
| 939 | + # actually know if this is a "new" core, or something super old. Given |
| 940 | + # that, we need to try going the legacy route here just to see if we |
| 941 | + # might actually have an old core. |
| 942 | + if is_version_head(tk.version) and is_shotgun_engine: |
| 943 | + try: |
| 944 | + engine = self._legacy_start_shotgun_engine(tk, engine_name, entity, ctx) |
| 945 | + except Exception: |
| 946 | + # We'll want to raise the original exception here. We don't |
| 947 | + # really know whether this is a legacy core or not, so if both |
| 948 | + # the legacy and new code paths failed, we'll raise the exception |
| 949 | + # from the new code path. |
| 950 | + log.warning( |
| 951 | + "Attempted legacy engine start path for Shotgun engine, which failed. " |
| 952 | + "This attempt was made because the tk-core version is HEAD, which means " |
| 953 | + "we don't know if it's new or old. As such, when the new-style bootstrap " |
| 954 | + "failed, the legacy pathway was attempted." |
| 955 | + ) |
| 956 | + raise exc |
| 957 | + else: |
| 958 | + # In this case, we know we're in a new enough core, but that we |
| 959 | + # just failed for some legitimate reason. |
| 960 | + raise exc |
950 | 961 |
|
951 | 962 | log.debug("Launched engine %r" % engine) |
952 | 963 |
|
953 | 964 | self._report_progress(progress_callback, self._BOOTSTRAP_COMPLETED, "Engine launched.") |
954 | 965 |
|
955 | 966 | return engine |
956 | 967 |
|
| 968 | + def _legacy_start_shotgun_engine(self, tk, engine_name, entity, ctx): |
| 969 | + """ |
| 970 | + Starts the tk-shotgun engine by way of the legacy "start_shotgun_engine" |
| 971 | + method provided by tank.platform.engine. |
| 972 | +
|
| 973 | + :param tk: Bootstrapped :class:`~sgtk.Sgtk` instance. |
| 974 | + :param engine_name: Name of the engine to start up. |
| 975 | + :param entity: Shotgun entity used to resolve a project context. |
| 976 | + :type entity: Dictionary with keys ``type`` and ``id``, or ``None`` for the site. |
| 977 | + """ |
| 978 | + # bootstrapping into a shotgun engine with an older core |
| 979 | + # we perform this special check to make sure that we correctly pick up |
| 980 | + # the shotgun_xxx.yml environment files, even for older cores. |
| 981 | + # new cores handles all this inside the tank.platform.start_shotgun_engine |
| 982 | + # business logic. |
| 983 | + log.debug( |
| 984 | + "Target core version is %s. Starting shotgun engine via legacy pathway." % tk.version |
| 985 | + ) |
| 986 | + |
| 987 | + if entity is None: |
| 988 | + raise TankBootstrapError( |
| 989 | + "Legacy shotgun environments do not support bootstrapping into a site context." |
| 990 | + ) |
| 991 | + |
| 992 | + # start engine via legacy pathway |
| 993 | + # note the local import due to core swapping. |
| 994 | + from tank.platform import engine |
| 995 | + return engine.start_shotgun_engine(tk, entity["type"], ctx) |
| 996 | + |
957 | 997 | def _report_progress(self, progress_callback, progress_value, message): |
958 | 998 | """ |
959 | 999 | Helper method that reports back on the bootstrap progress to a defined progress callback. |
|
0 commit comments