@@ -288,13 +288,10 @@ def cmd_wrapper(instance, cmdline):
288
288
argparser .prog = func .__name__ [3 :]
289
289
290
290
# put the help message in the method docstring
291
- funcdoc = func .__doc__
292
- if funcdoc :
293
- funcdoc += '\n '
294
- else :
295
- # if it's None, make it an empty string
296
- funcdoc = ''
297
- cmd_wrapper .__doc__ = '{}{}' .format (funcdoc , argparser .format_help ())
291
+ if func .__doc__ :
292
+ argparser .description = func .__doc__
293
+
294
+ cmd_wrapper .__doc__ = argparser .format_help ()
298
295
return cmd_wrapper
299
296
return arg_decorator
300
297
@@ -315,13 +312,10 @@ def cmd_wrapper(instance, cmdline):
315
312
argparser .prog = func .__name__ [3 :]
316
313
317
314
# put the help message in the method docstring
318
- funcdoc = func .__doc__
319
- if funcdoc :
320
- funcdoc += '\n '
321
- else :
322
- # if it's None, make it an empty string
323
- funcdoc = ''
324
- cmd_wrapper .__doc__ = '{}{}' .format (funcdoc , argparser .format_help ())
315
+ if func .__doc__ :
316
+ argparser .description = func .__doc__
317
+
318
+ cmd_wrapper .__doc__ = argparser .format_help ()
325
319
return cmd_wrapper
326
320
return arg_decorator
327
321
@@ -1341,7 +1335,7 @@ def show(self, args, parameter):
1341
1335
else :
1342
1336
raise LookupError ("Parameter '%s' not supported (type 'show' for list of parameters)." % param )
1343
1337
1344
- set_parser = argparse .ArgumentParser (description = 'show or set value of a parameter' )
1338
+ set_parser = argparse .ArgumentParser ()
1345
1339
set_parser .add_argument ('-a' , '--all' , action = 'store_true' , help = 'display read-only settings as well' )
1346
1340
set_parser .add_argument ('-l' , '--long' , action = 'store_true' , help = 'describe function of parameter' )
1347
1341
set_parser .add_argument ('settable' , nargs = '*' , help = '[param_name] [value]' )
@@ -1693,13 +1687,11 @@ def do_ipy(self, arg):
1693
1687
exit_msg = 'Leaving IPython, back to {}' .format (sys .argv [0 ])
1694
1688
embed (banner1 = banner , exit_msg = exit_msg )
1695
1689
1696
- history_parser = argparse .ArgumentParser (
1697
- description = 'run, edit, and save previously entered commands' ,
1698
- formatter_class = argparse .RawTextHelpFormatter ,
1699
- )
1690
+ history_parser = argparse .ArgumentParser (formatter_class = argparse .RawTextHelpFormatter )
1700
1691
history_parser_group = history_parser .add_mutually_exclusive_group ()
1701
1692
history_parser_group .add_argument ('-r' , '--run' , action = 'store_true' , help = 'run selected history items' )
1702
- history_parser_group .add_argument ('-e' , '--edit' , action = 'store_true' , help = 'edit and then run selected history items' )
1693
+ history_parser_group .add_argument ('-e' , '--edit' , action = 'store_true' ,
1694
+ help = 'edit and then run selected history items' )
1703
1695
history_parser_group .add_argument ('-o' , '--output-file' , metavar = 'FILE' , help = 'output to file' )
1704
1696
history_parser .add_argument ('-s' , '--script' , action = 'store_true' , help = 'script format; no separation lines' )
1705
1697
_history_arg_help = """empty all history items
@@ -1711,8 +1703,8 @@ def do_ipy(self, arg):
1711
1703
1712
1704
@with_argument_parser (history_parser )
1713
1705
def do_history (self , args ):
1714
- # If an argument was supplied, then retrieve partial contents of the
1715
- # history
1706
+ """View, run, edit, and save previously entered commands."""
1707
+ # If an argument was supplied, then retrieve partial contents of the history
1716
1708
cowardly_refuse_to_run = False
1717
1709
if args .arg :
1718
1710
# If a character indicating a slice is present, retrieve
@@ -1735,7 +1727,8 @@ def do_history(self, args):
1735
1727
if args .run :
1736
1728
if cowardly_refuse_to_run :
1737
1729
self .perror ("Cowardly refusing to run all previously entered commands." , traceback_war = False )
1738
- self .perror ("If this is what you want to do, specify '1:' as the range of history." , traceback_war = False )
1730
+ self .perror ("If this is what you want to do, specify '1:' as the range of history." ,
1731
+ traceback_war = False )
1739
1732
else :
1740
1733
for runme in history :
1741
1734
self .pfeedback (runme )
@@ -1744,20 +1737,20 @@ def do_history(self, args):
1744
1737
elif args .edit :
1745
1738
fd , fname = tempfile .mkstemp (suffix = '.txt' , text = True )
1746
1739
with os .fdopen (fd , 'w' ) as fobj :
1747
- for cmd in history :
1748
- fobj .write ('{}\n ' .format (cmd ))
1740
+ for command in history :
1741
+ fobj .write ('{}\n ' .format (command ))
1749
1742
try :
1750
1743
os .system ('"{}" "{}"' .format (self .editor , fname ))
1751
1744
self .do_load (fname )
1752
- except :
1745
+ except Exception :
1753
1746
raise
1754
1747
finally :
1755
1748
os .remove (fname )
1756
1749
elif args .output_file :
1757
1750
try :
1758
1751
with open (os .path .expanduser (args .output_file ), 'w' ) as fobj :
1759
- for cmd in history :
1760
- fobj .write ('{}\n ' .format (cmd ))
1752
+ for command in history :
1753
+ fobj .write ('{}\n ' .format (command ))
1761
1754
plural = 's' if len (history ) > 1 else ''
1762
1755
self .pfeedback ('{} command{} saved to {}' .format (len (history ), plural , args .output_file ))
1763
1756
except Exception as e :
@@ -1770,7 +1763,6 @@ def do_history(self, args):
1770
1763
else :
1771
1764
self .poutput (hi .pr ())
1772
1765
1773
-
1774
1766
@with_argument_list
1775
1767
def do_edit (self , arglist ):
1776
1768
"""Edit a file or command in a text editor.
@@ -1876,7 +1868,6 @@ def do_load(self, arglist):
1876
1868
1877
1869
self ._script_dir .append (os .path .dirname (expanded_path ))
1878
1870
1879
-
1880
1871
@staticmethod
1881
1872
def is_text_file (file_path ):
1882
1873
"""
0 commit comments