f2py doesn't update .mod file
See original GitHub issueHello,
When
f2py -c foo.f90 -m bar
and a foo.mod exists. F2py doesn’t update the .mod file, and what worse, it used the .mod file implicitly. If I changed something in the .f90 file, the .mod file will not be consistent with the .f90 file.
The .mod file is an intermediate file, as the same as .o, so if we don’t use it explicitly on a command line, it should be regenerated, at least, it should not be used.
The module variable with parameter
attribute will not be written in the .o file, but in the .mod file. I have just encounter an odd bug because f2py implicitly used inconsistent .mod file.
Issue Analytics
- State:
- Created 9 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
python - F2PY doesn't find a module - Stack Overflow
If I put the python module code in the same directory as where the mod files are it produces same error message. Here...
Read more >[Numpy-discussion] Do not understand what f2py is reporting
One is a > Fortran 77 subroutine (see file gravity_derivs.f) that calls ... If `f2py` doesn't generate the .mod files you could at...
Read more >Using F2PY — NumPy v1.23 Manual
If <fortran files> does not contain a signature file, then an extension module is constructed by scanning all Fortran source codes for routine...
Read more >Using F2PY — NumPy v1.17 Manual
If <fortran files> does not contain a signature file, then an extension module is constructed by scanning all Fortran source codes for routine ......
Read more >Parsing contents of .mod files using Python - Fortran Discourse
Mod files are definitely not the way to go if you need to support multiple compilers. In that case all you can do...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for the illuminating and extensive reply, I’m gonna bookmark that 😄
I think in my mental model until now, the compiler created the .mod and .o files during compilation (so I mentally filed them both under “object files”), and uses both during linking. I had thought that that aligned with what you point out in the Fortran wiki – compiling generates a .mod file, linking uses – in this sense I don’t see the difference between a .mod and a .o file. What I did not realise is that even the compiler does not always regenerate a .mod if already present (gfortran seems to detect an interface change and regenerate then).
Luckily, I’ll be using f2py as part of a build system, so if any regeneration needs to be done, I’ll let cmake figure it out. 😄 I just need to be careful during manual experiments.
Build systems, as you mentioned have their own logic for figuring out when to regenerate
.mod
files, as you noticed it is typically on the basis of when the interface changes.Unfortunately making
np.distutils
include such logic feels a bit out of scope.np.distutils
proxies over to a compiler command, not to a build system (though support for different build systems is planned) at which point this will be fixed.EDIT: The
mod
file contains all the code in a module, even if that is separated across source files --> themod
is the unit of program use defined in the standard.Consider section 5.2.4 of the J3/SD-007 Fortran 202X interpretation document. Crucially the standard nowhere defines any source files and defines a program as: