diff --git a/cylc/flow/parsec/jinja2support.py b/cylc/flow/parsec/jinja2support.py index 5a39dbd01fe..cd1e0a766a7 100644 --- a/cylc/flow/parsec/jinja2support.py +++ b/cylc/flow/parsec/jinja2support.py @@ -186,11 +186,17 @@ def jinja2environment(dir_=None): envnsp[fname] = getattr(module, fname) # Import WORKFLOW HOST USER ENVIRONMENT into template: - # (usage e.g.: {{environ['HOME']}}). + # (Usage e.g.: {{environ['HOME']}}). env.globals['environ'] = os.environ + env.globals['raise'] = raise_helper env.globals['assert'] = assert_helper + # And all `CYLC_` variables (this will include CYLC_WORKFLOW environment + # variables exported by `cylc` commands before config file parsing. + for key, val in os.environ.items(): + if key.startswith('CYLC_'): + env.globals[key] = val return env diff --git a/cylc/flow/scripts/view.py b/cylc/flow/scripts/view.py index 423480cc20f..5e69c86a5ee 100644 --- a/cylc/flow/scripts/view.py +++ b/cylc/flow/scripts/view.py @@ -18,11 +18,16 @@ """cylc view [OPTIONS] ARGS -Print a processed workflow configuration. +Print workflow configurations as processed before full parsing by Cylc. This +includes Jinja2 or Empy template processing, and inlining of include-files. +Some explanatory markup may also be requested. + +Warning: this command will fail if Jinja2 `CYLC_` variables are referenced +without default values, because they are only defined during full parsing. +E.g., `{{CYLC_WORKFLOW_NAME | default("not defined")}}`. + +See also `cylc config`, which displays the fully parsed configuration. -Note: - This is different to `cylc config` which displays the parsed - configuration (as Cylc would see it). """ import asyncio @@ -116,20 +121,24 @@ async def _main(options: 'Values', workflow_id: str) -> None: ) # read in the flow.cylc file - viewcfg = { - 'mark': options.mark, - 'single': options.single, - 'label': options.label, - 'empy': options.empy or options.process, - 'jinja2': options.jinja2 or options.process, - 'contin': options.cat or options.process, - 'inline': (options.inline or options.jinja2 or options.empy - or options.process), - } for line in read_and_proc( flow_file, - load_template_vars(options.templatevars, options.templatevars_file), - viewcfg=viewcfg, + load_template_vars( + options.templatevars, + options.templatevars_file + ), + viewcfg={ + 'mark': options.mark, + 'single': options.single, + 'label': options.label, + 'empy': options.empy or options.process, + 'jinja2': options.jinja2 or options.process, + 'contin': options.cat or options.process, + 'inline': ( + options.jinja2 or options.empy or + options.inline or options.process + ), + }, opts=options, ): print(line)