Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is possible to write custom connectors, but not to use them #977

Open
KACAH opened this issue Apr 15, 2023 · 2 comments
Open

It is possible to write custom connectors, but not to use them #977

KACAH opened this issue Apr 15, 2023 · 2 comments
Labels
Bug Label for all kind of bugs. Documentation Issues with docs/examples/docstrings.
Milestone

Comments

@KACAH
Copy link

KACAH commented Apr 15, 2023

There is more or less documented way to write your own connectors:
https://docs.pyinfra.com/en/2.x/api/connectors.html

However, connectors lookup is pretty much hardcoded to pyinfra.connectors package right here:
https://github.com/Fizzadar/pyinfra/blob/51c48de09adcc7b8e9ee5da7b56b44f230cc30a0/pyinfra/api/connectors.py#L33

and there:
https://github.com/Fizzadar/pyinfra/blob/51c48de09adcc7b8e9ee5da7b56b44f230cc30a0/pyinfra/api/inventory.py#L92

So, it's not possible to use connectors outside the official pyinfra release without monkey patching.

Is it designed to be like that? And if so, what is the purpose of the mentioned documentation page?

@KACAH KACAH added the Bug Label for all kind of bugs. label Apr 15, 2023
@mvgijssel
Copy link

I've managed to create a basic teleport connector here https://github.com/mvgijssel/setup/pull/262/files with the following monkey patch in the inventory.py

import pyinfra.api.connectors
import provisioner.connectors.teleport

from pyinfra.api.connectors import get_all_connectors
import pyinfra.api.inventory

original_get_all_connectors = pyinfra.api.connectors.get_all_connectors


def patched_get_all_connectors():
    data = original_get_all_connectors()
    data["teleport"] = provisioner.connectors.teleport
    return data


pyinfra.api.connectors.get_all_connectors = patched_get_all_connectors
pyinfra.api.inventory.get_all_connectors = patched_get_all_connectors

It's not pretty but it works!

@Fizzadar
Copy link
Member

Fizzadar commented May 17, 2023

The move to use entrypoints should facilitate exactly this kind of situation! I don't have time to pull an example together right now but essentially you need to define a package that adds to the pyinfra.connectors entry point (https://packaging.python.org/en/latest/guides/creating-and-discovering-plugins/#using-package-metadata).

I will try to get an example of this up somewhere!

@Fizzadar Fizzadar added this to the v3 milestone Jun 8, 2024
@Fizzadar Fizzadar added the Documentation Issues with docs/examples/docstrings. label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Label for all kind of bugs. Documentation Issues with docs/examples/docstrings.
Projects
None yet
Development

No branches or pull requests

3 participants