hatch icon indicating copy to clipboard operation
hatch copied to clipboard

Allow for Plugins/Hooks to provide custom construct_metadata_file_* functions

Open CarliJoy opened this issue 3 months ago • 1 comments

In order to test/develop features not yet fromalized in an accepted PEP it would be very helpful if Plugins could defined a custom construct_metadata_file_experimental function.

I am thinking about PEP 725 for example.

Currently adding a not formalized field to the metadata is impossible for plugins.

The proposal would be that one could register plugins like this

class ExperimentalMetadataFileHookInterface(ABC): 
    METADATA_VERSION = ''
    """The name used for selection, needs to start with `experimental-`"""


    @staticmethod
    @abstractmethod
    def construct_metadata_file(metadata: ProjectMetadata, extra_dependencies: tuple[str] | None = None) -> str: ...

And then in the pyproject.toml it could be selected by

[tool.hatch.target.wheel]
core-metadata-version = "experimental-pep725"

This would be very clear to the enduser what is happeing and quite simple for the plugin creator to create.

What do you think?

CarliJoy avatar Sep 22 '25 14:09 CarliJoy

I am aware of https://github.com/pypa/hatch/issues/1712 / https://pypi.org/project/hatch-external-dependencies/ but

type(self.build_config).core_metadata_constructor = metadata_constructor_extended

Just feels like a hack to me, that I would not like to rely on.

CarliJoy avatar Sep 22 '25 15:09 CarliJoy