#!/usr/bin/env bash # This script is run in the CI container to preparse all .sage files into .sage.py files # and can also be run locally for local linting/testing. set -e if command -v python >/dev/null 2>&1 && python -c "import sage.repl" >/dev/null 2>&1; then run_python() { python "$@"; } else run_python() { sage --python "$@"; } fi for f in $(find . -name "*.sage" -not -path "./playground/*"); do run_python -c " import sys from sage.repl.preparse import preparse_file path = sys.argv[1] with open(path) as fh: src = fh.read() with open(path + '.py', 'w') as fh: fh.write('from sage.all import * # noqa: F401,F403\n') fh.write(preparse_file(src)) " "$f" done