From 1e1209c2025b5c1a34259140b5e4affbf04f0d63 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 25 May 2021 08:13:58 +0000 Subject: [PATCH 01/10] Create draft PR for #1575 From f3cbc1550afd6fd7d5054127f6b172a480da60fd Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 25 May 2021 10:15:31 +0200 Subject: [PATCH 02/10] added global prelaunch hook for mac prepending `open -an` arguments --- openpype/hooks/pre_mac_launch.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 openpype/hooks/pre_mac_launch.py diff --git a/openpype/hooks/pre_mac_launch.py b/openpype/hooks/pre_mac_launch.py new file mode 100644 index 0000000000..be4aa9839c --- /dev/null +++ b/openpype/hooks/pre_mac_launch.py @@ -0,0 +1,18 @@ +from openpype.lib import PreLaunchHook + + +class LaunchWithTerminal(PreLaunchHook): + """Mac specific pre arguments for application. + + Mac applications should be launched using "open" argument which is internal + callbacks to open executable. We also add argument "-an" to create new + process. This is used only for executables ending with ".app". It is + expected that these executables lead to app packages. + """ + order = 1000 + + platforms = ["darwin"] + + def execute(self): + if self.launch_context.executable.endswith(".app"): + self.launch_context.launch_args.insert(0, ["open", "-an"]) From e433f17c29dd786d97798afa85f36808f3c3ad53 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 25 May 2021 10:21:14 +0200 Subject: [PATCH 03/10] added more specific logic --- openpype/hooks/pre_mac_launch.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openpype/hooks/pre_mac_launch.py b/openpype/hooks/pre_mac_launch.py index be4aa9839c..63ebcbfa43 100644 --- a/openpype/hooks/pre_mac_launch.py +++ b/openpype/hooks/pre_mac_launch.py @@ -14,5 +14,14 @@ class LaunchWithTerminal(PreLaunchHook): platforms = ["darwin"] def execute(self): - if self.launch_context.executable.endswith(".app"): + executable = self.launch_context.executable + # Skip executables not starting with ".app" + if not executable.endswith(".app"): + return + + # Check if first argument match executable path + # - Few applications are not executed directly but through OpenPype + # process (Photoshop, AfterEffects, Harmony, ...). These should not + # use `open -an`. + if self.launch_context.launch_args[0] == executable: self.launch_context.launch_args.insert(0, ["open", "-an"]) From 7ea0e8210395dec4bf893e13e9e66340134823bd Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 25 May 2021 11:15:57 +0200 Subject: [PATCH 04/10] added isdir check --- openpype/hooks/pre_mac_launch.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openpype/hooks/pre_mac_launch.py b/openpype/hooks/pre_mac_launch.py index 63ebcbfa43..3c00177680 100644 --- a/openpype/hooks/pre_mac_launch.py +++ b/openpype/hooks/pre_mac_launch.py @@ -1,3 +1,4 @@ +import os from openpype.lib import PreLaunchHook @@ -15,8 +16,8 @@ class LaunchWithTerminal(PreLaunchHook): def execute(self): executable = self.launch_context.executable - # Skip executables not starting with ".app" - if not executable.endswith(".app"): + # Skip executables not ending with ".app" or that are not folder + if not executable.endswith(".app") or not os.path.isdir(executable): return # Check if first argument match executable path From b8ef1abca007fdd5619254c630c284776456208c Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 25 May 2021 16:53:53 +0200 Subject: [PATCH 05/10] fix executable type --- openpype/hooks/pre_mac_launch.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hooks/pre_mac_launch.py b/openpype/hooks/pre_mac_launch.py index 3c00177680..db4c7858c7 100644 --- a/openpype/hooks/pre_mac_launch.py +++ b/openpype/hooks/pre_mac_launch.py @@ -15,7 +15,7 @@ class LaunchWithTerminal(PreLaunchHook): platforms = ["darwin"] def execute(self): - executable = self.launch_context.executable + executable = str(self.launch_context.executable) # Skip executables not ending with ".app" or that are not folder if not executable.endswith(".app") or not os.path.isdir(executable): return From d571487fcd6efb9c8c98bc33e6a14de105968582 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 26 May 2021 10:54:21 +0200 Subject: [PATCH 06/10] reversed condition logic --- openpype/hooks/pre_mac_launch.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/openpype/hooks/pre_mac_launch.py b/openpype/hooks/pre_mac_launch.py index db4c7858c7..e0c3133556 100644 --- a/openpype/hooks/pre_mac_launch.py +++ b/openpype/hooks/pre_mac_launch.py @@ -23,6 +23,9 @@ class LaunchWithTerminal(PreLaunchHook): # Check if first argument match executable path # - Few applications are not executed directly but through OpenPype # process (Photoshop, AfterEffects, Harmony, ...). These should not - # use `open -an`. - if self.launch_context.launch_args[0] == executable: - self.launch_context.launch_args.insert(0, ["open", "-an"]) + # use `open`. + if self.launch_context.launch_args[0] != executable: + return + + # Prepend open arguments + self.launch_context.launch_args.insert(0, ["open", "-a"]) From 221f60bb23364f46a2bb9e2a6443c449e57d9831 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 26 May 2021 10:54:39 +0200 Subject: [PATCH 07/10] pass --args to tell which ards should be passed --- openpype/hooks/pre_mac_launch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/openpype/hooks/pre_mac_launch.py b/openpype/hooks/pre_mac_launch.py index e0c3133556..9fd3e94aa8 100644 --- a/openpype/hooks/pre_mac_launch.py +++ b/openpype/hooks/pre_mac_launch.py @@ -27,5 +27,8 @@ class LaunchWithTerminal(PreLaunchHook): if self.launch_context.launch_args[0] != executable: return + # Tell `open` to pass arguments if there are any + if len(self.launch_context.launch_args) > 1: + self.launch_context.launch_args.insert(1, "--args") # Prepend open arguments self.launch_context.launch_args.insert(0, ["open", "-a"]) From 61e10a4fc498691ac5e65c04bca0cf251d38823a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 26 May 2021 10:54:54 +0200 Subject: [PATCH 08/10] modified docstring to match changes --- openpype/hooks/pre_mac_launch.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openpype/hooks/pre_mac_launch.py b/openpype/hooks/pre_mac_launch.py index 9fd3e94aa8..3f07ae07db 100644 --- a/openpype/hooks/pre_mac_launch.py +++ b/openpype/hooks/pre_mac_launch.py @@ -6,9 +6,9 @@ class LaunchWithTerminal(PreLaunchHook): """Mac specific pre arguments for application. Mac applications should be launched using "open" argument which is internal - callbacks to open executable. We also add argument "-an" to create new - process. This is used only for executables ending with ".app". It is - expected that these executables lead to app packages. + callbacks to open executable. We also add argument "-a" to tell it's + application open. This is used only for executables ending with ".app". It + is expected that these executables lead to app packages. """ order = 1000 From a6d7e89d97a1a5a510a2e5fe023eae78b40d4347 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 26 May 2021 10:55:35 +0200 Subject: [PATCH 09/10] ApplicationExecutable check if there is .app in passed path if does not exists on mac --- openpype/lib/applications.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index a44c43102f..d7674d64ad 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -440,7 +440,20 @@ class EnvironmentTool: class ApplicationExecutable: + """Representation of executable loaded from settings.""" + def __init__(self, executable): + # On MacOS check if exists path to executable when ends with `.app` + # - it is common that path will lead to "/Applications/Blender" but + # real path is "/Applications/Blender.app" + if ( + platform.system().lower() == "darwin" + and not os.path.exists(executable) + ): + _executable = executable + ".app" + if os.path.exists(_executable): + executable = _executable + self.executable_path = executable def __str__(self): From 77830ecb006616b1d46fc3826ee7248e3714d9fb Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 26 May 2021 13:06:47 +0200 Subject: [PATCH 10/10] separated catch error of filling workdir template and creating workdir on disk --- openpype/lib/applications.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index d7674d64ad..d82b7cd847 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -1190,17 +1190,23 @@ def prepare_context_environments(data): try: workdir = get_workdir_with_workdir_data(workdir_data, anatomy) - if not os.path.exists(workdir): - log.debug( - "Creating workdir folder: \"{}\"".format(workdir) - ) - os.makedirs(workdir) except Exception as exc: raise ApplicationLaunchFailed( "Error in anatomy.format: {}".format(str(exc)) ) + if not os.path.exists(workdir): + log.debug( + "Creating workdir folder: \"{}\"".format(workdir) + ) + try: + os.makedirs(workdir) + except Exception as exc: + raise ApplicationLaunchFailed( + "Couldn't create workdir because: {}".format(str(exc)) + ) + context_env = { "AVALON_PROJECT": project_doc["name"], "AVALON_ASSET": asset_doc["name"],