Skip to content

Instantly share code, notes, and snippets.

@jugmac00
Last active December 14, 2021 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugmac00/c580fd65872393dbabb59fe6850250ff to your computer and use it in GitHub Desktop.
Save jugmac00/c580fd65872393dbabb59fe6850250ff to your computer and use it in GitHub Desktop.
pluggy - different signature problem
# packages is a list of packages, created from the configuration object (config.job.packages),
# but also external plugins can extend this list
# so I need something like this here
packages = list(itertools.chain(*pm.hook.lpcraft_install_packages()))
packages_cmd = ["apt", "install", "-y"] + packages
emit.progress("Installing system packages")
with emit.open_stream(f"Running {packages_cmd}") as stream:
proc = instance.execute_run(
packages_cmd,
cwd=remote_cwd,
env=job.environment,
stdout=stream,
stderr=stream,
)
@hookspec
def lpcraft_install_packages() -> List[str]:
"""system packages to be installed"""
# this works like a charm
@hookimpl
def lpcraft_install_packages():
return ["tox"]
# here is the problem - we have a different signature
# pluggy throws an error/exception
# adding `config` to the hook specification also feels wrong, as it is only needed here, but not in other cases
@hookimpl
def lpcraft_install_packages(config):
return config["job_x"].packages
# as I cannot figure out how to create this internal plugin in a sane way I do the following
results = list(itertools.chain(*pm.hook.lpcraft_install_packages()))
packages = config["job_x"].packages + results
# maybe this is the solution?
packages = list(itertools.chain(*pm.hook.lpcraft_install_packages(packages_from_configuration)))
# and then the internal plugin would be something like this
@hookimpl
def lpcraft_install_packages(packages):
return packages
# and the external plugins just ignore the packages param?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment