def get_global_environments(env=None): """Load global environments from Pype. Return prepared and parsed global environments by pype's settings. Use combination of "global" environments set in pype's settings and enabled modules. Args: env (dict, optional): Initial environments. Empty dictionary is used when not entered. Returns; dict of str: Loaded and processed environments. """ import acre from openpype.modules import ModulesManager if env is None: env = {} # Get global environments from settings all_settings_env = get_environments() parsed_global_env = acre.parse(all_settings_env["global"]) # Merge with entered environments merged_env = acre.append(env, parsed_global_env) # Get environments from Pype modules modules_manager = ModulesManager() module_envs = modules_manager.collect_global_environments() publish_plugin_dirs = modules_manager.collect_plugin_paths()["publish"] # Set pyblish plugins paths if any module want to register them if publish_plugin_dirs: publish_paths_str = os.environ.get("PYBLISHPLUGINPATH") or "" publish_paths = publish_paths_str.split(os.pathsep) _publish_paths = { os.path.normpath(path) for path in publish_paths if path } for path in publish_plugin_dirs: _publish_paths.add(os.path.normpath(path)) module_envs["PYBLISHPLUGINPATH"] = os.pathsep.join(_publish_paths) # Merge environments with current environments and update values if module_envs: parsed_envs = acre.parse(module_envs) merged_env = acre.merge(parsed_envs, merged_env) return acre.compute(merged_env, cleanup=True)
def apply_project_environments_value(project_name, env, project_settings=None): """Apply project specific environments on passed environments. Args: project_name (str): Name of project for which environemnts should be received. env (dict): Environment values on which project specific environments will be applied. project_settings (dict): Project settings for passed project name. Optional if project settings are already prepared. Raises: KeyError: If project settings do not contain keys for project specific environments. """ import acre if project_settings is None: project_settings = get_project_settings(project_name) env_value = project_settings["global"]["project_environments"] if not env_value: return env parsed = acre.parse(env_value) return _merge_env(parsed, env)
def set_modules_environments(): """Set global environments for pype modules. This requires to have pype in `sys.path`. """ from pype.modules import ModulesManager import acre modules_manager = ModulesManager() module_envs = modules_manager.collect_global_environments() publish_plugin_dirs = modules_manager.collect_plugin_paths()["publish"] # Set pyblish plugins paths if any module want to register them if publish_plugin_dirs: publish_paths_str = os.environ.get("PYBLISHPLUGINPATH") or "" publish_paths = publish_paths_str.split(os.pathsep) _publish_paths = { os.path.normpath(path) for path in publish_paths if path } for path in publish_plugin_dirs: _publish_paths.add(os.path.normpath(path)) module_envs["PYBLISHPLUGINPATH"] = os.pathsep.join(_publish_paths) # Merge environments with current environments and update values if module_envs: parsed_envs = acre.parse(module_envs) env = acre.merge(parsed_envs, dict(os.environ)) os.environ.clear() os.environ.update(env)
def prepare_host_environments(data): """Modify launch environments based on launched app and context. Args: data (EnvironmentPrepData): Dictionary where result and intermediate result will be stored. """ import acre app = data["app"] log = data["log"] # `added_env_keys` has debug purpose added_env_keys = {app.group.name, app.name} # Environments for application environments = [app.group.environment, app.environment] asset_doc = data.get("asset_doc") # Add tools environments groups_by_name = {} tool_by_group_name = collections.defaultdict(list) if asset_doc: # Make sure each tool group can be added only once for key in asset_doc["data"].get("tools_env") or []: tool = app.manager.tools.get(key) if not tool: continue groups_by_name[tool.group.name] = tool.group tool_by_group_name[tool.group.name].append(tool) for group_name, group in groups_by_name.items(): environments.append(group.environment) added_env_keys.add(group_name) for tool in tool_by_group_name[group_name]: environments.append(tool.environment) added_env_keys.add(tool.name) log.debug("Will add environments for apps and tools: {}".format( ", ".join(added_env_keys))) env_values = {} for _env_values in environments: if not _env_values: continue # Choose right platform tool_env = acre.parse(_env_values) # Merge dictionaries env_values = _merge_env(tool_env, env_values) final_env = _merge_env(acre.compute(env_values), data["env"]) # Update env data["env"].update(final_env)
def test_parse_platform(self): """Parse works for 'platform-specific environments'""" data = { "A": { "darwin": "darwin-path", "windows": "windows-path", "linux": "linux-path" }, "B": "universal" } result = acre.parse(data, platform_name="darwin") self.assertEqual(result["A"], data["A"]["darwin"]) self.assertEqual(result["B"], data["B"]) result = acre.parse(data, platform_name="windows") self.assertEqual(result["A"], data["A"]["windows"]) self.assertEqual(result["B"], data["B"]) result = acre.parse(data, platform_name="linux") self.assertEqual(result["A"], data["A"]["linux"]) self.assertEqual(result["B"], data["B"])
def set_pype_global_environments() -> None: """Set global pype's environments.""" import acre from pype.settings import get_environments all_env = get_environments() # TODO Global environments will be stored in "general" settings so loading # will be modified and can be done in igniter. env = acre.merge( acre.parse(all_env["global"]), dict(os.environ) ) os.environ.clear() os.environ.update(env) # Hardcoded default values os.environ["PYBLISH_GUI"] = "pyblish_pype" # Change scale factor only if is not set if "QT_AUTO_SCREEN_SCALE_FACTOR" not in os.environ: os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"