Skip to content
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

[WIP] sage: make sage usable as a python library #58230

Closed
wants to merge 1 commit into from

Conversation

timokau
Copy link
Member

@timokau timokau commented Mar 24, 2019

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
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

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}
Copy link
Member Author

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).

@nixos-discourse
Copy link

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

@stale
Copy link

stale bot commented Jun 1, 2020

Thank you for your contributions.
This has been automatically marked as stale because it has had no activity for 180 days.
If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.
Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the
    related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse. 3. Ask on the #nixos channel on
    irc.freenode.net.

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 1, 2020
@timokau
Copy link
Member Author

timokau commented Jun 16, 2020

/marvin opt-in
/status needs_work

@marvin-mk2
Copy link

marvin-mk2 bot commented Jun 16, 2020

Hi! I'm an experimental bot. My goal is to guide this PR through its stages, hopefully ending with a merge. The stages are

  • needs_review, if the author considers this PR ready
  • needs_work if the PR in its current form is not ready yet. Maybe the reviewer requested changes, there is an ongoing discussion or you are waiting for upstream feedback.
  • needs_merge can be set by reviewers who do not have merge permission but would merge this PR if they could.

Anybody can switch the current status with a comment of the form /status <new_status_here>.

Feedback and contributions to this bot are appreciated.

@marvin-mk2 marvin-mk2 bot added the marvin label Jun 16, 2020
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jun 16, 2020
@ryantm ryantm marked this pull request as draft October 23, 2020 03:07
@stale
Copy link

stale bot commented Apr 26, 2021

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Apr 26, 2021
@Alexnortung
Copy link
Contributor

What is the status on this? And what would have to be changed? I would like to help if it is needed. 😃

@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 15, 2021
@collares
Copy link
Member

collares commented Dec 23, 2021

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 sage_conf module, through which downstream distributions can provide dependency location data to Sage in a robust way (https://trac.sagemath.org/ticket/29038), replacing our wrapper. See https://github.com/sagemath/sage/tree/develop/pkgs/sage-conf, sage_conf.py.in in particular, for an example. Personally I am waiting until most of the modularization effort happens before adapting Nixpkgs, since I don't have a lot of time now, but help with implementing sage_conf is very welcome!

@collares collares mentioned this pull request Jan 12, 2022
12 tasks
@timokau
Copy link
Member Author

timokau commented Jan 13, 2022

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.

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

Successfully merging this pull request may close these issues.

None yet

7 participants