Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build hooks should be able to exclude files #1787

Open
virtuald opened this issue Nov 9, 2024 · 2 comments
Open

build hooks should be able to exclude files #1787

virtuald opened this issue Nov 9, 2024 · 2 comments

Comments

@virtuald
Copy link

virtuald commented Nov 9, 2024

This probably comes up a lot when trying to write hatch plugins that compile native code. Let's say that you're writing a cmake plugin for hatch, you would want the build hook to be able to automatically exclude CMakeLists.txt (and probably the .cpp files too) from the built wheel without the user needing to manually add it to their pyproject.toml.

@virtuald
Copy link
Author

virtuald commented Nov 9, 2024

Hm, maybe I spoke too soon, this appears to work from plugin initialize function:

        build_config = self.build_config.build_config
        if "exclude" in build_config:
            build_config.append("CMakeLists.txt")
        else:
            build_config["exclude"] = ["CMakeLists.txt"]

... but this seems unintentional and it probably isn't something that should be relied on to work?

@virtuald
Copy link
Author

virtuald commented Nov 9, 2024

Ok, this works, but once again it seems pretty brittle:

       build_config = self.build_config.build_config
        wheel_config = build_config.get("targets", {}).get("wheel", {})
        if "exclude" in wheel_config:
            wheel_config["exclude"] += to_exclude
        elif "exclude" in build_config:
            build_config["exclude"] += to_exclude
        else:
            build_config["exclude"] = to_exclude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant