question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

f2py doesn't update .mod file

See original GitHub issue

Hello,

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:closed
  • Created 9 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
bilderbuchicommented, Nov 19, 2021

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.

0reactions
HaoZekecommented, Nov 18, 2021

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 --> the mod 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:

Program units are the fundamental components of a Fortran program. A program unit is a main program, an external subprogram, a module, a submodule, or a block data program unit

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found