Skip to content
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

Add 'quiet' option to suppress screen output during %prun calls, edited dochelp #1210

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 22 additions & 19 deletions IPython/core/magic.py
Expand Up @@ -92,7 +92,7 @@ def needs_local_scope(func):
func.needs_local_scope = True
return func


# Used for exception handling in magic_edit
class MacroToEdit(ValueError): pass

Expand Down Expand Up @@ -1314,7 +1314,7 @@ def magic_prun(self, parameter_s ='',user_mode=1,
object has all the information about the profile in it, and you can
later use it for further analysis or in other functions.

-s <key>: sort profile by given key. You can provide more than one key
-s <key>: sort profile by given key. You can provide more than one key
by using the option several times: '-s key1 -s key2 -s key3...'. The
default sorting key is 'time'.

Expand Down Expand Up @@ -1360,6 +1360,8 @@ def magic_prun(self, parameter_s ='',user_mode=1,
is generated by a call to the dump_stats() method of profile
objects. The profile is still shown on screen.

-q: suppress output to the screen. Best used with -T or -D above.

If you want to run complete programs under the profiler's control, use
'%run -p [prof_opts] filename.py [args to program]' where prof_opts
contains profiler specific options as described here.
Expand All @@ -1374,7 +1376,7 @@ def magic_prun(self, parameter_s ='',user_mode=1,
parameter_s = parameter_s.replace('"',r'\"').replace("'",r"\'")

if user_mode: # regular user call
opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:',
opts,arg_str = self.parse_options(parameter_s,'D:l:rs:T:q',
list_all=1)
namespace = self.shell.user_ns
else: # called to run a program by %run -p
Expand Down Expand Up @@ -1438,7 +1440,8 @@ def magic_prun(self, parameter_s ='',user_mode=1,
output = stdout_trap.getvalue()
output = output.rstrip()

page.page(output)
if not opts.has_key('q'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The has_key method is deprecated - we should use if 'q' not in opts instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing it to if not 'q' in opts is fine by me- i initially coded it like
this, and then noticed that the 'r' option is parsed like this, so I
changed it to match. We should probably change both.

I can double check and look for extraneous whitespace.

What is the best way to proceed? (I'm new to this- first contrib!) Do I
recommit and then do another pull request?

cheers,

ag

On Tue, Dec 27, 2011 at 07:23, Thomas <
reply@reply.github.com

wrote:

@@ -1438,7 +1440,8 @@ def magic_prun(self, parameter_s ='',user_mode=1,
output = stdout_trap.getvalue()
output = output.rstrip()

  •    page.page(output)
    
  •    if not opts.has_key('q'):
    

The has_key method is deprecated - we should use if 'q' not in opts
instead.


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/1210/files#r315482

Andrew Giessel, PhD

Department of Neurobiology, Harvard Medical School
220 Longwood Ave Boston, MA 02115
ph: 617.432.7971 email: andrew_giessel@hms.harvard.edu

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, some of the older code was written like that, and hasn't been updated. We're slowly updating it as we revisit it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, missed your question. Just add another commit after this one, and push it to the same branch (we usually make a feature branch, rather than working on master). The pull request automatically updates when you add commits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to make a new PR - any changes to the branch associated with this PR (master) will be reflected here. You can even remove/edit commits and replace them with a force-push (push -f).

page.page(output)
print sys_exit,

dump_file = opts.D[0]
Expand Down Expand Up @@ -2175,11 +2178,11 @@ def magic_loadpy(self, arg_s):
linesource = fileobj.read().decode('utf-8', 'replace').splitlines()
else:
fileobj = linesource = open(arg_s)

# Strip out encoding declarations
lines = [l for l in linesource if not _encoding_declaration_re.match(l)]
fileobj.close()

self.set_next_input(os.linesep.join(lines))

def _find_edit_target(self, args, opts, last_call):
Expand Down Expand Up @@ -3332,7 +3335,7 @@ def magic_gui(self, parameter_s=''):
%gui gtk # enable PyGTK event loop integration
%gui tk # enable Tk event loop integration
%gui OSX # enable Cocoa event loop integration
# (requires %matplotlib 1.1)
# (requires %matplotlib 1.1)
%gui # disable all event loop integration

WARNING: after any of these has been called you can simply create
Expand Down Expand Up @@ -3367,7 +3370,7 @@ def magic_install_profiles(self, s):
"Use `ipython profile list` to view available profiles.",
"Requesting a profile with `ipython profile create <name>`",
"or `ipython --profile=<name>` will start with the bundled",
"profile of that name if it exists."
"profile of that name if it exists."
])

def magic_install_default_config(self, s):
Expand Down Expand Up @@ -3406,7 +3409,7 @@ def magic_pylab(self, s):

# enable SVG figures, necessary for SVG+XHTML export in the qtconsole
In [1]: %config InlineBackend.figure_format = 'svg'

# change the behavior of closing all figures at the end of each
# execution (cell), or allowing reuse of active figures across
# cells:
Expand Down Expand Up @@ -3572,21 +3575,21 @@ def magic_notebook(self, s):

def magic_config(self, s):
"""configure IPython

%config Class[.trait=value]

This magic exposes most of the IPython config system. Any
Configurable class should be able to be configured with the simple
line::

%config Class.trait=value

Where `value` will be resolved in the user's namespace, if it is an
expression or variable name.

Examples
--------

To see what classes are availabe for config, pass no arguments::

In [1]: %config
Expand Down Expand Up @@ -3640,7 +3643,7 @@ def magic_config(self, s):
# this magic, as their presence is just noise:
configurables = [ c for c in self.configurables if c.__class__.class_traits(config=True) ]
classnames = [ c.__class__.__name__ for c in configurables ]

line = s.strip()
if not line:
# print available configurable names
Expand All @@ -3660,14 +3663,14 @@ def magic_config(self, s):
return
elif '=' not in line:
raise UsageError("Invalid config statement: %r, should be Class.trait = value" % line)


# otherwise, assume we are setting configurables.
# leave quotes on args when splitting, because we want
# unquoted args to eval in user_ns
cfg = Config()
exec "cfg."+line in locals(), self.user_ns

for configurable in configurables:
try:
configurable.update_config(cfg)
Expand Down