Skip to content

Commit

Permalink
Fix #376 by adapting setup.py and pyproject.toml (#431)
Browse files Browse the repository at this point in the history
* Fix #376 by meson build

* Replace meson by simpler solution

* Formatting

* Fix distutils for Python<3.12

* Makefile updated

* Added MANIFEST to f2py

* add build requirement

* Fixing extension

* Cleanup
  • Loading branch information
krystophny authored Jan 10, 2025
1 parent b6cbb86 commit 8a2358b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
4 changes: 4 additions & 0 deletions f2py/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include expro/expro.f90
include expro/expro_util.f90
include expro/expro_pycomm.f90
include geo/geo.f90
2 changes: 1 addition & 1 deletion f2py/pygacode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ def gapystr_set(s, l=10, n=200):
__all__.extend(list(tmp.keys()))
except:
# Not using pygacode
pass
pass
21 changes: 13 additions & 8 deletions f2py/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
[build-system]
requires = ['setuptools','wheel','numpy']
requires = [
'setuptools>=41.2.0', 'wheel',
'oldest-supported-numpy; python_version=="3.8"',
'numpy>=2.0.2; python_version>="3.9"',
'numpy>=2.1.3; python_version>="3.10"',
'meson; python_version>="3.12"',
]
build-backend = 'setuptools.build_meta'

[project]
name = 'pygacode'
version = '1.0.1'
version = '1.0.2'
description = 'Python-GACODE'
license = {text = 'MIT'}
requires-python = ">=3.8"

[project.urls]
Homepage = "https://gacode.io"

license = { text = 'MIT' }
requires-python = '>=3.8'
urls = { Homepage = 'https://gacode.io' }
dependencies = ['numpy']
52 changes: 44 additions & 8 deletions f2py/setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
from numpy.distutils.core import setup,Extension
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
from importlib.machinery import EXTENSION_SUFFIXES
import os
import shutil
import sys
import subprocess
import sysconfig


class F2PyExtension(Extension):
def __init__(self, name, fortran_sources, **kwargs):
super().__init__(name, sources=[], **kwargs)
self.fortran_sources = fortran_sources


class BuildF2PyExtension(build_ext):
def build_extension(self, ext):
output_module = ext.name
env = os.environ.copy()
if sys.version_info < (3, 12):
env["SETUPTOOLS_USE_DISTUTILS"] = "1"
subprocess.check_call([
"f2py", "-c", "-m", output_module, *ext.fortran_sources
], env=env)

ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
lib_name = f"{output_module}{ext_suffix}"

ext_path = self.get_ext_fullpath(ext.name)
ext_dir = os.path.dirname(ext_path)
if not os.path.exists(ext_dir):
os.makedirs(ext_dir)

shutil.move(lib_name, ext_path)


ext = F2PyExtension('gacode_ext',
fortran_sources=['expro/expro.f90',
'expro/expro_util.f90',
'expro/expro_pycomm.f90',
'geo/geo.f90'])

ext = Extension('gacode_ext',
sources=['expro/expro.f90',
'expro/expro_util.f90',
'expro/expro_pycomm.f90',
'geo/geo.f90'])

setup(py_modules=['pygacode.gacodefuncs',
'pygacode.gacodeinput'],
Expand All @@ -16,6 +52,6 @@
'pygacode.neo',
'pygacode.profiles_gen'],
package_data={'pygacode.test': ['input.gacode']},
ext_modules=[ext]
ext_modules=[ext],
cmdclass={'build_ext': BuildF2PyExtension},
)

0 comments on commit 8a2358b

Please sign in to comment.