Skip to content

Raise an error if template variables are set with no shebang#6948

Closed
wxtim wants to merge 6 commits intocylc:8.5.xfrom
wxtim:fix.template-vars-no-shebang
Closed

Raise an error if template variables are set with no shebang#6948
wxtim wants to merge 6 commits intocylc:8.5.xfrom
wxtim:fix.template-vars-no-shebang

Conversation

@wxtim
Copy link
Copy Markdown
Member

@wxtim wxtim commented Aug 28, 2025

line in the flow.cylc.

Fixes an otherwise unreported bug.

Real world example of bug:

#!/bin/bash
TMP=$(mktemp -d)
echo Files extracted to ${TMP}
mkdir -p "${TMP}/."

cat > "${TMP}/./flow.cylc" <<__ICI__
[scheduler]
    allow implicit tasks = true

[scheduling]
    initial cycle point = {{ STARTDATE }}T0000Z

    [[graph]]
        P1M = foo

__ICI__

cat > "${TMP}/./rose-suite.conf" <<__ICI__
[template variables]
STARTDATE="20000101"

__ICI__

cylc val ${TMP}
# .... lots of traceback

Check List

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Applied any dependency changes to both setup.cfg (and conda-environment.yml if present).
  • Tests are included (or explain why tests are not needed).
  • Changelog entry included if this is a change that can affect users
  • Cylc-Doc pull request opened if required at cylc/cylc-doc/pull/XXXX.
  • If this is a bug fix, PR should be raised against the relevant ?.?.x branch.

@wxtim wxtim added this to the 8.5.2 milestone Aug 28, 2025
@wxtim wxtim force-pushed the fix.template-vars-no-shebang branch from 3b4b88d to 58b6cdb Compare August 28, 2025 13:25
@wxtim wxtim force-pushed the fix.template-vars-no-shebang branch 2 times, most recently from c236a30 to 7de3421 Compare August 28, 2025 14:15
but no shebang line is set in the flow.cylc.
@wxtim wxtim force-pushed the fix.template-vars-no-shebang branch from 7de3421 to 85d9252 Compare August 28, 2025 14:18
Copy link
Copy Markdown
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is overzealous for this example:

# ./flow.cylc
[scheduling]
  [[graph]]
    R1 = foo

[runtime]
  [[foo]]

# ./rose-suite.conf
[env]
FOO=bar
$ cylc val . -s FOO=1
TemplateVarLanguageClash: No shebang line (#!jinja2) in config file.

But underzealous for this one

# ./flow.cylc
[scheduling]
  [[graph]]
    R1 = foo

[runtime]
  [[foo]]
$ cylc val . -s FOO=1
Valid for cylc-8.5.2.dev

TEMPLATE_VARIABLES: {},
TEMPLATING_DETECTED: None
}
JINJA2_SHEBANG = '#!jinja2'
Copy link
Copy Markdown
Member

@hjoliver hjoliver Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note we allow #!Jinja2 (capitalized) as well... but this is just for insertion, not detection?

Copy link
Copy Markdown
Member Author

@wxtim wxtim Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where it's used for detection it'd be used with JINJA2_SHEBANG = var.lower()

Correction: It's a regex

@wxtim wxtim marked this pull request as draft September 1, 2025 09:02
@wxtim
Copy link
Copy Markdown
Member Author

wxtim commented Sep 1, 2025

Converted to draft.

@MetRonnie MetRonnie removed their request for review September 1, 2025 14:45
@wxtim
Copy link
Copy Markdown
Member Author

wxtim commented Sep 2, 2025

I'm slightly worried that this has the potential to throw out a lot of valid workflows, just because they have a rose-suite.conf. Perhaps it should be a warning with a plan to make an error in future?

@oliver-sanders what think you?

@oliver-sanders
Copy link
Copy Markdown
Member

@oliver-sanders what think you?

This isn't a biggie, I'm not too concerned.

We shouldn't add a check which has the potential to fail, so if there ain't a good way to do it, let's not do it.

@MetRonnie MetRonnie modified the milestones: 8.5.2, 8.5.x Sep 3, 2025
@wxtim wxtim marked this pull request as ready for review September 3, 2025 11:44
@@ -1,3 +1,4 @@
#!jinja2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

This config doesn't use Jinja2!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But template variables are supplied - looks like there's vestigial garbage in the test.

flines = jinja2process(
fpath, flines, fdir, template_vars
)
elif template_vars.keys() - {"CYLC_VERSION", "CYLC_TEMPLATE_VARS"}:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does cylc-rose provide default template vars even if templating was not configured?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you turn Cylc Rose on it provides template variables. You turn it on by adding a blank rose-suite.conf.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So adding a rose-suite.conf file will force the user to add a Jinja2 shebang line, even if they are not using Jinja2 in the config?

Copy link
Copy Markdown
Member Author

@wxtim wxtim Sep 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a simple/sane* way around that. If you think that's a deal breaker IMO we just call this PR off. It's too small an issue for me to spend much more time on it.

* Non simple ways

  • with supress: from cylc.rose.utilites import STANDARD_VARS (less general change, but I don't like adding a single plugin exception)
  • Modify the plugin interface (more general, but I don't want to change the interface!)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a simple/sane* way around that.

I think forcing people to add Jinja2 shebangs where they aren't needed is going to be more of a problem than failing to spot when shebangs aren't needed but should have been added.

@wxtim
Copy link
Copy Markdown
Member Author

wxtim commented Sep 5, 2025

Solutions worse than problem. Bug recorded at #6971

@hjoliver
Copy link
Copy Markdown
Member

hjoliver commented Sep 8, 2025

I guess this is to be closed then?

@wxtim
Copy link
Copy Markdown
Member Author

wxtim commented Sep 9, 2025

I guess this is to be closed then?

Thought I had

@wxtim wxtim closed this Sep 9, 2025
@wxtim wxtim deleted the fix.template-vars-no-shebang branch September 9, 2025 09:02
@oliver-sanders oliver-sanders removed this from the 8.5.x milestone Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants