generic plugin support

This commit is contained in:
daywalker90
2024-02-07 18:45:04 +01:00
committed by mergify[bot]
parent 27f47b568d
commit 23268522cd

View File

@@ -56,6 +56,8 @@ def enumerate_plugins(basedir: Path) -> Generator[Plugin, None, None]:
]
print(poetry_pytest)
other_plugins = [x for x in plugins if x not in pip_pytest and x not in poetry_pytest]
for p in sorted(pip_pytest):
yield Plugin(
name=p.name,
@@ -79,6 +81,18 @@ def enumerate_plugins(basedir: Path) -> Generator[Plugin, None, None]:
}
)
for p in sorted(other_plugins):
yield Plugin(
name=p.name,
path=p,
language="other",
framework="generic",
details={
"requirements": p / Path("tests/requirements.txt"),
"setup": p / Path("tests/setup.sh"),
}
)
def prepare_env(p: Plugin, directory: Path) -> bool:
""" Returns whether we can run at all. Raises error if preparing failed.
"""
@@ -91,6 +105,8 @@ def prepare_env(p: Plugin, directory: Path) -> bool:
return prepare_env_pip(p, directory)
elif p.framework == "poetry":
return prepare_env_poetry(p, directory)
elif p.framework == "generic":
return prepare_generic(p, directory)
else:
raise ValueError(f"Unknown framework {p.framework}")
@@ -162,6 +178,34 @@ def prepare_env_pip(p: Plugin, directory: Path):
install_pyln_testing(pip_path)
return True
def prepare_generic(p: Plugin, directory: Path):
pip_path = directory / 'bin' / 'pip3'
# Install pytest (eventually we'd want plugin authors to include
# it in their requirements-dev.txt, but for now let's help them a
# bit).
subprocess.check_call(
[pip_path, 'install', *pip_opts, *global_dependencies],
stderr=subprocess.STDOUT,
)
# Now install all the requirements
if p.details['requirements'].exists():
print(f"Installing requirements from {p.details['requirements']}")
subprocess.check_call(
[pip_path, 'install', '-U', *pip_opts, '-r', p.details['requirements']],
stderr=subprocess.STDOUT,
)
if p.details['setup'].exists():
print(f"Running setup script from {p.details['setup']}")
subprocess.check_call(
['bash', p.details['setup']],
stderr=subprocess.STDOUT,
)
install_pyln_testing(pip_path)
return True
def install_pyln_testing(pip_path):
# Many plugins only implicitly depend on pyln-testing, so let's help them