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
Option to limit search result in history magic command #2404
Conversation
@@ -16,10 +16,13 @@ | |||
# Stdlib | |||
import os | |||
from io import open as io_open | |||
from argparse import Action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you import it from IPython.external ?
otherwise it fails on python 2.6
I didn't fully try, but looks ok to me once the small small comment I made is fixed. |
What is the new feature here? i.e., what |
@@ -27,16 +30,75 @@ | |||
# Magics class implementation | |||
#----------------------------------------------------------------------------- | |||
|
|||
|
|||
class HistoryArgLimitAction(Action): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A custom action is probably overkill. It's probably easier to just do
_unspecified = object()
# ...
@magic_arguments.argument(
'-l', dest='limit', type=int, nargs='?', default=_unspecified,
...
)
# ...
def history(self, line):
#...
if args.limit is None:
args.limit = 10
elif args.limit is _unspecified:
args.limit = None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree with @bfroehle on this one.
@bfroehle You can limit history search result using
|
This does not pass the test on python 2.6 because of argparse that should be imported from IPython external where we do the check of wether system argparse exist and load the one we ship if it does not. |
@Carreau Thanks, I noticed your first comment. I just don't have time to fix it. I should have told you that I acknowledged it. |
No problem, I just now that when discussion start on another topic, at least I, tend to forgot the things I have to fix in previous messages. |
Fixed |
Applied the suggestion by @bfroehle to not use the custom action. |
Hi, I re-read quickly and didn't saw anything wrong. |
seen as 'get_ipython().magic("%%cd /")' instead of '%%cd /'. | ||
""") | ||
@argument( | ||
'-f', dest='filename', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this missing nargs=1 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nargs=1
is default behavior for optional argument
In [4]:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--filename')
parser.add_argument('positional')
vars(parser.parse_args(['--filename', 'a', 'b']))
Out [4]:
{'filename': 'a', 'positional': 'b'}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it works that way:
% ./ipython.py -c '%history -f out.log -g import' && head out.log
9/2: import pylab
9/3: import numpy
10/1: import numpy
12/1: import numpy
13/1: import pylab
14/1: import pylab
15/1: import numpy
17/11: ';'.join(__IP.complete('''import'''))
17/12: import numpy
17/13: import sys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, my bad. :/ You are correct.
I think there might be a little bug with |
Option to limit search result in history magic command
Option to limit search result in history magic command
To use the new limit option introduced in #2393.
Diff is rather big for what it really does because I need argparse and custom action to parse argument without changing other semantics.
BTW probably 3e6f57d (magic_arguments.py refactoring) is not needed. I just couldn't stand introducing duplicated code. But removing it should not change the functionality.