I have a Python 3.5 script that I would like to invoke as a pre-build step in my Code Composer build. To be clear, it should be run as one of the entries in (my project) > Properties > CCS Build > Steps > Pre-build steps.
The script currently begins with the hashbang
"C:\\ti\\ccsv6\\utils\\bin\\gmake" -k all
makefile:217: recipe for target 'pre-build' failed
process_begin: CreateProcess(NULL, env python3 C:\path\to\prebuild.py ../output_file, ...) failed.
make (e=2): The system cannot find the file specified.
python3 ../prebuild.py ../output_file
py ../prebuild.py ../output_file
Have a wrapper script that works under both Python 2 and 3 to detect and run the script with the correct Python version. The Eclipse/CCS pre build step can then be
python ../wrapper.py (possibly with extra arguments like
You could just check if it is running on Windows or Linux and what version of Python it is running. If it is running on Linux and running the wrong Python version, run
subprocess.call(['python3','prebuild.py']). To check the Python version and OS use:
import os, sys, subprocess if sys.version_info < 3 and os.name == 'posix': subprocess.call(['python3','../prebuild.py']) sys.exit() else: subprocess.call(['python','../prebuild.py']) sys.exit()
A more generic script might check if the interpreter is already the right one and try to pass through arguments if it is:
import sys if sys.version_info >= 3 and sys.version_info >= 3: subprocess.call([sys.executable] + sys.argv[1:]
Otherwise the wrapper could iterate over a list of possible interpreters until it succeeds, like:
interpreters = [["py", "-3"], ["python3"]] for interp in interpreters: # Try a subprocess.call(...) as above. Detect bad return codes (eg. py failed) or OSErrors (ie. command wasn't found). success = False try: success = subprocess.call(...) == 0 except OSError: pass if success: break