Opened 10 years ago

Closed 10 years ago

#12333 closed defect (fixed)

Restore --grep and --grepdoc command line options

Reported by: was Owned by: jason
Priority: major Milestone: sage-5.0
Component: misc Keywords:
Cc: Merged in: sage-5.0.beta6
Authors: Francis Clarke Reviewers: William Stein, John Palmieri
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by jhpalmieri)

I just tried one of my *favorite* command line options in Sage-4.8:

$ sage -grep optional |grep gap # and all kinds of other awesome command line stuff 

and was very surprised and disappointed that (a) sage -grep is just gone, and (b) there is no other equivalent command line functionality.

Searching reveals that #12190 removed sage -grep from sage. You can't just remove functionality without any comment. At a minimum it would have to be deprecated for a year, and should also be discussed on sage-devel.

I'm able to accomplish what I want via

./sage -c "search_src('optional', 'gap')"

However, this requires starting up Sage, which is much slower than the old sage -grep. I admit that "-grep" wasn't the best command line option name -- search_src would have been better.

The optimal fix for this ticket would be to refactor the code in sage/misc/sagedoc.py (if possible) so it can be imported without importing all Sage, then use it to implement a command line "-search_src", and add back "-grep" with a 1-year deprecation.

Failing that, just revert #12190 for 1 year.


Apply:

Attachments (4)

trac_12333_restore_sage_-grep.patch (2.0 KB) - added by fwclarke 10 years ago.
trac_12333_restore_grep_root.patch (1.4 KB) - added by fwclarke 10 years ago.
apply to root repository
trac_12333_restore_grep_scripts.patch (680 bytes) - added by fwclarke 10 years ago.
apply to scripts repository
trac_12333-documentation.patch (1.8 KB) - added by jhpalmieri 10 years ago.
Sage library

Download all attachments as: .zip

Change History (12)

Changed 10 years ago by fwclarke

comment:1 Changed 10 years ago by fwclarke

  • Authors set to Francis Clarke
  • Status changed from new to needs_review

The patch restore sage -grep, and sage -grepdoc, but uses a new simpler, one-line grep. This has the following advantages:

  • It is significantly faster;
  • The files are searched in lexicographical order, rather than putting all the ".py" files before the ".pyx" files, etc.

In addition a new header is provided, which doesn't include the irrelevant "Type notebook() ...", and which shows the branch (if it isn't main).

comment:2 follow-ups: Changed 10 years ago by jhpalmieri

  • Status changed from needs_review to needs_work

Unfortunately, grep --recursive ... does not work on Solaris or OpenSolaris. These are supported platforms for Sage, so we need another approach.

As far as the banner occurs, maybe it shouldn't be there at all? Set SAGE_BANNER=no, as in sage -c ..., to omit it.

Finally, this should be rebased to some beta release of Ssge 5.0: the script sage-sage is no longer there; instead, patch SAGE_ROOT/spkg/bin/sage.

comment:3 in reply to: ↑ 2 Changed 10 years ago by was

Replying to jhpalmieri:

Unfortunately, grep --recursive ... does not work on Solaris or OpenSolaris. These are supported platforms for Sage, so we need another approach.

But please keep grep --recursive for everything but Solaris.

As far as the banner occurs, maybe it shouldn't be there at all? Set SAGE_BANNER=no, as in sage -c ..., to omit it.

Agreed.

Finally, this should be rebased to some beta release of Ssge 5.0: the script sage-sage is no longer there; instead, patch SAGE_ROOT/spkg/bin/sage.

Changed 10 years ago by fwclarke

apply to root repository

Changed 10 years ago by fwclarke

apply to scripts repository

comment:4 in reply to: ↑ 2 Changed 10 years ago by fwclarke

  • Status changed from needs_work to needs_review

Replying to jhpalmieri:

Unfortunately, grep --recursive ... does not work on Solaris or OpenSolaris.

The code in the new trac_12333_restore_grep_scripts.patch should work much more generally. It seems to be no slower than the previous approach.

As far as the banner occurs, maybe it shouldn't be there at all? Set SAGE_BANNER=no, as in sage -c ..., to omit it. Finally, this should be rebased to some beta release of Sage 5.0: the script sage-sage is no longer there; instead, patch SAGE_ROOT/spkg/bin/sage.

The attachment trac_12333_restore_grep_root.patch patches SAGE_ROOT/spkg/bin/sage, removes the banner, and allows -search_src as a synonym for -grep, and -search_doc for -grepdoc.

One other modification to earlier behaviour: the grep option -i is no longer hard-wired, but it can be restored, as can other options. For example:

$ sage -search_src -il clarke
sage/rings/morphism.pyx
sage/rings/number_field/number_field.py
sage/rings/number_field/number_field_element.pyx
sage/rings/number_field/number_field_ideal.py
sage/rings/number_field/unit_group.py
sage/rings/polynomial/polynomial_element_generic.py

comment:5 follow-up: Changed 10 years ago by jhpalmieri

  • Description modified (diff)
  • Reviewers set to William Stein, John Palmieri

Looks good, works on sage.math, OS X, OpenSolaris. So there don't seem to be any cross-platform issues.

I'm happy with the two main patches: positive review for those. What do you think of the attached patch for the reference manual?

Changed 10 years ago by jhpalmieri

Sage library

comment:6 in reply to: ↑ 5 Changed 10 years ago by fwclarke

  • Status changed from needs_review to positive_review

Replying to jhpalmieri:

... What do you think of the attached patch for the reference manual?

Looks good to me, so positive review for the documentation change.

comment:7 Changed 10 years ago by jdemeyer

  • Summary changed from Add back functionality that was inadvertantly deleted from Sage to Restore --grep and --grepdoc command line options

comment:8 Changed 10 years ago by jdemeyer

  • Merged in set to sage-5.0.beta6
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.