Odd fastcore.script behaviour

Hi,

I have recently been looking at using fastcore.script as a way to create lightweight scripts around functions which are also imported and used elsewhere. However, I seem to be experiencing some odd behaviour, which I will illustrate with a trivial example.

Let’s say I define a script say_hello_script.py which contains:

from fastcore.script import *


@call_parse
def say_hello(greeting: Param('Greeting', str) = 'Hello',
              name: Param('Name', str) = 'World'):
    print(f'{greeting}, {name}')

If I call this from the command line using python say_hello_script.py --name Chris, I get the expected output of Hello, Chris. All is good so far.

However, now I want to call this function from a different script, so I will create a script greeter.py which contains:

from say_hello_script import say_hello

if __name__ == '__main__':
    say_hello(greeting='hi', name='person')

Running python greeter.py I get the output of Hello, World, which seems to have bypassed my arguments! Is this the normal behaviour?

Thanks,
Chris

So, I thought that this had something to do with you putting it into an if/main construct, while @call_parse is designed to not needing that.
However, when removing it, I still bizarrely cannot get it to work in the greeter.py script when run as a whole, while importing say_hello into a live session works as expected. This is indeed weird:

I believe that I found the issue that causes this. Adding the line args = merge(args, kwargs) before tfunc(**merge(args, args_from_prog(func, xtra))) ) resolved it for me.

However, as fastcore uses nbdev, something I haven’t looked into extensively, after trying and failing to get my environment set up - combined with there being no clear way to test this in a notebook - I abandoned both the PR and the use of fastscript!

Hopefully that helps!