How can I pass custom config from pyproject.toml to custom build hook? #2049
-
I'd like to be able to set a value in # Section in pyproject.toml
[tool.hatch.build.hooks.custom]
path = "my_build_hook.py"
myconfig = "xyz" Then inside from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
super().initialize(version, build_data)
print(self.get_config_somehow("myconfig")) # prints "xyz" Is this possible somehow? I realise that I could just make myconfig a global constant in the build hook Python file, but I have something that I imagine will change with each release while the rest of the code of the hook won't, so it would be more elegant if it were in the Looking at the source code to class CustomBuildHook(BuildHookInterface):
def __init__(self, root, config, *args, **kwargs):
self.myconfig = config["myconfig"] # Saves xyz in self.myconfig But I don't see it documented anywhere so I don't know if this is guaranteed to be a stable API. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Ah, I think it might be as simple as class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
print(self.config["myconfig"]) |
Beta Was this translation helpful? Give feedback.
Ah, I think it might be as simple as
BuildHookInterface.config
: