-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
[BUG] f2py unable to compile extension module if C sources are generated first #14960
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
Comments
Thanks for the report @melissawm. We're talking about this page right: https://numpy.org/devdocs/f2py/getting-started.html? I can confirm what you're seeing:
However, the doc page does @pearu any thoughts? |
I am not sure which docs say this but the following is wrong:
Use one of the followinig options:
or
These examples are minimal in the sense that if anything is skipped in the above f2py command lines then a failure is expected. |
Actually, I'm talking about this page: https://numpy.org/devdocs/f2py/usage.html There, in items 2 and 3, we have the following: Item 2 is to run
f2py -c <options> <fortran files> \
[[ only: <fortran functions> : ] \
[ skip: <fortran functions> : ]]... \
[ <fortran/c source files> ] [ <.o, .a, .so files> ]
From what you said, I understand we're not supposed to use the Thanks for the input! |
This page describes the While f2py can be used for creating extension modules that wrap also C functions (contained in One should distinguish the |
I'm adding the explanation from @pearu above to the docs, if you have any other ideas let me know. Thank you all for your coments! Feel free to close the issue (or should I do it only after that PR gets accepted?) |
I suggest closing when the PR that tackles this issue is accepted. |
+1 @melissawm you can also add |
* Updated f2py "Getting Started" doc to python3. * WIP: updating f2py docs to python3: intro to python-usage done. * WIP: updated "Scalar Arguments" session of python-usage.rst * WIP: updated "String arguments" section of python-usage.rst. TODO check for string bug here. * WIP: updated "Array arguments" section of python-usage.rst * WIP: updated "Callback arguments" section in python-usage.rst * WIP: updated sections "Common blocks" and "F90 module data" from python-usage.rst * Finished update of python-usage.rst * WIP: updating usage.rst * PEP8 fix for equal sign and added note about building extension modules. * Finished update of usage.rst * Remove future imports from f2py example. * Fixed typos. * Fixed typo. * Updated f2py "Getting Started" doc to python3. * Finished update of python-usage.rst * Finished update of usage.rst * Fixed typos. * Addressing comments on PR. * Addressing PR review; closes gh-14812; fixes gh-14919; closes gh-14960; fixes gh-14865; fixes gh-14862 * Restore names of common block items.
I ran into this again when working on the scipy.linalg Meson build, so let me document how this works before I forget it again (example for
Obviously |
To make it more annoying: sometimes a Having the number of generated output files depend on file contents rather than build flags or file extension is not a good thing. Not sure what the best way to avoid it is though, short of renaming F77 files from |
At least we should document the above. The closest is https://numpy.org/devdocs/f2py/usage.html#numpy.f2py.run_main, which says "returns a dictionary containing information on generated modules and their dependencies on source files" with an example. I didn't get this on a first read of that whole "Using F2PY" page though. @pearu if you have any idea on how to make output files predictable based on input files and command without actually running |
@rgommers one option to achieve predictability would be to always generate the Otherwise, FYI, the files are generated whenever the wrapped routines contain Fortran functions plus some other cases like wrapping F90 module routines. |
That sounds like a good idea. Not urgent, but if it's easy to do at some point during other f2py work, that would be nice. |
This is useful for similar reasons as `numpy.get_include`, see numpy#14960 (comment)
This is useful for similar reasons as `numpy.get_include`, see numpy#14960 (comment)
Following the docs/User Guide from f2py, if one wants to generate a
.c
file with the extension module one must doto generate a
fib1module.c
file. This works. However, the next step to build the extension module to be importable in Python, according to the docs, isHowever, this fails for me with the following messages:
Doing
seems to work (this is the location of my
fortranobject.h
file), but then the module is not importable:TL; DR: Is this a bug, or something we are not supposed to do (generate
.c
sources and then build the extension module in a separate step)?The text was updated successfully, but these errors were encountered: