Skip to content

don't use cythonize in setup.py#379

Open
jswhit wants to merge 6 commits intomasterfrom
no_cythonize
Open

don't use cythonize in setup.py#379
jswhit wants to merge 6 commits intomasterfrom
no_cythonize

Conversation

@jswhit
Copy link
Collaborator

@jswhit jswhit commented Oct 14, 2025

@neutrinoceros hopefully this will help with PR #372

Copy link
Contributor

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ping. I don't understand how this is supposed to work yet, and with a red CI I'm not yet convinced it should.

setup.py Outdated
e.cython_directives = {'language_level': "3"}
e.compiler_directives = COMPILER_DIRECTIVES
# remove _cftime.c file if it exists, so cython will recompile _cftime.pyx.
if len(sys.argv) >= 2:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what the intention for this check is. Seems to me there are many ways to end up executing this code with completely different commands so I'm a bit unconfortable with it. Can you explain ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is that anytime you run setup.py, you will want to recompile _cftime.pyx. If there is a left-over _cftime.c file, then cython won't run, so this code removes it if it exists.

Copy link
Collaborator Author

@jswhit jswhit Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the setuptools docs:

"When your Cython extension modules are declared using the setuptools.Extension class, setuptools will detect at build time whether Cython is installed or not.

If Cython is present, then setuptools will use it to build the .pyx files. Otherwise, setuptools will try to find and compile the equivalent .c files (instead of .pyx). These files can be generated using the cython command line tool."

so you don't really need to use cythonize explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea is that anytime you run setup.py, you will want to recompile _cftime.pyx

but why would this be captured specifically by the number of CLI arguments ? This is what I'm having a hard time wrapping my head around.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from netcdf4-python - I think it can be removed.

@jswhit
Copy link
Collaborator Author

jswhit commented Oct 15, 2025

Don't know why the wheels fail some tests

@ocefpaf
Copy link
Contributor

ocefpaf commented Feb 24, 2026

Don't know why the wheels fail some tests

I can reproduce that failure locally and I get significantly different _cftime.c when not calling cythonize:

https://gist.github.com/ocefpaf/086f5540ca9705dc111509b02b282801

include_dirs=[numpy.get_include(),])]
for e in ext_modules:
e.cython_directives = {'language_level': "3"}
e.compiler_directives = COMPILER_DIRECTIVES
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this part is being ignored. When I add #cython: c_api_binop_methods=True to the top of the pyx everything works as expected.

@ocefpaf ocefpaf mentioned this pull request Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants