From 2d6cc7788199c26e338ab6e960aef1fc25caca9b Mon Sep 17 00:00:00 2001 From: Alexey Bogomolov Date: Tue, 21 Feb 2023 02:42:36 +0300 Subject: [PATCH] fle formatting --- .../hosts/fusion/hooks/pre_fusion_setup.py | 45 ++++++++++++------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/openpype/hosts/fusion/hooks/pre_fusion_setup.py b/openpype/hosts/fusion/hooks/pre_fusion_setup.py index 949f86d981..3f521bb60d 100644 --- a/openpype/hosts/fusion/hooks/pre_fusion_setup.py +++ b/openpype/hosts/fusion/hooks/pre_fusion_setup.py @@ -17,16 +17,16 @@ class FusionPrelaunch(PreLaunchHook): as set in openpype/hosts/fusion/deploy/fusion_shared.prefs to enable the OpenPype menu and force Python 3 over Python 2. - PROFILE_NUMBER is used because from the Fusion v16 the profile folder + PROFILE_NUMBER is used because from the Fusion v16 the profile folder is project-specific, but then it was abandoned by devs, and despite it is already Fusion version 18, still FUSION16_PROFILE_DIR is used. The variable is added in case the version number will be updated or deleted so we could easily change the version or disable it. """ + app_groups = ["fusion"] PROFILE_NUMBER = 16 - def get_fusion_profile_name(self) -> str: """usually set to 'Default', unless FUSION16_PROFILE is set""" return os.getenv(f"FUSION{self.PROFILE_NUMBER}_PROFILE", "Default") @@ -41,14 +41,18 @@ class FusionPrelaunch(PreLaunchHook): # if FUSION16_PROFILE_DIR variable exists if fusion_var_prefs_dir and Path(fusion_var_prefs_dir).is_dir(): fusion_prefs_dir = Path(fusion_var_prefs_dir, fusion_profile) - self.log.info(f"Local Fusion prefs environment is set to {fusion_prefs_dir}") + self.log.info( + f"Local Fusion prefs environment is set to {fusion_prefs_dir}" + ) return fusion_prefs_dir # otherwise get the profile folder from default location fusion_prefs_dir = f"Blackmagic Design/Fusion/Profiles/{fusion_profile}" if platform.system() == "Windows": prefs_source = Path(os.getenv("AppData"), fusion_prefs_dir) elif platform.system() == "Darwin": - prefs_source = Path("~/Library/Application Support/", fusion_prefs_dir).expanduser() + prefs_source = Path( + "~/Library/Application Support/", fusion_prefs_dir + ).expanduser() elif platform.system() == "Linux": prefs_source = Path("~/.fusion", fusion_prefs_dir).expanduser() self.log.info(f"Got Fusion prefs file: {prefs_source}") @@ -56,11 +60,8 @@ class FusionPrelaunch(PreLaunchHook): def get_copy_fusion_prefs_settings(self): """Get copy prefserences options from the global application settings""" - copy_fusion_settings = ( - self.data - ["project_settings"] - ["fusion"] - .get("copy_fusion_settings", {}) + copy_fusion_settings = self.data["project_settings"]["fusion"].get( + "copy_fusion_settings", {} ) if not copy_fusion_settings: self.log.error("Copy prefs settings not found") @@ -71,7 +72,9 @@ class FusionPrelaunch(PreLaunchHook): copy_path = Path(copy_path).expanduser() return copy_status, copy_path, force_sync - def copy_existing_prefs(self, copy_from: Path, copy_to: Path, force_sync: bool) -> None: + def copy_existing_prefs( + self, copy_from: Path, copy_to: Path, force_sync: bool + ) -> None: """On the first Fusion launch copy the contents of Fusion profile directory to the working predefined location. If the Openpype profile folder exists, skip copying, unless re-sync is checked. @@ -79,21 +82,25 @@ class FusionPrelaunch(PreLaunchHook): clean Fusion profile will be created in fusion_profile_dir. """ if copy_to.exists() and not force_sync: - self.log.info("Local Fusion preferences folder exists, skipping profile copy") + self.log.info( + "Local Fusion preferences folder exists, skipping profile copy" + ) return self.log.info(f"Starting copying Fusion preferences") self.log.info(f"force_sync option is set to {force_sync}") dest_folder = copy_to / self.get_fusion_profile_name() - dest_folder.mkdir(exist_ok=True, parents=True) + dest_folder.mkdir(exist_ok=True, parents=True) if not copy_from.exists(): self.log.warning(f"Fusion preferences file not found in {copy_from}") return for file in copy_from.iterdir(): if file.suffix in (".prefs", ".def", ".blocklist", "fu"): # convert Path to str to be compatible with Python 3.6 and above - shutil.copy(str(file), str(dest_folder)) - self.log.info(f"successfully copied preferences:\n {copy_from} to {dest_folder}") - + shutil.copy(str(file), str(dest_folder)) + self.log.info( + f"successfully copied preferences:\n {copy_from} to {dest_folder}" + ) + def execute(self): # making sure python 3 is installed at provided path # Py 3.3-3.10 for Fusion 18+ or Py 3.6 for Fu 16-17 @@ -102,7 +109,7 @@ class FusionPrelaunch(PreLaunchHook): fusion_python3_home = self.launch_context.env.get(py3_var, "") for path in fusion_python3_home.split(os.pathsep): - # Allow defining multiple paths, separated by os.pathsep, + # Allow defining multiple paths, separated by os.pathsep, # to allow "fallback" to other path. # But make to set only a single path as final variable. py3_dir = os.path.normpath(path) @@ -135,7 +142,11 @@ class FusionPrelaunch(PreLaunchHook): self.log.info(f"Setting OPENPYPE_FUSION: {FUSION_HOST_DIR}") self.launch_context.env["OPENPYPE_FUSION"] = FUSION_HOST_DIR - copy_status, fusion_profile_dir, force_sync = self.get_copy_fusion_prefs_settings() + ( + copy_status, + fusion_profile_dir, + force_sync, + ) = self.get_copy_fusion_prefs_settings() if copy_status: prefs_source = self.get_profile_source() self.copy_existing_prefs(prefs_source, fusion_profile_dir, force_sync)