Skip to content

Build/install when sage installed in meson editable mode fails #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
user202729 opened this issue Apr 21, 2025 · 6 comments
Open

Comments

@user202729
Copy link

See sagemath/sage#39376 (comment)

@orlitzky
Copy link
Collaborator

I guess you are using the meson build instructions rather than pip?

I think the problem is ultimately that sagemath-giac depends on sagemath-standard, and you don't have sagemath-standard "installed" as far as python is concerned. Using pip should have caught that, but a direct meson build assumes that you have the prereqs installed.

If so, the docs are missing some necessary step to build against a sagemath-standard that hasn't been "installed."

@user202729
Copy link
Author

Both instructions (meson install or pip install) give the same result.

I think pip does show sage being installed, something like this…

(sage-dev) [sage]$ pip freeze
...
-e git+https://github.com/user202729/sage@71b335b662e6310d2ca9df0b040bc5e383965214#egg=sagemath
...

@orlitzky
Copy link
Collaborator

Is that a sage shell (like you would get from ./sage -sh)?

If python knows that sage is installed, there is probably some bootstrap script/shell that modifies your python path to include the path to sagelib (which is installed outside of the sys.path, AFAIK). If that's the case, maybe that same process could modify CYTHONFLAGS as well to include the appropriate paths.

That wouldn't fix the general problem of editable dependencies of meson/cython projects, but it would get sage working again quickly in this scenario.

@user202729
Copy link
Author

No, that's bash with conda/mamba environment activated.

Yes, Python knows that sage is installed. But Python path does not include the path to sagelib. Meson-python uses metapath instead.

You can try building sage with meson yourself. On my machine path and meta_path looks like this:

[sage]$ sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.7.beta1, Release Date: 2025-04-18              │
│ Using Python 3.11.11. Type "help()" for help.                      │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: import sys
sage: sys.path
['~/sage/src/bin',
 '~/.local/share/mamba/envs/sage-dev/lib/python311.zip',
 '~/.local/share/mamba/envs/sage-dev/lib/python3.11',
 '~/.local/share/mamba/envs/sage-dev/lib/python3.11/lib-dynload',
 '',
 '~/.sage/local/lib/python3.11/site-packages',
 '~/.local/share/mamba/envs/sage-dev/lib/python3.11/site-packages',
 '/usr/lib/python3.12/site-packages']
sage: sys.meta_path
[MesonpyMetaFinder('sagemath', '~/sage/build/cp311'),
 <_distutils_hack.DistutilsMetaFinder object at 0x...>,
 <class '_frozen_importlib.BuiltinImporter'>,
 <class '_frozen_importlib.FrozenImporter'>,
 <class '_frozen_importlib_external.PathFinder'>]

that's why I use SAGE_SRC in my proposed patch in sagemath/sage#39376 (comment) .

@orlitzky
Copy link
Collaborator

No, that's bash with conda/mamba environment activated.

Yes, Python knows that sage is installed. But Python path does not include the path to sagelib. Meson-python uses metapath instead.

This is my first time seeing that MetaPathFinder, I will have to do some digging to figure out what's going on here. (Is it only with editable installs? Does it affect only your user? How does it get un/installed?)

that's why I use SAGE_SRC in my proposed patch in sagemath/sage#39376 (comment) .

The "right" solution can't involve SAGE_SRC because there is nothing special about sage here. We have one cython package that depends on another, and having the dependency be --editable is making its headers invisible to the dependent. Sage happens to do this, but in general, we wouldn't expect all cython packages to expose their own source directories, so there must be some other solution.

The existing hack traverses sys.path at build time... maybe we should be traversing sys.meta_path instead, or in addition?

I'd like to get it right because AFAIK this is the first such modular cython package and whatever we come up with is likely to be copy/pasted in the future.

@user202729
Copy link
Author

I'd like to get it right because AFAIK this is the first such modular cython package and whatever we come up with is likely to be copy/pasted in the future.

sounds like a right thing to do, in principle. (well also because it doesn't really affect me for now)

How about we propose a change to meson-python to also modify sys.path instead? (technically there should be a separate sys.cpath or something which would be appropriate here, but Python doesn't support that — after all, Cython header is not part of Python infrastructure)

(side note: technically in this case Sage is the package (dependent) and sagemath-giac is the one that requires sage.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants