Skip to content

Instantly share code, notes, and snippets.

@SpotlightKid SpotlightKid/pyxrun.sh
Last active Aug 29, 2015

Embed
What would you like to do?
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.
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
You can’t perform that action at this time.