uwefladrich / scriptengine

A lightweight and extensible framework for execution scripts written in YAML.
GNU General Public License v3.0
15 stars 4 forks source link

`base.time` does not work as expected within the a `do` structure #106

Closed oloapinivad closed 8 months ago

oloapinivad commented 8 months ago

If I have a do structure I cannot use the base.time feature, or at least it is unclear how to make it work:

The following script leads to:

- base.time:
    set: script_start_time
- base.echo:
    msg: "{{script_start_time}}"

- do: 
  - base.time:
      since: "{{script_start_time}}"
      set: script_elapsed_time
  - base.echo:
      msg: "{{script_elapsed_time}}"

- base.time:
    since: "{{script_start_time}}"
    set: script_elapsed_time
- base.echo:
    msg: "{{script_elapsed_time}}"

leads to:

2024-02-01 15:56:21 INFO [se.cli] Logging configured and started
2024-02-01 15:56:21 INFO [se.task:time <62cb894f01>] Storing datetime in 'script_start_time'
2024-02-01 15:56:21 INFO [se.task:echo <b08443882f>] {{script_start_...
2024-02-01 15:56:21.219558
2024-02-01 15:56:21 INFO [se.task:time <6b3f17db3b>] Storing time delta in 'script_elapsed_time'
2024-02-01 15:56:21 INFO [se.task:echo <27b4b3525e>] {{script_elapse...
None
2024-02-01 15:56:21 INFO [se.task:time <0c700ea187>] Storing time delta in 'script_elapsed_time'
2024-02-01 15:56:21 INFO [se.task:echo <2163f69078>] {{script_elapse...
0.004453

I am not sure if there is another way to access to variable within the do, but I cannot measure it within the do and therefore within a loop. Is there any workaround for this?

uwefladrich commented 8 months ago

It looks indeed like a bug to me. Thanks for reporting, I will have a look.

uwefladrich commented 8 months ago

Hi @oloapinivad, I fixed the issue in the master branch, see #108. The question now is how to get the fix out to you (and others). Normally, I would make a new release and that creates new packages on PyPI and conda-forge.

However, I am in the process of preparing the ScriptEngine 1.0 release. You might have seen that there are already pre-releases 1.0.0rc1 and 1.0.0rc2 on PyPI. So I could release 1.0.0rc3 with the fix included.

The pre-releases are, however, not automatically installed. For one thing, they live only on PyPI, not conda-forge (i.e. install with pip, even in a conda environment). Furthermore, you have to explicitly install them by something like pip install scriptengine>=1.0.0rc1. Thirdly, you also have to install the matching scriptengine-tasks-hpc>=1.0.0rc1.

None of this is really a problem, you just have to know.

The alternative is to create a bugfix release ScriptEngine 0.14.5. That's a little bit more work, I would do it (only) if needed.

oloapinivad commented 8 months ago

Thanks @uwefladrich! No need to create a special release for this, I can wait for the official one or install in my mamba env the main from github if I need it. I was planning to use this to address issue 51 from EC-Earth, it is not urgent. I