Last active
August 29, 2015 13:56
-
-
Save SpotlightKid/42880bb873c5ff9e697a to your computer and use it in GitHub Desktop.
Here is a useful little shell function I came up with while experimenting with Cython (http://cython.org/). Put it in your ~/.bashrc and then use it to compile a Cython source code file (*.pyx extension) into a standalone executable and run it directly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pyxrun() { | |
PYTHON="${PYTHON:-python}" | |
if [ "x$1" = "x-t" ]; then | |
local timeit="time" | |
shift | |
fi | |
if [ -z "$1" ]; then | |
echo "usage: pyxrun [-t] <file>.pyx" | |
return 2 | |
else | |
pyx="$1" | |
bn="${pyx%.*}" | |
shift | |
fi | |
if [ ! -x "$bn" -o "$pyx" -nt "$bn.c" ]; then | |
cython --embed "$pyx" && \ | |
gcc -o "$bn" "$bn.c" `$PYTHON-config --cflags --ldflags` | |
if [ $? -ne 0 ]; then | |
echo "Compilation of $pyx failed." | |
return 1 | |
fi | |
fi | |
eval $timeit "`dirname $pyx`/${bn##*/}" "$@" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment