boa
boa copied to clipboard
environ not available in context
When trying to use boa with a recipe like
context:
version: "{{ environ.get('VERSION', '3.1.4') }}"
boa build fails with
Traceback (most recent call last):
File "/home/mvanniekerk/miniconda3/bin/boa", line 10, in <module>
sys.exit(main())
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/boa/cli/boa.py", line 131, in main
run_build(args)
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/boa/core/run_build.py", line 455, in run_build
all_recipes = find_all_recipes(args.target, config) # [noqa]
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/boa/core/run_build.py", line 50, in find_all_recipes
yml = render(fn, config=config)
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/boa/core/render.py", line 182, in render
context_dict[key] = tmpl.render(context_dict)
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 1090, in render
self.environment.handle_exception()
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 832, in handle_exception
reraise(*rewrite_traceback_stack(source=source))
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/jinja2/_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
File "/home/mvanniekerk/miniconda3/lib/python3.8/site-packages/jinja2/environment.py", line 471, in getattr
return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'environ' is undefined
I'm looking at ways to inject context variables (esp. the version) into my boa recipes and this would be very handy.
I'm currently doing a jinja2 pre-render to inject the context but it would be nice if I didn't have to and this seems like an easy solution
I'm not quite doing a jinja2 pre-render but i load the recipe.yaml with ruamel.yaml and setdefault into the context key
Maybe a CLI option would be a good alternative?
boa build --context "version=${VERSION}" .