Setting Cython.Compiler.Options.emit_code_comments = False does not work when generating .c code from .py files.
from distutils.core import setup
from Cython.Distutils import build_ext
from Cython.Compiler import Options
from Cython.Build import cythonize
Options.emit_code_comments = False # not being applied
...
setup(
ext_modules=cythonize("mymodule.py")
cmdclass={'build_ext': build_ext}
)
The generated .c file contains the code comments, which should be disabled since emit_code_comments is set to false.
Code.py:1856:
def emit_marker(self):
pos, trace = self.last_pos
self.last_marked_pos = pos
self.last_pos = None
self.write("\n")
if self.code_config.emit_code_comments:
self.indent()
self.write("/* %s */\n" % self._build_marker(pos))
self.code_config.emit_code_comments is True even when setting Options.emit_code_comments to False.
The documentation says it's an option but actually it's currently a compiler directive. Sounds like there was going to be a transition from being an option to being a compiler directive, but the option variable is still there and not being used.
Here's where the value is passed to the code config. It's obtained from the directives, not the Options.
ModuleNode.py:53:
return Code.CCodeConfig(
emit_linenums=emit_linenums,
emit_code_comments=env.directives['emit_code_comments'],
c_line_in_traceback=options.c_line_in_traceback)
So I tried to set emit_code_comments as a compiler directive instead, and it worked as expected (no comments added to the .c file):
from distutils.core import setup
from Cython.Distutils import build_ext
from Cython.Compiler import Options
from Cython.Build import cythonize
compiler_directives = Options.get_directive_defaults()
compiler_directives["emit_code_comments"] = False # works
...
setup(
ext_modules=cythonize("mymodule.py",
compiler_directives=compiler_directives))
cmdclass={'build_ext': build_ext}
)
Tested in Cython 0.29.1.
Setting
Cython.Compiler.Options.emit_code_comments = Falsedoes not work when generating .c code from .py files.The generated .c file contains the code comments, which should be disabled since
emit_code_commentsis set to false.Code.py:1856:
self.code_config.emit_code_commentsisTrueeven when settingOptions.emit_code_commentstoFalse.The documentation says it's an option but actually it's currently a compiler directive. Sounds like there was going to be a transition from being an option to being a compiler directive, but the option variable is still there and not being used.
Here's where the value is passed to the code config. It's obtained from the directives, not the Options.
ModuleNode.py:53:
So I tried to set
emit_code_commentsas a compiler directive instead, and it worked as expected (no comments added to the .c file):Tested in Cython 0.29.1.