-
-
Notifications
You must be signed in to change notification settings - Fork 567
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
sage-native-execute leaves traces of sage #9386
Comments
New commits:
|
Author: Thierry Monteil |
Commit: |
comment:8
This goes a long way towards reconstructing the starting environment. The main thing I am worried about is that a lot of variables are "restored" by unsetting them, regardless of whether they had a previous value.That could break things. That makes me wonder whether we should do something like the following at the start of sage:
and restore it by something like
This doesn't actually work, but I hope you get the idea. If we go this route we should probably make a python script "store_environment", and make In fact, we should probably do this all on C-level with tiny programs, where we can use first the I'd be fine with a more piecemeal solution as proposed here, because at least it will significantly improve the situation. |
comment:9
I agree that once Sage exports a variable, we lose the information on whether it existed before (apart from |
comment:10
Replying to @sagetrac-tmonteil:
edit: better to store the relevant variable names in a separate variable The restoring bit could be easy:
The difficult part is ensuring all exports adhere to the standard imposed here. You could make a bash function that does this, but not all environment setting needs to happen by bash, and we might not have easy control over all environment setting instructions (chances are we do for all variables that matter, though. If we adjust sage-env, we're probably already good). An obvious advantage is that any non-cooperating environment clobbering will simply not be restored, which is not necessarily an error condition.
Agreed. Storing an environment in a temporary variable somewhere sounds awkward. |
comment:11
On the Python side, i did the following short enumeration:
So, this should not require much work to update, but perhaps there are other ways to modify an environment variable in Python ? |
comment:12
Replying to @sagetrac-tmonteil:
You don't really need to fix those in-situ. You just need to trigger saving the original value of the variables involved sage-env. I suspect that will be much more robust than trying to track down every site where the environment gets modified. |
comment:13
After quite some work, the following seems to work (and let us love Python):
|
comment:14
Ah good. Looks like we came up with about the same solution relatively independently. Some things:
|
sage export/restore environment variable facility |
comment:15
Attachment: sage_restore.sh.gz Unsetting |
comment:16
Replying to @jdemeyer:
Would you care to elaborate? If I do
I end up with my original path back, not with an unset path. I fully expect that the script needs further tuning and probably lots of quotes in all kinds of places to catch all kinds of little quirks (it's scary to think that shell scripts are the weapon of choice for complicated configuration tasks), but I think the general mechanism is fine. Do you have better suggestions? I'm not married to my implementation. If you come up with something better I'm sure we'll be happy to adopt that. However, if you're going to suggest to unset PATH then I don't think we'll be so eager, because indeed, I think if you do that, you'll break a lot. |
comment:17
I didn't look at your script, just the branch here. If a ticket gets set to "needs_review", it's assumed that the branch is what should be reviewed, not some random attachment to the ticket. |
comment:26
There are some typos: "and its value and, if this hasn't been done before, its value" s/sage-native execute/sage-native-execute/
There are some other issues I can't all list right now... ;-) But for example, #we need to test early that the first parameter is a valid identifier
export "$varname" || return 1
should probably give a more explicit error message instead of just relying on bash's. Otherwise, nice work. Why not define It could also be extended to restore individual variables (e.g. |
comment:27
Replying to @nexttime:
And |
comment:28
Quoting and use of curly braces is inconsistent. At some points, quoting isn't necessary, while for example in There's also a wild mixture of bash constructs and non-bash constructs, such as In But more importantly, that check does not at all work with variable names like |
comment:30
Replying to @nexttime:
because we need it (only) in
which should be done if the need arises (would you prefer to do it now?) |
comment:31
Replying to @nexttime:
Please fix! I will never be a reliable bash/sh programmer. If you have better knowledge on the pitfalls there please go ahead and make the changes. It'll be much faster than explaining to me which changes to make and then have to correct my incomplete fixes afterwards.
Oops ... The easiest fix for that is to ensure that |
comment:32
Replying to @nbruin:
Well, at the moment I think. (I was also wondering whether people will find it at all if it's [just] defined in
Every The only thing we'd have to add is There's probably one problem already: It at least used to be the case that If that's still a problem, we could "bypass" some things in case the shell isn't bash. When or where is
Just an idea, doesn't have to be implemented here. |
comment:33
Replying to @nbruin:
No problem, provided the source is "stable". Not sure yet whether to make it "all bash" (e.g. |
comment:34
Replying to @nbruin:
Good idea, probably using a different separator as well (to avoid confusion with typical
Not at first glance. |
comment:35
Replying to @nexttime:
I tried staying with POSIX but it's a pain for this case, in particular because we need dereferencing of variables, which is easy in bash and painful in POSIX. I recall that the substring matching was also easier with bash. The fact is that For separation: I figured I was pretty happy with the state of the script, so I'm happy to not make changes to it. |
comment:36
Replying to @nexttime:
That's horrible! That stores the entire function in the environment. Every process spawned after sage-env was sourced would have that in its memory.
OK, it's unlikely that a program that has such specific environment needs that it needs However, I think there is something logically wrong with sourcing The "proper" solution would probably be to have sage_export and sage_restore in yet another file and source that in sage-env. But probably adds considerable overhead (to any sourcing of sage-env). |
comment:37
OK, I'm holding off updating the branch here because leif expressed willingness to clean up the shell style of the code here. leif pointed out one actual deficiency (the substring problem), which I know how to correct. It looks like this ticket is a prereq (or at least should be) for #18438, so there's a little more urgency to resolving this ticket. Preferences on how to proceed? |
comment:38
The added |
The following shows that
sage-native-execute
creates a very hostile environment for running python:The problem is
python
refers to the sage python, because $PATH still has sage paths in it. This doesn't run because LD_LIBRARY_PATH does not point at sage library anymoreThe system python
/usr/bin/python
doesn't run successfully either because PYTHONPATH and PYTHONHOME still point at sage locations.This problem arose while trying to use the magma interface. My magma startup script uses python to resolve some paths, which didn't work anymore.
There are other traces left by sage-native-execute:
so I imagine local ecl, gp python, singular will all have problems.
I include LD_LIBRARY_PATH because that variable was originally undefined, not just empty. The variables PYTHONHOME and PYTHONPATH really need to be unset, not just emptied.
CC: @gvol @nexttime @vbraun
Component: scripts
Author: Nils Bruin, Thierry Monteil
Branch/Commit: u/nbruin/sage_native_execute_leaves_traces_of_sage @
c4fdc67
Issue created by migration from https://trac.sagemath.org/ticket/9386
The text was updated successfully, but these errors were encountered: