#!/usr/bin/env python

# This script is a deprecated wrapper around the "cython" program.
# It is deprecated since Trac #27041 (Sage 8.7) because one should
# simply use "cython" directly. We display deprecation messages whenever
# "sage-cython" does something different from plain "cython".

import os
import sys
args = sys.argv[1:]

if "SAGE_SRC" not in os.environ:
    raise RuntimeError("The environment variable SAGE_SRC must be set.")
SAGE_SRC = os.environ["SAGE_SRC"]

# args can have length 0, in case we're printing a usage message (see trac 12207)
pyx_file = os.path.abspath(args[-1]) if len(args) else None
include_sage_flags = False

if pyx_file and pyx_file.startswith(SAGE_SRC):
    sys.stderr.write("WARNING: in the future, sage --cython will not add special flags for files in Sage sources.\n")
    include_sage_flags = True

if '-sage' in args:
    sys.stderr.write("WARNING: sage --cython -sage is deprecated.\n")
    include_sage_flags = True
    args.remove('-sage')
elif '-no-sage' in args:
    sys.stderr.write("WARNING: sage --cython -no-sage is deprecated, remove the -no-sage flag.\n")
    include_sage_flags = False
    args.remove('-no-sage')

if include_sage_flags:
    args = ['--embed-positions', '-I%s' % SAGE_SRC] + args

args.insert(0, 'sage-cython')
os.execlp('cython', *args)
