I am not much of a user of Python, but there are some things that make me want to learn more... Like Saleae is in beta builds with the ability to write python High Level Analyzers, which looks interesting.
So I probably can not help much with python script. But will throw out a few thoughts.
Do you really need/want the Raspberry PI to actually do the compiles? Yes you can do this. But alternatively you could have your main processor do the builds and then transfer the resultant binary files to the RPI and then use the command line Teensy transfer program to actually then program the teensy with the new code.
I was doing that a couple of years ago. Most of the time I would use something like WinSCP to transfer the binary to the RPI. But at one point I had mucked with the Arduino IDE (platform.txt)
to allow me to setup to have the Arduino build, use a transfer setup to copy the file automatically to a known location on the RPI.
I then had a simple process (I think at the time it was a simple command sketch), but could be python, that checked for a new file to show up at the specific location on the RPI, and it would then do the command to transfer that binary to the Teensy...
Again it has been probably a couple of years since I did that, so it may have lost my scripts and the like. But hopefully I posted the information somewhere.