Ok. I think I will get it to work like that.
But after fiddling around with it I found out that the type of the first argument depends on whether a "hosts" argument was passed into the task decorator or not. This was quite confusing. And the error is a bit cryptic. When calling "local" on an invoke context, the following AttributeError is thrown:
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/invoke/config.py", line 113, in __getattr__
return self._get(key)
File "/usr/lib/python3.7/site-packages/invoke/config.py", line 178, in _get
value = self._config[key]
File "/usr/lib/python3.7/site-packages/invoke/config.py", line 169, in __getitem__
return self._get(key)
File "/usr/lib/python3.7/site-packages/invoke/config.py", line 178, in _get
value = self._config[key]
KeyError: 'local'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/exhuma/.local/bin/fab", line 10, in <module>
sys.exit(program.run())
File "/usr/lib/python3.7/site-packages/invoke/program.py", line 363, in run
self.execute()
File "/usr/lib/python3.7/site-packages/invoke/program.py", line 532, in execute
executor.execute(*self.tasks)
File "/usr/lib/python3.7/site-packages/invoke/executor.py", line 129, in execute
result = call.task(*args, **call.kwargs)
File "/usr/lib/python3.7/site-packages/invoke/tasks.py", line 128, in __call__
result = self.body(*args, **kwargs)
File "/home/exhuma/tmp/fabfile.py", line 8, in get_version
version = ctx.local('python setup.py --version').strip()
File "/usr/lib/python3.7/site-packages/invoke/config.py", line 125, in __getattr__
raise AttributeError(err)
AttributeError: No attribute or config key found for 'local'
Valid keys: ['connect_kwargs', 'forward_agent', 'gateway', 'inline_ssh_env', 'load_ssh_configs', 'port', 'run', 'runners', 'ssh_config_path', 'sudo', 'tasks', 'timeouts', 'user']
Valid real attributes: ['cd', 'clear', 'config', 'cwd', 'from_data', 'pop', 'popitem', 'prefix', 'run', 'setdefault', 'sudo', 'update']