-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[WIP] sage: make sage usable as a python library #58230
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
Conversation
Use a python wrapper instead of a bash wrapper. As a result, you can now `import sage` from regular python.
exec(compile(open('${targetDir}/inject.py').read(), '${targetDir}/inject.py', 'exec'), {}, {}) | ||
sys.path = [ '${packageToWrap}/lib/${python.libPrefix}/site-packages' ] + sys.path | ||
sys.modules.pop(__name__) | ||
import ${module_name} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FRidh @dotlambda what do you think about this?
It turns out we actually can wrap python libraries (continuing the discussion in #53816). The trick is to create a module with the same name that does whatever the wrapper is supposed to do and then swaps itself out with the actual module (like exec
in bash).
Here I use this for sage, but it could be generalized and used for gnome etc. where we need to set certain environment variables.
There is a usage example in sage-env.nix
(better look at the file directly instead of the diff).
This pull request has been mentioned on Nix community. There might be relevant details there: https://discourse.nixos.org/t/add-libraries-to-sagemath-jupyter-sage-python-kernels/3281/2 |
Thank you for your contributions.
|
/marvin opt-in |
Hi! I'm an experimental bot. My goal is to guide this PR through its stages, hopefully ending with a merge. The stages are
Anybody can switch the current status with a comment of the form Feedback and contributions to this bot are appreciated. |
I marked this as stale due to inactivity. → More info |
What is the status on this? And what would have to be changed? I would like to help if it is needed. 😃 |
This PR's approach probably still works, but upstream is currently undergoing a big modularization effort (https://trac.sagemath.org/ticket/29705) that would probably make it easier to support importing parts of Sage from Python. A part of this process which already exists the |
I am no longer very actively involved in sage maintenance, @collares is the main authority in that regard now. It would be great if you could help him with the modularization :) I don't plan to work on this PR any time soon, so I'll close it for now. |
Motivation for this change
Use a python wrapper instead of a bash wrapper. As a result, you can now
import sage
from regular python.WIP as there is some restructuring (and hopefully simplification) needed.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nix-review --run "nix-review wip"
./result/bin/
)nix path-info -S
before and after)