Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#29975 add app_path, app_args, version params to before_app_launch hook #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,21 @@ def launch_from_entity(self, version=None):

self._launch_app(self.context, version=version)

def _get_clean_version_string(self, version):
"""
Returns version string used for current app launch stripped of any ()'s defining
additional version tokens. For example, if the version setting is "(8.4)v6" this will
return "8.4v6"

:param version: version of the application being launched specified by the value from
'versions' settings. If no 'versions' were defined in the settings, then
this will be None.
"""
if version is None:
return version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor but I think this would be clearer if it was 'return None'

clean_version = re.sub('[()]', '', version)
return clean_version

def _translate_version_tokens(self, raw_string, version):
"""
Returns string with version tokens replaced by their values. Replaces
Expand All @@ -205,7 +220,7 @@ def _translate_version_tokens(self, raw_string, version):
# split version string into tokens defined by ()s
version_tokens = re.findall(r"\(([^\)]+)\)", version)
# ensure we have a clean complete version string without ()s
clean_version = re.sub('[()]', '', version)
clean_version = self._get_clean_version_string(version)
# do the substitution
string = raw_string.replace("{version}", clean_version)
for i, token in enumerate(version_tokens):
Expand All @@ -217,7 +232,7 @@ def _get_app_path(self, version=None):
platform_name = {"linux2": "linux", "darwin": "mac", "win32": "windows"}[sys.platform]
raw_app_path = self.get_setting("%s_path" % platform_name, "")
if version is None:
# there are two reasons version could be none
# there are two reasons version could be None
# the first is if versions have not been configured, in which case the raw path is valid
# if versions has been configured, then we should expand with the first element in the
# list, which will be treated as the default
Expand Down Expand Up @@ -308,9 +323,11 @@ def _launch_app_internal(self, context, file_to_open=None, version=None):
else:
(app_path, app_args) = self.prepare_generic_launch(engine_name, context, app_path, app_args)

version_string = self._get_clean_version_string(version)
# run before launch hook
self.log_debug("Running before launch hook...")
self.execute_hook("hook_before_app_launch")
self.log_debug("Running before app launch hook...")
self.execute_hook("hook_before_app_launch", app_path=app_path, app_args=app_args,
version=version_string)

# Ticket 26741: Avoid having odd DLL loading issues on windows
# Desktop PySide sets an explicit DLL path, which is getting inherited by subprocess.
Expand All @@ -320,7 +337,8 @@ def _launch_app_internal(self, context, file_to_open=None, version=None):
try:
# Launch the application
self.log_debug("Launching executable '%s' with args '%s'" % (app_path, app_args))
result = self.execute_hook("hook_app_launch", app_path=app_path, app_args=app_args)
result = self.execute_hook("hook_app_launch", app_path=app_path, app_args=app_args,
version=version_string)

cmd = result.get("command")
return_code = result.get("return_code")
Expand Down
4 changes: 3 additions & 1 deletion hooks/app_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class AppLaunch(tank.Hook):
Hook to run an application.
"""

def execute(self, app_path, app_args, **kwargs):
def execute(self, app_path, app_args, version, **kwargs):
"""
The execute functon of the hook will be called to start the required application

:param app_path: (str) The path of the application executable
:param app_args: (str) Any arguments the application may require
:param version: (str) version of the application being run if set in the "versions" settings
of the Launcher instance, otherwise None

:returns: (dict) The two valid keys are 'command' (str) and 'return_code' (int).
"""
Expand Down
10 changes: 8 additions & 2 deletions hooks/before_app_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ class BeforeAppLaunch(tank.Hook):
Hook to set up the system prior to app launch.
"""

def execute(self, **kwargs):
def execute(self, app_path, app_args, version, **kwargs):
"""
The execute functon of the hook will be called to start the required application
The execute functon of the hook will be called prior to starting the required application

:param app_path: (str) The path of the application executable
:param app_args: (str) Any arguments the application may require
:param version: (str) version of the application being run if set in the "versions" settings
of the Launcher instance, otherwise None

"""

# accessing the current context (current shot, etc)
Expand Down