Repository navigation
Replies: 1 comment
|
A build hook is probably the wrong lifecycle for this if the generated files are required before tests run. Build hooks belong to artifact construction, so making Current Hatch gives you a more direct place to express this: the internal For example, make code generation an ordinary command/script and sequence it before pytest in the test environment: [tool.hatch.envs.hatch-test.scripts]
generate = "python path/to/generate_protos.py"
run = [
"generate",
"pytest{env:HATCH_TEST_ARGS:} {args}",
]The exact pytest command should be copied from the current Hatch test-environment defaults you are using, especially if you need coverage/matrix behavior; the important part is that generation is an explicit prerequisite in the test script rather than a side effect of If the same generator is also required when producing distributions, keep the build hook too, but have both the build hook and test script call the same underlying generator. That avoids duplicating generation logic while preserving the correct lifecycle: building generates for an artifact; testing generates because tests require the files. If the generated protobufs are checked into the repository instead, then neither lifecycle hook is needed for normal tests, but whether that is desirable depends on how you manage generated sources. |
Uh oh!
There was an error while loading. Please reload this page.
hey,
We are generating some code with a hook (generating protobuf files), which works great. The only downside is that we also need to run
hatch buildbefore we are able to run tests. I am curious if there is a way to bind a hook to the initial setup phase, like when resolving dependencies or creating some kind of dependency on the hook.Maybe my approach is not the right one, and there is a different approach we should use to generate those files upfront. If so please let me know.
Disclaimer I am not as familiar with python as i am a Java developer, and only used to maven and gradle.
Thank you.
All reactions