Skip to content

Commit

Permalink
src/bin/sage-cython: new cython wrapper with the venv sys.path
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
orlitzky committed Jan 24, 2025
1 parent 255259e commit dddfdc5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/bin/sage-cython
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit dddfdc5

Please sign in to comment.