-
Notifications
You must be signed in to change notification settings - Fork 313
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
Support for custom Jinja filters #477
Conversation
if hasattr(self, '_jinja_filters'): | ||
return self._jinja_filters | ||
# load jinja filters if not already cached | ||
env_var_name = 'SCEPTRE_JINJA_FILTER_ROOT' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be reaching env_vars directly, can we read this as environment config for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How exactly should that be done? Template()
seems to only be instantiated with with scepre_user_data
, not environment_config
. See also this related issue.
Does a path from environment_config or stack_config actually help here? I think what is really needed is the exact value passed from the CLI argument --dir
, because even given an environment or stack path, if env folders are nested then one couldn't be sure how far to go back up the directory tree to get to the sceptre root (i.e. the folder that holds config
, template
, hooks
, resolvers
, and by symmetry jinja_filters
).
msg = 'loading jinja filters from: {}' | ||
self.logger.debug(msg.format(filter_dir)) | ||
self._jinja_filters = {} | ||
for fpath in glob.glob(os.path.join(filter_dir, '*.py')): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally this would be done using entry points, as per the new hooks, resolves code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an example of that in v1, or would this need backport from v2?
Closing as won't support in v1. v1 EOL as of tomorrow. Would consider support for v2? |
Corresponding issue is here. Syndicating content: My use-case involves adding new custom Jinja filters into projects using the v1 releases of sceptre, which I haven't found a supported way to accomplish.
I think this should work in way similar to hooks/resolvers, i.e. loading this project-specific functionality from "jinja_filters" folder underneath the sceptre root.
This PoC here is rough but working. Mostly this approach feels bad because I can't see how to access any kind of global sceptre config to get at information like the --dir argument applied by the CLI. I've had to configure the directory for external jinja filters from an environment variable for now to work around this.
Obviously even if smoothed this pull would needs corresponding docs changes. Waiting for some guidance about how to move forward and whether/how this could be accepted into 1.x mainline (my org probably can't commit to v2 soon)