Last active
December 14, 2021 08:51
-
-
Save jugmac00/c580fd65872393dbabb59fe6850250ff to your computer and use it in GitHub Desktop.
pluggy - different signature problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@hookspec | |
def lpcraft_install_packages() -> List[str]: | |
"""system packages to be installed""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this works like a charm | |
@hookimpl | |
def lpcraft_install_packages(): | |
return ["tox"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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