Syntax and usage of 'cylc view'

Hi there.

In cylc view how can I make it explicitly show all the files which are being included by e.g.

{% if TASK_RUN and TASK_TESTS %}
{% include “site/” \~ SITE \~“-tests.cylc” %}
{% endif %}

I see there is this option from cylc view -h

-l, --label (With ‘-i’) Label file inclusions with the file name.

But when I run this from my roses/[workflow] directory…

cylc view -il .

… It doesn’t seem to show me any ‘labels‘.

I’m using version 8.6.1 on ARCHER2 in the UK.

Thanks in advance for any tips!

Jonny

cylc view -p

-p, --process View after all processing (Jinja2, inlining, line-
continuation joining).

The -l won’t do anything without -i or -p, and only works for Cylc’s own %include directive, not to Jinja2 Includes:

# This text is in jinja2.include
#++++ START INLINED INCLUDE FILE cylc.include
# This text is in cylc.include
#++++ END INLINED INCLUDE FILE cylc.include
[scheduler]
    allow implicit tasks = True
[scheduling]
    [[graph]]
        R1 = foo

1 Like

Hi Tim.

Many thanks for this.

I think this is the key point that I hadn’t appreciated…

The -l … only works for Cylc’s own %include directive, not to Jinja2 Includes.

In essence I was looking for some indication that this had worked…

{% if TASK_RUN and TASK_TESTS %}
{% include "site/" ~ SITE ~"-tests.cylc" %}
{% endif %}

All the best.

Jonny

-p should work though!

Hi Tim.

I get nothing from this…

> cd ~/roses/[my workflow dir]
> cylc view -lp . | grep -i include

[no output]

I’ve checked and in my workflow there is a site/archer2.cylc file which is being successfully included.

I reckon I’m probably misunderstanding how this is supposed to work. What I’m naively expecting is some easy-to-spot indication - as mentioned above #++++ START INLINED INCLUDE FILE cylc.include - that the archer2.cylc has indeed been included (which it is).

Cheers.

Hi @jonnyhtwilliams !

I’m guessing that by " -p should work though!" @wxtim meant functionally (i.e. the file will be included), not that some indicator comment will be added as for native Cylc include file inlining mechanism.

Jinja2 includes are handled by the Jinja2 processor, so we don’t have control over the internals of that.

One thing you can do is add a Jinja2 print statement inside the Jinja2 include file, to print a Cylc comment (i.e. prefixed by # - so it doesn’t process to illegal Cylc syntax). Then if the file is included as you intend, the comment will appear in the processed flow.cylc.

{{ "# hello world!" }}

H

1 Like

@hilary.j.oliver - Why not just a comment without the jinja2?:slight_smile:

# Included file: site/esnz.cylc
[runtime]
  [[BIGTASK]]
    platform = big_machine
# END Include: site/esnz.cylc

I’m almost tempted to suggest that we should add this to the user guide

We recommend using Cylc native %%include directives becuase you can use cylc view -l to understand where included configuration came from. If you choose to use Jinja2 includes, we recommend that each include file should have a comment at the start and end of the file indicating that a file has been included.

Aha OK thanks @wxtim and @hilary.j.oliver!

Personally I think that advising a comment would be helpful but each to their own!

I put this at the start of the site/[site].cylc file and it works exactly as I want…

> cylc view  -p .|grep --context 1 INCLUDE

#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#
# INCLUDED FILE site/archer2.cylc
#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#/#

All the best.

Jonny

Ah, yes of course :man_facepalming: - the plain text within which the Jinja2 template code is embedded in gets printed verbatim (if not manipulated by the code).

Using a Jinja2 print statement is only needed if you want to print the value of a Jinja2 variable in a Cylc comment.

So the following will print # hello world three times into the flow.cylc:

{% set NAME = "world" %}
# hello world
# hello {{ NAME }}
{{ "# hello " + NAME }}