python Runner

Can run a gada node from a Python script by spawning a subprocess.

Basic Python package structure:

├── mycomponent
│   ├── __init__.py
│   ├── mynode.py
│   └── config.yml

Content of mynode.py:

def main():
    print("hello world")

if __name__ == "__main__":
    main()

Sample config.yml:

nodes:
  mynode:
    runner: python
    file: ${comp_dir}/mynode.py

Usage:

$ gada mycomponent.mynode
hello world

Full configuration

Based on Python package structure shown above:

nodes:
  mynode:
    runner: python
    [bin: python]
    file: ${comp_dir}/mynode.py

Parameters:

  • bin: Optional - Python bin to use in command line (default is python)

  • file: Python script to run

Handle command line arguments

The python runner will run your gada node as python ${file} ${argv} where argv are the command line arguments. You can retrieve them with sys.argv as in any Python script.

Content of mynode.py:

import sys

def main(argv, **kwargs):
    print(argv)

if __name__ == "__main__":
    main(sys.argv)

Usage:

$ gada mycomponent.mynode 1 2
['path/to/mynode.py', '1', '2']

Note

argv[0] is the Python script that is run.

Multiple Python versions

Add the following to gada/config.yml:

bins:
  python3.7: /path/to/python3.7.exe
  python3.8: /path/to/python3.8.exe

Now you can make your gada node either run with Python 3.7 or Python 3.8 by setting the right bin in config.yml:

nodes:
  mynode:
    runner: python
    bin: python3.8
    file: ${comp_dir}/mynode.py

Content of mynode.py:

import sys

def main(**kwargs):
    print(sys.version)

if __name__ == "__main__":
    main()

Usage:

$ gada mycomponent.mynode
3.8