Fazil Topal
09/12/2024, 11:44 AMcredentials: openai
?Ian Whalen
09/12/2024, 12:25 PM.env
file with the dotenv
package.Ian Whalen
09/12/2024, 12:28 PMNok Lam Chan
09/12/2024, 12:59 PMFazil Topal
09/12/2024, 1:58 PMFazil Topal
09/12/2024, 3:03 PMlogger = get_logger(__name__)
class EnvHook:
@hook_impl
def after_catalog_created(self, *args, **kwargs) -> None:
""" User credentials.yml file over .env. If not found, fall back to .env """
creds = kwargs.get("conf_creds")
if creds is None:
load_dotenv()
else:
env = creds["envs"]
for k, v in env.items():
k = k.upper() # Convert envs to upper case if they are not already.
if k in os.environ:
logger.warn(f"Environment variable {k} is already set to {v}")
continue # In case env is already set don't touch it
if v is not None:
os.environ[k] = v
I have set it update in settings
from projx.hooks import EnvHook
# Hooks are executed in a Last-In-First-Out (LIFO) order.
HOOKS = (EnvHook(),)
Do we know why my hook don't get executed?Fazil Topal
09/12/2024, 3:04 PMJavier del Villar
09/12/2024, 3:10 PMNok Lam Chan
09/12/2024, 3:36 PMNok Lam Chan
09/12/2024, 3:37 PMconf_cred
explicitly as an argumentFazil Topal
09/12/2024, 3:37 PMFazil Topal
09/12/2024, 3:38 PMNok Lam Chan
09/12/2024, 3:39 PMHOOKS = (EnvHook(),)
Nok Lam Chan
09/12/2024, 3:42 PMFazil Topal
09/12/2024, 3:43 PMFazil Topal
09/13/2024, 9:40 AMconftest.py
@fixture(scope='session')
def kedro_context(config_loader):
return KedroContext(
package_name="projx",
project_path=PROJECT_PATH,
config_loader=config_loader,
hook_manager=_create_hook_manager(),
env="test"
)
test_run.py
def test_catalog_hook(kedro_context):
# Invoke catalog loading
catalog = kedro_context.catalog.list()
# By this time we should be running the catalog hook
print("stop")
hooks.py
class EnvHook:
@hook_impl
def after_catalog_created(self, *args, **kwargs) -> None:
""" User credentials.yml file over .env. If not found, fall back to .env """
print("Hello")
Trying this and debugger doesn't stop as hook code. I don't see print statements when i run as wellFazil Topal
09/13/2024, 9:46 AMFazil Topal
09/13/2024, 9:47 AMdef test_project_catalog(kedro_context, kedro_session):
# Invoke catalog parsing to see if there is a problem in the catalog
print(kedro_context.catalog.list())
kedro_session.load_context() # -> This invokes hooks
Fazil Topal
09/13/2024, 9:49 AMhook_manager = _create_hook_manager()
_register_hooks(hook_manager, settings.HOOKS)
_register_hooks_entry_points(hook_manager, settings.DISABLE_HOOKS_FOR_PLUGINS)
while during context creation i don't call the register hooks function which i assume ignores them all. Is there a reason why these functions are private?Fazil Topal
09/13/2024, 10:09 AMNok Lam Chan
09/13/2024, 11:03 AMFazil Topal
09/13/2024, 11:04 AMNok Lam Chan
09/13/2024, 11:05 AMNok Lam Chan
09/13/2024, 11:09 AMFazil Topal
09/13/2024, 11:56 AMFazil Topal
09/13/2024, 11:57 AM