Executing a custom target action from a custom target action

I got a third-party python file called download_fs.py, which adds a custom target to PlatformIO when included as an extra_scripts. It works very well.

The custom target is called downloadfs, and contains a single action, called command_download_fs.

Now I want to create my own custom target, which would 1. do some stuff, and then 2. call command_download_fs.

What I did:

  1. I successfully created my own custom target and included it as an extra_scripts
  2. In my custom target, I loaded download_fs.py like this:
    env.SConscript("../../../xxxx/xxxx/download_fs.py", exports="env")
    
  3. I checked that downloadfs has been succesdfully loaded by running env.DumpTargets()

But I’m blocked at this point: how do I execute command_download_fs on the newly loaded downloadfs custom target?

Also, I’d need to pass command line arguments to a python script that expects to find something in sys.argv.

I’ve tried:

env.SConscript("another_script.py --level=100", exports="env")

and:

args =  {'--level': 100}
env.SConscript("another_script.py --level=100", exports="env args")

but it doesn’t work.

Anyone knows how to do this?

I think the easiest way is to just

from download_fs import command_download_fs

and call the function in the handler for your own target, with the same arguments that the own handler was called.