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
install_scripts should use "$@" instead of $* #11602
Comments
comment:1
Yep, from if os.path.exists(target):
print "The file '%s' already exists; not adding shortcut"%(target)
else:
o = open(target,'w')
o.write('#!/bin/sh\n')
o.write('sage -%s $*\n'%c)
print "Created script '%s'"%target
os.system('chmod a+rx %s'%target) So this should be At first glance, there are some other things that should be changed:
Moreover:
Btw, you don't have to provide a doctest when fixing this; we'll just review the changes. |
comment:2
Or use the function |
comment:3
Meanwhile... ;-) Replying to @nexttime:
You can replace p = Popen(['which', c], stdout=PIPE, stderr=PIPE) by p = Popen("command -v %s"%c, shell=True, stdout=PIPE, stderr=PIPE) |
comment:4
Replying to @jhpalmieri:
Ok, in principle better, but we also want the result (the command or more precisely its path), to check whether it's located inside the Sage installation. Extending |
comment:5
I assume that, when this script gets executed, we're within an environment like the "sage -sh" shell? Then the $SAGE_ROOT/local/bin directory is in the path before any of the system directories, so it will ALWAYS come back with the Sage version of the tools, UNLESS Sage doesn't have them. In the latter case, there's no need to make a shortcut; in the former, a shortcut will ALWAYS be made. I see no way of finding a system install separately... Hence the suggestion to force an install would not change things; I'll modify the docstring to reflect this. |
comment:6
Replying to @sagetrac-Stefan:
Not necessarily, so I wouldn't change that, or rather fix the baviour such that it matches the description, not the other way around.
Parameter |
comment:7
John perhaps knows better from where this (rather plain Python) script is or can be called; it actually (currently) just requires I haven't found something like Also, not all |
comment:8
I noticed this issue, too, and wrote a patch for it. I think that since this is in a file in the Sage library, we may assume that it is used while Sage is running, so all of the appropriate environment variables are set. Anyway, here's one attempt at a patch. |
comment:9
The following is from README.txt in the root directory:
|
comment:10
Ahem,
|
comment:11
P.S.: Also, if |
comment:12
P.P.S.: I'd also move the |
comment:13
Replying to @nexttime:
Sorry, I missed the quotes in your original comment
On OS X, it works with
I guess on POSIX systems, the directories are always separated by colons. (If not, are there any functions in the Python library for parsing PATH and then reassembling it? Is there a function or variable saying what the separator is?) So the new patch fixes this. (In this case, anyway, the relevant portion of the PATH variable is set by sage-env, which uses the value of SAGE_ROOT, so "SAGE_ROOT/local/bin" should be there as is. This seems to be the case on several different machines in which my Sage install is buried under various symbolic links.)
Right. See the new version.
Okay. |
comment:14
Ah, found it. Bad variable names, I think: it's too easy to confuse these. >>> import os
>>> os.pathsep
':'
>>> os.path.sep
'/' |
comment:15
Replying to @jhpalmieri:
There can be a real command
I wouldn't rely on I'd rather search (Haven't yet looked at the new patch though.) Replying to @jhpalmieri:
> >>> import os
> >>> os.pathsep
> ':' Yep. On M$ Windows, it is " |
comment:16
Ok, The The description of Maybe we should also mention that the destination directory has to be added to There btw. is a typo in the docstring, Also, the message "The command ... is not available ..." should read "... not available in Sage". The if not cmd_inside_sage:
# We *may* also report if a system-wide version is available.
...
continue
if cmd_outside_sage:
print "The command '%s' is installed outside of Sage." % cmd
if not ignore_existing: # ambiguous unless one reads the docstring
print "Not installing a shortcut to Sage's version."
continue
# normal operation, simply install the shortcut unless a file with
# the same name already exists in the target directory
... |
comment:17
Replying to @nexttime:
Yes, and on OS X, there is at least one nonexistent item in the PATH, because of these lines in sage-env:
Note the "2.5". (And of course, someone might have some non-existent directories in their path to start with.)
I don't see any problem with using PIPE to suppress output. Having redirections as part of the shell command seems somehow less elegant to me.
Okay.
I've added some messages about this, both in the docstring and the message printed as the function finishes.
Okay.
if not cmd_inside_sage:
# We *may* also report if a system-wide version is available.
...
continue
if cmd_outside_sage:
print "The command '%s' is installed outside of Sage." % cmd
if not ignore_existing: # ambiguous unless one reads the docstring
print "Not installing a shortcut to Sage's version."
continue
# normal operation, simply install the shortcut unless a file with
# the same name already exists in the target directory
... I changed it to be something like this. |
Attachment: trac_11602-install-scripts.patch.gz |
comment:18
Sorry, completely forgot this ticket. IMHO works as advertised with Sage 4.7.1.rc0, so positive review. Only a few minor things:
(Also,
Not that important here, but in general you should pass the whole environment to |
Reviewer: Leif Leonhardy |
Author: John Palmieri |
for reference only; do not apply |
comment:19
Attachment: trac_11602-delta.patch.gz Replying to @nexttime:
I've attached attachment: trac_11602-install-scripts.v2.patch to deal with these; attachment: trac_11602-delta.patch shows the differences between the two versions.
Maybe the
I quoted it both ways, so it's a backquoted string.
Okay.
Okay
I think it's best to leave this as is. I can't think of a way to phrase it which clarifies things and which isn't too complicated. We could add a phrase like "All things being equal" at the beginning, but I think it's best unchanged.
I think
Okay.
I omitted it. I made a few other changes: it now checks to see if any scripts were written at all. If not, then the ending message doesn't say "Finished creating scripts", etc. Also, the original docstring (and the function name itself) talked about "scripts", while all of the messages printed during execution talked about "shortcuts". I changed it so now they all talk about "scripts" only. |
This comment has been minimized.
This comment has been minimized.
comment:22
Replying to @jhpalmieri:
I'm almost happy with the delta patch, should test the new version though.
Just double-backquotes (monospaced font) would have sufficed.
Well, the notion of shortcuts (or better shortcut scripts) in the description / docstring isn't all bad, as it emphasizes their purpose and perhaps connotes their "light-weightness". The docstring actually lacks a description of what a shortcut [script] is or really / technically does; an example saying that the scripts make e.g. When talking about software components, I'd use their name rather than the corresponding command, i.e. GAP, Maxima, Singular, PARI/GP, MWrank (?), Mercurial, GNU R etc., without quotes. In contrast, when referring to the commands / options to (I guess William just copied and pasted the contents of the Python list.) I'd also typeset "You may need to run Sage as root in order to ..." and perhaps mention sudo sage -c "install_scripts('/usr/local/bin')" (Do you want to add a "shortcut script" We should check once in advance that the given directory is writable by the user, right after the presence test, in order to give a nice(r) error message [earlier]. Btw., I still get an ugly traceback if the directory doesn't exist; can we suppress that or do we really have to I thought we would advise the user (at the end, if any scripts were created) to add (As you may have noticed, I've meanwhile tested also the v2 a little while writing...) If you don't want to make further changes, I won't mind and give it positive review as is (unless I missed some severe flaw, which I don't expect). |
comment:23
P.S.: As an overkill,
etc. :-) |
Attachment: trac_11602-install-scripts.v2.patch.gz |
Attachment: trac_11602-delta2to3.patch.gz for reference only; do not apply |
This comment has been minimized.
This comment has been minimized.
comment:24
Attachment: trac_11602-install-scripts.v3.patch.gz Replying to @nexttime:
Well, it is a string, so it's nice to explicitly include the single quotes in the html version of the reference manual.
I expanded this, perhaps too much.
See the new patch.
Okay.
Okay
No.
Right.
I modified the error messages so they don't raise errors.
Done, although it will not print anything if
I didn't do this. One other change: in the old patch, in every iteration of the loop, we computed PATH and imported |
comment:25
Ok, It's better than the previous version and much better than the original (and of course fixes the issue of this ticket), so positive review. |
comment:26
Ah, forgot one thing: To save one process (yet another shell), we should have written: #!/bin/sh
exec sage -CMD "$@" Or even with two dashs... ;-) |
comment:27
I could add these changes: diff --git a/sage/misc/dist.py b/sage/misc/dist.py
--- a/sage/misc/dist.py
+++ b/sage/misc/dist.py
@@ -133,7 +133,7 @@ def install_scripts(directory=None, igno
else:
o = open(target,'w')
o.write('#!/bin/sh\n')
- o.write('sage -%s "$@"\n'%cmd)
+ o.write('exec sage --%s "$@"\n'%cmd)
o.close()
print "Created script '%s'"%target
os.system('chmod a+rx %s'%target)
diff --git a/sage/misc/sage_ostools.py b/sage/misc/sage_ostools.py
--- a/sage/misc/sage_ostools.py
+++ b/sage/misc/sage_ostools.py
@@ -34,8 +34,12 @@ def have_program(program, path=None):
import os
try:
if path:
+ # env is a copy of the current environment, so modifying
+ # it won't affect os.environ.
+ env = os.environ.copy()
+ env['PATH'] = path
return not call('command -v %s' % program, shell=True,
- stdout=PIPE, env = {'PATH': path})
+ stdout=PIPE, env=env)
else:
return not call('command -v %s' % program, shell=True,
stdout=PIPE) |
comment:28
Yeah, looks good. |
comment:29
Attachment: trac_11602-install-scripts.v4.patch.gz Okay, here's a new patch incorporating exactly those changes. I'm leaving the ticket as "positive review", so if you're happy with the new patch, please change the description of the ticket ("Apply ...") to refer to "v4" instead of "v3". |
comment:30
Positive review also for version 4. |
This comment has been minimized.
This comment has been minimized.
Merged: sage-4.7.2.alpha2 |
When using a script created by Sage's install_scripts() function, parameters with spaces cause problems. Example:
Apparently this was discussed on the mailing list back in 2008:
https://groups.google.com/forum/#!msg/sage-devel/oeFrvqWiP_s/o8mKO-4OAKkJ
It seems that the solution is to make install_scripts write "$@" instead of $* .
Apply only attachment: trac_11602-install-scripts.v4.patch.
CC: @sagetrac-drkirkby @nexttime
Component: misc
Keywords: install_scripts, hg, command line
Author: John Palmieri
Reviewer: Leif Leonhardy
Merged: sage-4.7.2.alpha2
Issue created by migration from https://trac.sagemath.org/ticket/11602
The text was updated successfully, but these errors were encountered: