hydrogeoscience / pygtide

A Python module and wrapper for ETERNA PREDICT to compute gravitational tides on Earth
Mozilla Public License 2.0
53 stars 19 forks source link

Create wheels including compiled Fortran code with Github Actions #33

Open trichter opened 2 years ago

trichter commented 2 years ago

WIP: Do not merge

I created a Github action to try to solve issue #32. Unfortunately it is not working yet for Windows and MacOS.

trichter commented 2 years ago

Unfortunately I do not know how to make any progress here.

hydrogeoscience commented 2 years ago

Have you seen this: https://github.com/pypa/cibuildwheel

trichter commented 2 years ago

Yes, I have seen this. It's already used via this action:

      - name: Build and test wheels
        uses: pypa/cibuildwheel@2.5.0
trichter commented 2 years ago

On Windows I have seen this error:

error: [Errno 2] No such file or directory: 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-c3jqdxcc\\cp310-win_amd64\\build\\venv\\libs\\python310.def'

Do you know how to fix it?

trichter commented 2 years ago

On MacOS, the problem is that no fortan compiler can be found

    customize Gnu95FCompiler
    Could not locate executable gfortran
    Could not locate executable f95
    customize NAGFCompiler
    customize AbsoftFCompiler
    Could not locate executable f90
    Could not locate executable f77
    customize IBMFCompiler
    Could not locate executable xlf90
    Could not locate executable xlf
    customize IntelFCompiler
    Could not locate executable ifort
    Could not locate executable ifc
    customize GnuFCompiler
    Could not locate executable g77
    customize G95FCompiler
    Could not locate executable g95
    customize PGroupFCompiler
    Could not locate executable pgfortran
    don't know how to compile Fortran code on platform 'posix'

although it appears to be installed:

Running before_build...
  + brew install --verbose gfortran && pip install numpy
  Warning: gcc 11.3.0_2 is already installed and up-to-date.
  To reinstall 11.3.0_2, run:
    brew reinstall gcc
  Collecting numpy
    Downloading numpy-1.21.6-cp37-cp37m-macosx_10_9_x86_64.whl (16.9 MB)
  Installing collected packages: numpy
  Successfully installed numpy-1.21.6
hydrogeoscience commented 2 years ago

Thanks for all your effort. I'll look into https://github.com/hydrogeoscience/pygtide/pull/33#issuecomment-1169781336 soon.

hydrogeoscience commented 2 years ago

"ERROR: Can not executesetup.pysince setuptools is not available in the build environment."

It seems that under Windows you must have setuptools installed: https://pypi.org/project/setuptools/

trichter commented 2 years ago

I squeezed all the trial and error into one commit and rebased this branch. On MacOs I simply got it working by creating a symlink for gfortran pointing to a specific gfortran version.

In Windows for the default setup, everything compiles fine, but something is not working with the linking, because when trying to import the module, the following error occurs:

python -c "import pygtide; pygtide.test(); pygtide.update(); pygtide.test()"
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\runneradmin\AppData\Local\Temp\cibw-run-8dnevi3b\cp37-win_amd64\venv-test\lib\site-packages\pygtide\__init__.py", line 1, in <module>
      from pygtide.core import pygtide
    File "C:\Users\runneradmin\AppData\Local\Temp\cibw-run-8dnevi3b\cp37-win_amd64\venv-test\lib\site-packages\pygtide\core.py", line 93, in <module>
      import pygtide.etpred as etpred
  ImportError: DLL load failed: The specified module could not be found.

When appending the command line flags --compiler=mingw32 --fcompiler=gnu95 to setup.cfg as done for the latest commit:

[build_ext]
compiler=mingw32
fcompiler=gnu95

compiling fails with the error mentioned above:

error: [Errno 2] No such file or directory: 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-c3jqdxcc\\cp310-win_amd64\\build\\venv\\libs\\python310.def'

Here is the software installed in the used Windows image:

https://github.com/actions/virtual-environments/blob/win22/20220626.1/images/win/Windows2022-Readme.md

trichter commented 2 years ago

It seems that under Windows you must have setuptools installed: https://pypi.org/project/setuptools/

Yes, I think when using setup.py installation procedure, setuptools is needed for all platforms.

trichter commented 2 years ago

One step forward? Using setuptools<60 as recommended, with python3.7 its still the missing def file. For python>3.7 a new error popped up:

      File "C:\Users\runneradmin\AppData\Local\Temp\cibw-run-kuns43px\cp310-win_amd64\build\venv\lib\site-packages\numpy\distutils\ccompiler.py", line 773, in new_compiler
        compiler = klass(None, dry_run, force)
      File "C:\Users\runneradmin\AppData\Local\Temp\cibw-run-kuns43px\cp310-win_amd64\build\venv\lib\site-packages\numpy\distutils\mingw32ccompiler.py", line 58, in __init__
        distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose,
      File "C:\Users\runneradmin\AppData\Local\pypa\cibuildwheel\Cache\nuget-cpython\python.3.10.4\tools\lib\distutils\cygwinccompiler.py", line 155, in __init__
        self.dll_libraries = get_msvcr()
      File "C:\Users\runneradmin\AppData\Local\pypa\cibuildwheel\Cache\nuget-cpython\python.3.10.4\tools\lib\distutils\cygwinccompiler.py", line 84, in get_msvcr
        raise ValueError("Unknown MS Compiler version %s " % msc_ver)
    ValueError: Unknown MS Compiler version 1929

Edit: I think we need to focus on the missing-def-error, because it occurs after the compiler-version-error.

hydrogeoscience commented 2 years ago

Under Windows, there's two main ways to compile. One uses MinGW, the other uses the MS Visual C++.

In my experience with compiling this under Windows, this error:

ImportError: DLL load failed: The specified module could not be found.

typically arises when the compiled DLL (1) is not compatible (e.g., compiled for a different Python version), (2) it misses an external dependency. My guess is it's (2) which can be solved with static compile, see here. So you would have to add --inplace to the compiler flags, and -static -static-libgfortran -static-libgcc as extra link arguments.