From 025cf4e8cc2c9a2a075f02b5c0e3676d261f25c3 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 3 Dec 2020 11:23:30 +0100 Subject: [PATCH] added function to get current context project settings `get_current_project_settings` --- pype/api.py | 2 ++ pype/settings/__init__.py | 2 ++ pype/settings/lib.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/pype/api.py b/pype/api.py index 34e2c79845..3854da6d30 100644 --- a/pype/api.py +++ b/pype/api.py @@ -1,6 +1,7 @@ from .settings import ( get_system_settings, get_project_settings, + get_current_project_settings, get_anatomy_data, get_environments ) @@ -53,6 +54,7 @@ from .lib import _subprocess as subprocess __all__ = [ "get_system_settings", "get_project_settings", + "get_current_project_settings", "get_anatomy_data", "get_environments", diff --git a/pype/settings/__init__.py b/pype/settings/__init__.py index 2f487038bd..479236b99a 100644 --- a/pype/settings/__init__.py +++ b/pype/settings/__init__.py @@ -1,6 +1,7 @@ from .lib import ( get_system_settings, get_project_settings, + get_current_project_settings, get_anatomy_data, get_environments ) @@ -8,6 +9,7 @@ from .lib import ( __all__ = ( "get_system_settings", "get_project_settings", + "get_current_project_settings", "get_anatomy_data", "get_environments" ) diff --git a/pype/settings/lib.py b/pype/settings/lib.py index 0b830dd5ab..23e303556e 100644 --- a/pype/settings/lib.py +++ b/pype/settings/lib.py @@ -464,6 +464,22 @@ def get_project_settings(project_name): return apply_overrides(studio_overrides, project_overrides) +def get_current_project_settings(): + """Project settings for current context project. + + Project name should be stored in environment variable `AVALON_PROJECT`. + This function should be used only in host context where environment + variable must be set and should not happen that any part of process will + change the value of the enviornment variable. + """ + project_name = os.environ.get("AVALON_PROJECT") + if not project_name: + raise ValueError( + "Missing context project in environemt variable `AVALON_PROJECT`." + ) + return get_project_settings(project_name) + + def get_environments(): """Calculated environment based on defaults and system settings.