Wednesday 31 March 2021

How to generate python code during a build and include those in a python wheel?

We have a package that generates code by means of

$PYTHON -m grpc_tools.protoc -I="foo_proto" --python-out="$package/out" \
         --grpc_python_out="$package/out" ./path/to/file.proto

This was integrated (read hacked) into our setup.py building by means of:

from distutils.command.build_py import build_py

class BuildPyCommand(build_py):
    """
    Generate GRPC code before building the package.
    """
    def run(self):
        import subprocess
        subprocess.call(["./bin/generate_grpc.sh", sys.executable], shell=True)
        build_py.run(self)

setup(
      ....
      cmdclass={
        'build_py': BuildPyCommand
    },
)

Which ugly as is, seems to work when building with the legacy setup.py, but when the package is built with wheel it doesn't work at all.

How can I make this work when installing my package by means of wheel?



from How to generate python code during a build and include those in a python wheel?

No comments:

Post a Comment