pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.85k stars 374 forks source link

ImportError: cannot import name 'init' from 'pyinfra.operations' #843

Closed jave closed 2 years ago

jave commented 2 years ago

Describe the bug

While trying to run an old pyinfra script, I get ImportError: cannot import name 'init' from 'pyinfra.operations'

23:12:56-joakim@tanaka:~/infra/vagrant_mail_vm$ pyinfra inventory-dev.py bugvm.py --> Loading config... --> Loading inventory... Getting Vagrant config...

--> Connecting to hosts... [@vagrant/mailvm-dev] Connected

--> Preparing operations... Loading: bugvm.py Traceback (most recent call last): File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 68, in exec_file exec(PYTHON_CODES[filename], data) File "bugvm.py", line 2, in from pyinfra.operations import dnf, server, init, files, postgresql ImportError: cannot import name 'init' from 'pyinfra.operations' (/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra/operations/init.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 232, in load_file exec_file(filename) File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 72, in exec_file raise UnexpectedExternalError(e, filename) pyinfra_cli.exceptions.UnexpectedExternalError: 2022-06-24T21:14:06Z <Greenlet at 0x7fb472a44940: load_file(Host(@vagrant/mailvm-dev))> failed with UnexpectedExternalError

--> An unexpected exception occurred in: bugvm.py:

File "/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra_cli/util.py", line 68, in exec_file exec(PYTHON_CODES[filename], data) File "bugvm.py", line 2, in from pyinfra.operations import dnf, server, init, files, postgresql ImportError: cannot import name 'init' from 'pyinfra.operations' (/home/joakim/.local/pipx/venvs/pyinfra/lib64/python3.10/site-packages/pyinfra/operations/init.py)

To Reproduce

inventory-dev.py

mail_dev = [ ('@vagrant/mailvm-dev', {'production':False, 'fqdn':'mboxdev.verona.se'}) ]

bugvm.py import sys from pyinfra.operations import dnf, server, init, files, postgresql from pyinfra import host

Expected behavior

to be able to run code like

    init.systemd(
        name='Restart and enable the {} service'.format(service),
        service='{}.service'.format(service),
        running=True,
        restarted=True,
        enabled=True,
    )

Meta

jave commented 2 years ago

looking through gitlog, seems I should use systemd.service instead of init.systemd?

However the examples still mention init.systemd

jave commented 2 years ago

ok, its not a bug, it might be a doc issue, but i close for now