We had similar code-gen steps [1] and had a bit of a journey getting to a happy place. But everyone here was extremely helpful and we did eventually arrive at a good solution that no longer relied on invoking setup.py directly. In case it is useful, here is that thread: