From dddfdc544becf7b4413d7a309d78991dbe49b717 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 21 Jan 2025 19:47:08 -0500 Subject: [PATCH] src/bin/sage-cython: new cython wrapper with the venv sys.path When Sage is installed in a venv, sagelib gets added to sys.path by virtue of venv/bin/python, which basically runs whatever python you were going to run anyway, but with a modified sys.path. If however you are building an external cython package using the system cython, this falls apart: the system cython is run under the system python, which does not have sagelib in its sys.path. This makes it impossible to build cython SPKGs that depend on sagelib. To address the issue, we add a tiny wrapper called sage-venv-cython that essentially runs "python /path/to/cython" rather than"cython". To use it, simply set export CYTHON=sage-cython in spkg-install.in. (By the time the package is built, the wrapper will be in $PATH.) --- src/bin/sage-cython | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 src/bin/sage-cython diff --git a/src/bin/sage-cython b/src/bin/sage-cython new file mode 100755 index 00000000000..dbcddb22835 --- /dev/null +++ b/src/bin/sage-cython @@ -0,0 +1,23 @@ +#!/usr/bin/env sage-python +# +# A wrapper that calls "python /path/to/cython" rather than executing +# "cython" directly. This ensures that, within a venv, cython is +# executed using the venv python and not the system python. The +# distinction is important because cython uses the same sys.path as +# the python it's running under; if we use the system python to run +# cython, then cython won't be able to see sage's own pxd files. +# +# This only matters when building external cython packages that +# make use of sage's own C extensions. + +import os +import shutil +import sys + +python = sys.executable +cython = shutil.which("cython") + +args = sys.argv[1:] +args.insert(0, python) +args.insert(1, cython) +os.execv(python, args)