-
-
Notifications
You must be signed in to change notification settings - Fork 482
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
command line option parsing #21
Comments
comment:1
no -- you can't combine command line options like that. this isn't a bug |
comment:2
This should be fixable, but the long term goal is to do a proper rewrite of the command line options. Cheers, Michael |
comment:5
See also #180 for a bunch of related failures due to the option parsing being dumb :o Cheers, Michael |
comment:7
Note that sage -bn now builds, then does notebook, though of course it doesn't fix the issue here. |
Attachment: makefile.gz the file SAGE_ROOT/makefile |
Attachment: makefile.diff.gz Attachment: trac_21-extcode.patch.gz extcode repo |
sagenb repo |
comment:8
Attachment: trac_21-sagenb.patch.gz Here are patches. After applying "trac_21-scripts.patch", you may need to make "SAGE_ROOT/local/bin/sage-sage.py" executable. The build process works for me with these patches. For the standard packages, the third line in
should be changed to "Maybe run 'sage --sh'?", but this doesn't affect the functioning of the packages, and otherwise, they don't need changing. I haven't looked at optional packages. This approaches uses Python's optparse to parse command-line options. If someone wants to write a version using shflags or some other package, go ahead. I propose the following approach, whether using these patches or other ones:
Running "sage" (with no arguments) would not trigger this message. (Perhaps we could only turn this on in prerelease (alpha and rc) versions? Alternatively, a change like this could go with the version 5.0 release.)
perhaps with no easy way of disabling this message while using old-style options.
See sage-devel for some discussion. |
comment:10
I've marked this as "needs review", but it might need work. In the previously cited thread from sage-devel, there was the following suggestion:
This is to speed up access to these programs: do a check like this in a shell script, and then pass the rest of the arguments to Python's optparse using the script included in this patch, or one like it. Then you avoid the slight delay involved in starting up Python if you want to run "gp". It would be nice to have a shell script which had a list of strings "gp", "gap", etc., checked to see if the first(?) argument was "--STR" for STR in this list, and if so, run the appropriate program from SAGE_LOCAL/lib, passing the rest of the line as arguments. Having one list containing all of these strings would make it easy to customize. |
the file SAGE_ROOT/sage |
Attachment: sage.gz Attachment: sage.diff.gz |
comment:11
Replying to @jhpalmieri:
Okay, here's a new version which does this: it adds a file sage-sage-quickstart which gets run first, implementing the above idea. Then if SAGE_NEW_OPTIONS is nonempty, it calls sage-sage.py, the Python/optparse version with GNU/Posix standard command-line options. Otherwise, it calls the old parser sage-sage. For the record, the commands in sage-sage-quickstart are: axiom, ecl/lisp, gap, gp, hg, ipython, maxima, mwrank, python, R, singular. Are any others particularly sensitive to startup times? (Using python adds something less than .1 second on my two-year old iMac, so we're not talking about a lot of time, in any case.) |
comment:12
Note that Python 2.7 will include the argparse module, which might be easier to use than optparse. |
comment:13
Wow, this is really fantastic. |
comment:57
Yes, something quite like that. And I was thinking of writing up some kind of declarative list(s) of subcommands. In particular I was thinking two separate lists:
Although somewhat redundant, because it's common I would also have I might also hide more of the development-specific commands ( |
comment:58
(I should add, that's a very nice mock-up of what such an interface would look like, so thank you for that.) |
comment:59
Replying to @embray:
What about |
comment:60
We should also think to what extent the build system should be exposed under the
and
This is all for historical and accidental reasons, but this ticket should clean that up too. |
comment:61
Needless to say, many people don't even know the subtle differences between the above commands. |
comment:62
Replying to @jdemeyer:
I was actually thinking of allowing subcommands to be chained, like in |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
comment:66
Strong -1 "wontfix" for the idea of making an incompatible change toward using "subcommands" after 14 years of the existence of the |
comment:67
I think the current interface of the |
comment:68
+1 from me to changing the sage script to support subcommands, especially if we can somehow do it in a way that preserves compatibility with the current parsing. I wonder to what extent the following is possible:
Or something else, e.g,. if you do "sage [explicit list of subcommands]" uses the subcommand approach; otherwise, fall back to the current parser. I wrote at least the first version of the current sage command line parser, and frankly I didn't know what I was doing at the time, and just sort of stupidly copied random bits and pieces of design from programs I had used. Using python's subcommands support is a lot more systematic, and can also result in very nice modular code. |
comment:69
Since all of the sage script's current "subcommands" (e.g. |
comment:70
Replying to @williamstein:
I might still just write it as a shell script. Reason being, based on my experience implementing CLIs in Python, it tends to be much much slower to run a single command. At the very least I would do this for the top-level |
comment:71
+1 I should have just said "in my experience, structuring command line parsing code as subcommands (implemented in any language) can result in very nice modular code." |
comment:73
Replying to @williamstein:
One very frustrating part of subcommands is the failure of standard tab-completion to work with it: |
comment:74
Replying to @nbruin:
The question so far has been (for example) |
comment:75
Replying to @jhpalmieri:
From a tab-completion point of view that would make sense, yes. (that, or learn how to extend the tab completion patterns). For this particular example, I'd use The traditional reason for having dashes in front of options/subcommands is to remove ambiguity from Extrapolating from that, I think that using subcommands for the |
comment:76
Replying to @nbruin:
I fully agree. |
comment:77
Replying to @nbruin:
FWIW, there are tools which can do this for you if your command line subcommands and options are all handled by argparse (rather than e.g. a top level bash script that calls out to python programs that use argparse for each subcommand, as embray suggested). argcomplete will dynamically provide on-the-fly completion candidates by actually running the argument parsing logic from the shtab also runs the argument parsing logic from the If you use a shell other than bash, it may be harder. zsh, at least, is supported by shtab and to some extent argcomplete as well. I suggest that |
We should improve and/or modernize and/or revise Sage's command-line parsing.
Two ideas, which could be debated endlessly and could also be implemented independently of each other:
sage --package ...
would be changed tosage package ...
, etc. (comment:56 and comment:57 list some possibilities)Depends on #9958
CC: @kini @saraedum @gvol
Component: user interface
Issue created by migration from https://trac.sagemath.org/ticket/21
The text was updated successfully, but these errors were encountered: