# This script loads packages from /src/sage instead of site-packages/sage to make development easier
# For this to work, the following preparation is necessary:
# - Compile sage using `./sage -b`
# - Remove the imports of the packages from site-packages/sage/all.py
# - Delete (or rename) the packages from site-packages/sage
# Moreover, this file has to reside in `src/sage`, e.g. `src/sage/test.py`
# %% Load sage
import sys
import importlib
# Import sage from site-packages
import sage.all
# Load manifolds and tensor packages from src folder, and put them at "sage.manifolds" and "sage.tensor"
spec = importlib.util.find_spec("manifolds")
print(spec) # This should show that the module is loaded from /sage/src/
module = importlib.util.module_from_spec(spec)
sys.modules["manifolds"] = module
sys.modules["sage.manifolds"] = module
spec = importlib.util.find_spec("tensor")
print(spec) # This should show that the module is loaded from /sage/src/
module = importlib.util.module_from_spec(spec)
sys.modules["sage.tensor"] = module
# %%
# Reload manifold packages (actually not needed on first run, use this if you change code in /src/manifolds)
for k,v in sys.modules.items():
if k.startswith('sage.manifolds'):
print(k)
importlib.reload(v)
# Actual imports
from sage.manifolds.differentiable.tensorfield import TensorField
from sage.manifolds.manifold import Manifold
# %% Do what you want here
M = Manifold(2, 'M'); M
XM = M.vector_field_module()