Skip to content

numpy.f2py.compile removed since NumPy 2.0.0 causing test failuresΒ #103

@kanamesasaki

Description

@kanamesasaki

Describe the bug
numpy.f2py.compile function has been removed since NumPy 2.0.0 (https://numpy.org/doc/stable/release/2.0.0-notes.html), causing the python/Fortran test code in psychrolib to fail. The following error message is displayed when executing "pytest -v -s"

ImportError while loading conftest '/workspaces/psychrolib/tests/conftest.py'.
tests/conftest.py:26: in <module>
    f2py.compile(source , modulename='psychrolib_fortran', extension='.f90')
/usr/local/lib/python3.11/site-packages/numpy/f2py/__init__.py:82: in __getattr__
    raise AttributeError("module {!r} has no attribute "
E   AttributeError: module 'numpy.f2py' has no attribute 'compile'

To Reproduce
Steps to reproduce the behavior:

  1. see Environment for the installed packages
  2. execute: python -m pytest -v -s

Environment:

  • Docker container based on python:3.11-slim
  • Installed python packages:
    cffi 1.17.1
    charset-normalizer 3.4.0
    iniconfig 2.0.0
    numpy 2.2.0
    packaging 24.2
    pip 24.0
    pluggy 1.5.0
    PsychroLib 2.5.0 /psychrolib/src/python
    pycparser 2.22
    pytest 8.3.4
    setuptools 65.5.1
    wheel 0.45.1

Additional comment
A possible workaround is to use subprocess.run to directly call f2py
Example:

import subprocess

PATH_TO_LIB = Path(__file__).parents[1] / 'src' / 'fortran' / 'psychrolib.f90'
subprocess.run(['f2py', '-c', '-m', 'psychrolib_fortran', str(PATH_TO_LIB)], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions