On Tue, Apr 12, 2016 at 10:27 AM, Jeroen Demeyer <jdeme...@cage.ugent.be> wrote: > On 2016-04-12 10:16, Erik Bray wrote: >> >> That said, I >> think it makes more sense for cythonize() to read the distutils >> options from the C source instead of the Cython source, though in >> practice I don't know if it's a worthwhile change or not. > > > I don't quite get what you mean. The C file is only read by distutils (which > compiles the .c files to .so), not by Cython (which compiles the .pyx files > to .c).
Right. What I'm saying is that when you call cythonize() the output is a list of Extension objects, which include instructions for how to distutils should compile the C sources (in this case, the define_macros attribute in particular). cythonize(), at some step along the way, reads "# distutils:" directives directly out of the .pyx sources, but then applies them to the Extension object representing the C sources to be compiled. What I'm suggesting is that there should be a clearer separation--the Cython compiler should generate the C sources first--including outputting their JSON metadata which may include some distutils directives, but otherwise remain completely agnostic as to how the C sources will ultimately be compiled (currently this *is* true insofar as how Cython's compile() works--the confusion is in cythonize()). After the Cython sources have been compiled to C sources, the cythonize() function should then inspect the resulting C sources (which are given explicitly in CompilerResult objects, which are currently ignored by cythonize()) and use the metadata in the C sources to tell distutils what to do with them. The Cython sources shouldn't be consulted any further at this point. It's a subtle difference which currently wouldn't affect the end result. The reason I thought of this is that I wanted to be able to set "distutils" directives directly in the C sources without them needing to be manually declared in the Cython sources. But even without that use case it's a clearer separation of concerns. Erik _______________________________________________ cython-devel mailing list cython-devel@python.org https://mail.python.org/mailman/listinfo/cython-devel