I am working on a Python project that uses Thrift files to define the structure of on-the-wire network messages.
The .thrift files (which define the structure of the messages) are of course checked into version control (git in my case).
The thrift compiler is used to generate code in a choice of language bindings (Python in my case) to encode and decode the on-the-wire messages from and to native Python data structures.
The command to run the compiler is:
thrift --gen py encoding.thrift
The compiler generates a new directory (gen-py) which contains the generated Python files:
$ find gen-py
gen-py
gen-py/__init__.py
gen-py/encoding
gen-py/encoding/constants.py
gen-py/encoding/__init__.py
gen-py/encoding/ttypes.py
While there are pros and cons to checking generated files into version control (see for example here and here), I am on the side of the fence that I prefer to not check generated files into version control.
I am relatively new to Python development. I come from a background of using mostly compiled languages (e.g. C++) that use some sort of build tool (e.g. make files) where it is relatively straight-forward to add some rules to the build script to run the thrift compiler and generate the language bindings.
My questions are:
What is the best practice in Python to automatically run the thrift compiler and generate the Python files?
If possible, I would like to have dependency awareness in what-ever build tool you suggest, so that the thrift compiler is only run if necessary (i.e. the generated files are absent, or the .thrift files have been touched since the last build).