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

Multiple Build Targets #1876

Open
jayceslesar opened this issue Jan 2, 2025 · 10 comments
Open

Multiple Build Targets #1876

jayceslesar opened this issue Jan 2, 2025 · 10 comments

Comments

@jayceslesar
Copy link

Is it possible to specify multiple build targets, or is it better practice to have multiple pyproject.toml files? I basically have a use case where I want

[tool.hatch.buiild.targets.foo] with a custom configuration and similarly for a [tool.hatch.buiild.targets.bar], I want to have a different custom configuration.

@ofek
Copy link
Collaborator

ofek commented Jan 2, 2025

@jayceslesar
Copy link
Author

Are there any documented examples of what this looks like in the wild?

@ofek
Copy link
Collaborator

ofek commented Jan 2, 2025

Oh I see, you mean multiple custom targets. In that case you would create only the custom target and have different logic for each version. You would then build like hatch build -t custom:foo.

@jayceslesar
Copy link
Author

Ah, thank you. Seems like I have opened a duplicate for #1669. Do I still need the get_builder? If I were to pass hatch build -t custom:foo how would I direct it to the foo builder, and similarly for the hatch build -t custom:bar if I had multiple BuilderInterface's defined?

@ofek
Copy link
Collaborator

ofek commented Jan 2, 2025

You could define that yes but the main reason it exists is because sometimes you want to extend an existing builder which requires an import and then automatic detection does not work. I would recommend the version approach and only have a dedicated builder class. Currently there is no environment variable populated that indicates the current target & version so I don't think you would have a way to determine. That exists in a branch somewhere that I working on actually but I've been very busy.

@jayceslesar
Copy link
Author

Ok, thank you so much, this was incredibly helpful! I will look into pushing some docs on this in the future if that is something you would find valuable.

One last question, how would I just inject custom build config into that callable that the get_version_api returns? I basically want to override the sources, include, and scripts and then build as normal using the hatch backend

@ofek
Copy link
Collaborator

ofek commented Jan 2, 2025

For static config use TOML e.g. [tool.hatch.buiild.targets.custom.foo], for dynamic config use environment variables. The [tool.hatch.buiild.targets.custom] mapping is available as the property BuilderInterface.target_config.

@jayceslesar
Copy link
Author

jayceslesar commented Jan 3, 2025

Maybe needs a new issue, but it doesnt look like force-include is respecting a custom target, anything past the custom key --> tool.hatch.build.targets.custom.foo.force-include seems to do nothing, but tool.hatch.build.targets.custom.force-include does

@jayceslesar
Copy link
Author

jayceslesar commented Jan 3, 2025

Ah after looking at the source code it seems that the BuilderConfig does not respect a version at all, and instead the version is only used in the get_version_api, so any actual modifications would need to happen in an overridden build_standard function, because none of the BuilderConfig actually looks for the specified version in the pyproject.toml. Looks like version is entirely stripped in the cli as well https://github.com/pypa/hatch/blob/master/src/hatch/cli/build/__init__.py#L83.

Is modifying what happens in a build based on the version something you are interested in supporting? I would be happy to hack on that if possible, I am new to this project but it doesnt seem like a huge lift given the interfaces are so mature

@jayceslesar
Copy link
Author

jayceslesar commented Jan 3, 2025

@ofek here is a working example of what I am attempting to accomplish -- note that versions are not respected with WheelBuilder, nor are the respective foo and bar versions with force-include entries in the pyproject.toml

https://github.com/jayceslesar/hatch-bug

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

2 participants