Skip to content

environments.prepare_cmds are not executed when calling find_modules #3698

Description

@casparvl

I have a module whose behavior I can modify by setting an environment variable before loading it. This module loads an environment, that again provides other modules. I.e. interactively, I'd do:

export X=foo
module load Y/1.1  # the load behaviour is affected by the value of X
module avail bar  # bar is available in this environment (but only if X=foo)

I'd like reframe.utility.find_modules to be able to find bar. I've noticed that I cannot simply specify environment.env_vars because those only get set after reframe.core.runtime.loadenv has already called the module commands. So, I figured I'll just leverage prepare_cmds instead:

'environments': [
    {
        'prepare_cmds': ['export X=foo'],
        'modules': ['Y/1.1']
    }

Alas, this didn't work. Looking at the code, I can see why: the prepare_cmds are appended to the returned commands here, but they are not executed when loadenv() is called. According to my AI friend, they are only emitted to the job script that reframe stages (this may or may not be accurate, I'm not sure: I cannot get that far, since it won't generate a test for bar, since it cannot find it :)).

What I'm wondering is: is this a bug? If it is intended behaviour, I'm wondering in which scenario you want to have these prepare commands be emitted in the job script, but not during the find_modules. Also: would it be worth making this more explicit in the documentation? ("List of shell commands to be emitted before any commands that load the environment." => that sounds like it would also happen when find_modules loads an environment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions