-
Notifications
You must be signed in to change notification settings - Fork 910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to pass the env
to config loader since registration moved to settings.py
in 0.18.x
#1411
Comments
You're not missing anything: this is indeed no longer possible. I believe it's a deliberate casualty of moving library component customisation from registration hooks into settings.py. Similarly injecting credentials into There are two possible ways to do this now:
Personally I'm not a big fan either of these, and I think your idea of automatically including |
For the record, this would solve #506 which is currently broken since |
@AntonyMilneQB note that my current attempted workaround (similar to yours above) needs dynaconf.validator.ValidationError: Invalid value `semicon_forecast.config_loader.CustomTemplatedConfigLoader` received for setting `CONFIG_LOADER_CLASS`. It must be a subclass of `kedro.config.config.ConfigLoader`. my current approach is to class CustomTemplatedConfigLoader(TemplatedConfigLoader):
"""
A custom config loader that injects `env` as a globals value to be used in parameters files and nodes,
as well as any environment variable starting with KEDRO_
"""
def __init__(self, conf_source, env, runtime_params, **kwargs):
# grab parameters from env variables and add them to the config loader
# so that they can be used in the config files
# conf_paths = ["conf/base", f"conf/{env}", "conf/local"]
runtime_params = runtime_params or {}
env_params = self.get_kedro_parameters_from_env_variables()
globals_dict = {**env_params, **runtime_params, "env": env}
logging.info("using extra parameters")
logging.info(env_params)
super().__init__(
conf_source,
env,
runtime_params,
globals_pattern="*globals.yml",
globals_dict=globals_dict,
**kwargs,
)
def get_kedro_parameters_from_env_variables(self):
env_params = {
str.lower(k[len("KEDRO_") :]): os.environ.get(k)
for k in os.environ.keys()
if k.startswith("KEDRO_")
}
return env_params |
In this context, I also noticed that we changed the way that the
It used to be that you passed a list of config directories to the TemplatedConfigLoader, hence the commented out 3 paths above. kedro/kedro/config/templated_config.py Line 97 in 59bcb50
But now we just pass
and since
we don't look in
resolves the credentials.yml not found issue |
So I'd propose a PR with the following changes:
|
@pascalwhoop The validation error is definitely an unpleasant bug, sorry - see #1402 which includes a horrible hack workaround fix if you don't want to explicitly inherit from Regarding the Very small modification to your
(note that |
So overall I'd say, much as we appreciate PRs... 🙂
This is not such an easy fix for reasons I explained in #1402 and we're prioritising fixing it already so I'd leave it (or work out the best way to fix it for us 😀)
Personally I think this may well make sense, but I don't recommend doing a PR on it without gathering more opinions on it, since I know it has been considered and then rejected before.
Not sure I understand how this is distinct from the previous point?
💯% this would be good, as would pointing towards it in our migration guide given that this is not clearly spelt out anywhere. |
I'm closing this because we do have a method for passing |
Description
In 0.17.x we would register the config loader like so:
In 0.18.x we can register a configloader like this:
However we can no longer retrieve the runtime environment in this manner? (I may be missing something)
Context
When using
TemplatedConfigLoader
this is a common pattern to make sure paths are explicit.Possible solutions:
$kedro_env
in theglobals_dict
/self._config_mapping
namespace?KEDRO_ENV
environment variable, but it is a fragile solutionThe text was updated successfully, but these errors were encountered: