Commit 70d77032 authored by realead's avatar realead Committed by Stefan Behnel

Replace "--annotate=fullc" with "--annotate-fullc" to fix a regression from GH-2858 (GH-2986)

parent 37a13a55
...@@ -52,7 +52,7 @@ Features added ...@@ -52,7 +52,7 @@ Features added
* PEP-479 (``generator_stop``) is now enabled by default with language level 3. * PEP-479 (``generator_stop``) is now enabled by default with language level 3.
(Github issue #2580) (Github issue #2580)
* Code annotation accepts a new debugging argument ``--annotate=fullc`` that * Code annotation accepts a new debugging argument ``--annotate-fullc`` that
will include the complete syntax highlighted C file in the HTML output. will include the complete syntax highlighted C file in the HTML output.
(Github issue #2855) (Github issue #2855)
......
...@@ -168,10 +168,11 @@ def create_args_parser(): ...@@ -168,10 +168,11 @@ def create_args_parser():
help='use Python 3 syntax mode by default') help='use Python 3 syntax mode by default')
parser.add_argument('--3str', dest='language_level', action='store_const', const='3str', parser.add_argument('--3str', dest='language_level', action='store_const', const='3str',
help='use Python 3 syntax mode by default') help='use Python 3 syntax mode by default')
parser.add_argument('-a', '--annotate', nargs='?', const='default', type=str, choices={'default','fullc'}, parser.add_argument('-a', '--annotate', action='store_const', const='default', dest='annotate',
help='Produce a colorized HTML version of the source. ' help='Produce a colorized HTML version of the source.')
'Use --annotate=fullc to include entire ' parser.add_argument('--annotate-fullc', action='store_const', const='fullc', dest='annotate',
'generated C/C++-code.') help='Produce a colorized HTML version of the source '
'which includes entire generated C/C++-code.')
parser.add_argument('-x', '--exclude', metavar='PATTERN', dest='excludes', parser.add_argument('-x', '--exclude', metavar='PATTERN', dest='excludes',
action='append', default=[], action='append', default=[],
help='exclude certain file patterns from the compilation') help='exclude certain file patterns from the compilation')
......
...@@ -179,11 +179,13 @@ class CythonMagics(Magics): ...@@ -179,11 +179,13 @@ class CythonMagics(Magics):
@magic_arguments.magic_arguments() @magic_arguments.magic_arguments()
@magic_arguments.argument( @magic_arguments.argument(
'-a', '--annotate', nargs='?', const="default", type=str, '-a', '--annotate', action='store_const', const='default', dest='annotate',
choices={"default","fullc"}, help="Produce a colorized HTML version of the source."
help="Produce a colorized HTML version of the source. " )
"Use --annotate=fullc to include entire " @magic_arguments.argument(
"generated C/C++-code." '--annotate-fullc', action='store_const', const='fullc', dest='annotate',
help="Produce a colorized HTML version of the source "
"which includes entire generated C/C++-code."
) )
@magic_arguments.argument( @magic_arguments.argument(
'-+', '--cplus', action='store_true', default=False, '-+', '--cplus', action='store_true', default=False,
......
...@@ -16,11 +16,11 @@ class TestCythonizeArgsParser(TestCase): ...@@ -16,11 +16,11 @@ class TestCythonizeArgsParser(TestCase):
are_none = ['language_level', 'annotate', 'build', 'build_inplace', 'force', 'quiet', 'lenient', 'keep_going', 'no_docstrings'] are_none = ['language_level', 'annotate', 'build', 'build_inplace', 'force', 'quiet', 'lenient', 'keep_going', 'no_docstrings']
for opt_name in empty_containers: for opt_name in empty_containers:
if len(getattr(options, opt_name))!=0 and (not opt_name in skip): if len(getattr(options, opt_name))!=0 and (not opt_name in skip):
self.assertEqual(opt_name,"") self.assertEqual(opt_name,"", msg="For option "+opt_name)
return False return False
for opt_name in are_none: for opt_name in are_none:
if (getattr(options, opt_name) is not None) and (not opt_name in skip): if (getattr(options, opt_name) is not None) and (not opt_name in skip):
self.assertEqual(opt_name,"") self.assertEqual(opt_name,"", msg="For option "+opt_name)
return False return False
if options.parallel!=3 and (not 'parallel' in skip): if options.parallel!=3 and (not 'parallel' in skip):
return False return False
...@@ -243,17 +243,24 @@ class TestCythonizeArgsParser(TestCase): ...@@ -243,17 +243,24 @@ class TestCythonizeArgsParser(TestCase):
self.assertEqual(options.annotate, 'default') self.assertEqual(options.annotate, 'default')
def test_annotate_fullc(self): def test_annotate_fullc(self):
options, args = self.parse_args(['--annotate=fullc']) options, args = self.parse_args(['--annotate-fullc'])
self.assertFalse(args) self.assertFalse(args)
self.assertTrue(self.are_default(options, ['annotate'])) self.assertTrue(self.are_default(options, ['annotate']))
self.assertEqual(options.annotate, 'fullc') self.assertEqual(options.annotate, 'fullc')
def test_annotate_fullc(self): def test_annotate_and_positional(self):
options, args = self.parse_args(['-a=default']) options, args = self.parse_args(['-a', 'foo.pyx'])
self.assertFalse(args) self.assertEqual(args, ['foo.pyx'])
self.assertTrue(self.are_default(options, ['annotate'])) self.assertTrue(self.are_default(options, ['annotate']))
self.assertEqual(options.annotate, 'default') self.assertEqual(options.annotate, 'default')
def test_annotate_and_optional(self):
options, args = self.parse_args(['-a', '--3str'])
self.assertFalse(args)
self.assertTrue(self.are_default(options, ['annotate', 'language_level']))
self.assertEqual(options.annotate, 'default')
self.assertEqual(options.language_level, '3str')
def test_exclude_short(self): def test_exclude_short(self):
options, args = self.parse_args(['-x', '*.pyx']) options, args = self.parse_args(['-x', '*.pyx'])
self.assertFalse(args) self.assertFalse(args)
......
...@@ -226,14 +226,14 @@ x = sin(0.0) ...@@ -226,14 +226,14 @@ x = sin(0.0)
def test_cython_annotate_default(self): def test_cython_annotate_default(self):
ip = self._ip ip = self._ip
html = ip.run_cell_magic('cython', '--a=default', code) html = ip.run_cell_magic('cython', '-a', code)
# somewhat brittle way to differentiate between annotated htmls # somewhat brittle way to differentiate between annotated htmls
# with/without complete source code: # with/without complete source code:
self.assertTrue(AnnotationCCodeWriter.COMPLETE_CODE_TITLE not in html.data) self.assertTrue(AnnotationCCodeWriter.COMPLETE_CODE_TITLE not in html.data)
def test_cython_annotate_complete_c_code(self): def test_cython_annotate_complete_c_code(self):
ip = self._ip ip = self._ip
html = ip.run_cell_magic('cython', '--a=fullc', code) html = ip.run_cell_magic('cython', '--annotate-fullc', code)
# somewhat brittle way to differentiate between annotated htmls # somewhat brittle way to differentiate between annotated htmls
# with/without complete source code: # with/without complete source code:
self.assertTrue(AnnotationCCodeWriter.COMPLETE_CODE_TITLE in html.data) self.assertTrue(AnnotationCCodeWriter.COMPLETE_CODE_TITLE in html.data)
...@@ -34,7 +34,8 @@ Options: ...@@ -34,7 +34,8 @@ Options:
-D, --no-docstrings Strip docstrings from the compiled module. -D, --no-docstrings Strip docstrings from the compiled module.
-a, --annotate Produce a colorized HTML version of the source. -a, --annotate Produce a colorized HTML version of the source.
Use --annotate=fullc to include entire generated C/C++-code. --annotate-fullc Produce a colorized HTML version of the source which
includes entire generated C/C++-code.
--annotate-coverage <cov.xml> Annotate and include coverage information from cov.xml. --annotate-coverage <cov.xml> Annotate and include coverage information from cov.xml.
--line-directives Produce #line directives pointing to the .pyx source --line-directives Produce #line directives pointing to the .pyx source
--cplus Output a C++ rather than C file. --cplus Output a C++ rather than C file.
...@@ -129,7 +130,9 @@ def parse_command_line(args): ...@@ -129,7 +130,9 @@ def parse_command_line(args):
elif option in ("-D", "--no-docstrings"): elif option in ("-D", "--no-docstrings"):
Options.docstrings = False Options.docstrings = False
elif option in ("-a", "--annotate"): elif option in ("-a", "--annotate"):
Options.annotate = pop_value('default') Options.annotate = "default"
elif option == "--annotate-fullc":
Options.annotate = "fullc"
elif option == "--annotate-coverage": elif option == "--annotate-coverage":
Options.annotate = True Options.annotate = True
Options.annotate_coverage_xml = pop_value() Options.annotate_coverage_xml = pop_value()
......
...@@ -104,23 +104,23 @@ class CmdLineParserTest(TestCase): ...@@ -104,23 +104,23 @@ class CmdLineParserTest(TestCase):
]) ])
self.assertFalse(Options.annotate) self.assertFalse(Options.annotate)
def test_annotate_simple(self): def test_annotate_short(self):
options, sources = parse_command_line([ options, sources = parse_command_line([
'-a', '-a',
'source.pyx', 'source.pyx',
]) ])
self.assertEqual(Options.annotate, 'default') self.assertEqual(Options.annotate, 'default')
def test_annotate_default(self): def test_annotate_long(self):
options, sources = parse_command_line([ options, sources = parse_command_line([
'--annotate=default', '--annotate',
'source.pyx', 'source.pyx',
]) ])
self.assertEqual(Options.annotate, 'default') self.assertEqual(Options.annotate, 'default')
def test_annotate_fullc(self): def test_annotate_fullc(self):
options, sources = parse_command_line([ options, sources = parse_command_line([
'--annotate=fullc', '--annotate-fullc',
'source.pyx', 'source.pyx',
]) ])
self.assertEqual(Options.annotate, 'fullc') self.assertEqual(Options.annotate, 'fullc')
......
...@@ -621,7 +621,9 @@ You can see them also by typing ```%%cython?`` in IPython or a Jupyter notebook. ...@@ -621,7 +621,9 @@ You can see them also by typing ```%%cython?`` in IPython or a Jupyter notebook.
============================================ ======================================================================================================================================= ============================================ =======================================================================================================================================
-a, --annotate Produce a colorized HTML version of the source. Use ``--annotate=fullc`` to include the complete generated C/C++-code as well. -a, --annotate Produce a colorized HTML version of the source.
--annotate-fullc Produce a colorized HTML version of the source which includes entire generated C/C++-code.
-+, --cplus Output a C++ rather than C file. -+, --cplus Output a C++ rather than C file.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment