pyinfra
pyinfra copied to clipboard
Running packaged deploys programmatically
I would like to use the packaged deployments from within Python code to build a more dynamic deployer system which would have a UI.
How would I go about running the packaged deployments this way? By just calling the packaged deploy I get a exception:
type object 'State' has no attribute 'config'
Is there a way to do this and could an example be provided? In the documentation currently only how to use the CLI is extensively described. https://docs.pyinfra.com/en/2.x/deploy-process.html
In case it's useful – I noticed that there's some information on how to use PyInfra via its API here: https://docs.pyinfra.com/en/2.x/api/index.html
However, it's not entirely clear from this how you'd invoke a packaged deploy. In the CLI code, it looks like the following function is responsible for loading a deploy script:
https://github.com/pyinfra-dev/pyinfra/blob/9256e6ab8cf5196d4bc1e49eb0aa58b693d53ff3/pyinfra_cli/util.py#L191-L193
It's not entirely clear to me what the invoked _parallel_load_hosts function is doing, but if you look at it, it seems to be passing a pyinfra.api.state.State object to the current Context, and ultimately, compiling the packaged deploy and executing it with Python's builtin exec
function (here).
(I have a somewhat similar problem, trying to execute a particular function programmatically – if I end up creating an issue for it, I'll link this one too, in case the answers might be of assistance to you too.)