#!/bin/bash

if [ -z "$PYFILE" ]; then
    echo "Error: PYFILE environment variable not set."
    exit 1
fi

OUTPUT_FILE="${PYFILE}c"

echo "Compiling $PYFILE ..."
python3 -m compileall -b "$PYFILE"

if [ -f "__pycache__/$OUTPUT_FILE" ]; then
    mv "__pycache__/$OUTPUT_FILE" .
    rm -rf "__pycache__"
    echo "Compilation successful. Output file: $OUTPUT_FILE"
else
    echo "Error: Compilation failed."
fi
