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

Options.emit_code_comments is not used #2740

Open
yuriescl opened this Issue Nov 30, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@yuriescl

yuriescl commented Nov 30, 2018

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.

@scoder

This comment has been minimized.

Contributor

scoder commented Nov 30, 2018

Hmm, right. I think we should add a warning when users disable it and remove it from the docs. It's been non-functional for a while now.

@scoder

This comment has been minimized.

Contributor

scoder commented Nov 30, 2018

Thanks for the report and the investigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment