1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
#!/usr/bin/env python
# Author: Lisandro Dalcin
# Contact: dalcinl@gmail.com
"""mpi4py: Python bindings for MPI."""
# ruff: noqa: C408
# ruff: noqa: D103
# ruff: noqa: S101
import os
import sys
import glob
topdir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(topdir, 'conf'))
# --------------------------------------------------------------------
# Metadata
# --------------------------------------------------------------------
require_python = (3, 6)
maxknow_python = (3, 13)
def get_metadata():
import metadata as md
req_py = '>={}.{}'.format(*require_python)
assert req_py == md.requires_python
author = md.authors[0]
readme = md.get_readme()
return {
# distutils
'name' : md.get_name(),
'version' : md.get_version(),
'description' : md.description,
'long_description' : readme['text'],
'classifiers' : md.classifiers,
'keywords' : md.keywords,
'license' : md.license,
'author' : author['name'],
'author_email' : author['email'],
# setuptools
'project_urls': md.urls,
'python_requires': md.requires_python,
'long_description_content_type': readme['content-type'],
}
# --------------------------------------------------------------------
# Extension modules
# --------------------------------------------------------------------
def sources():
# mpi4py.MPI
MPI = dict(
source='src/mpi4py/MPI.pyx',
depends=[
'src/mpi4py/*.pyx',
'src/mpi4py/*.pxd',
'src/mpi4py/MPI.src/*.pyx',
'src/mpi4py/MPI.src/*.pxi',
],
)
#
return [MPI]
def extensions():
import mpidistutils
# MPI extension module
MPI = dict(
name='mpi4py.MPI',
sources=['src/mpi4py/MPI.c'],
depends=(
glob.glob('src/*.h') +
glob.glob('src/lib-mpi/*.h') +
glob.glob('src/lib-mpi/config/*.h') +
glob.glob('src/lib-mpi/compat/*.h')
),
include_dirs=['src'],
define_macros=[],
configure=mpidistutils.configure_mpi,
)
if sys.version_info[:2] > maxknow_python:
api = '0x{:02x}{:02x}0000'.format(*maxknow_python)
MPI['define_macros'].extend([
('CYTHON_LIMITED_API', api),
])
if os.environ.get('CIBUILDWHEEL') == '1':
MPI['define_macros'].extend([
('CIBUILDWHEEL', 1),
])
#
return [MPI]
def executables():
import mpidistutils
# MPI-enabled Python interpreter
pyexe = dict(
name='python-mpi',
optional=True,
package='mpi4py',
dest_dir='bin',
sources=['src/python.c'],
configure=mpidistutils.configure_pyexe,
)
#
return [pyexe]
# --------------------------------------------------------------------
# Setup
# --------------------------------------------------------------------
package_info = dict(
packages = [
'mpi4py',
'mpi4py.futures',
'mpi4py.util',
],
package_data = {
'mpi4py' : [
'*.pxd',
'MPI*.h',
'include/mpi4py/*.h',
'include/mpi4py/*.i',
'include/mpi4py/*.pxi',
'py.typed',
'*.pyi',
'*/*.pyi',
],
},
package_dir = {'' : 'src'},
)
if sys.version_info < (3, 8):
del package_info['package_data']['mpi4py'][-3:]
def run_setup():
"""Call setuptools.setup(*args, **kwargs)."""
try:
import setuptools
except ImportError as exc:
setuptools = None
if sys.version_info >= (3, 12):
sys.exit(exc)
from mpidistutils import setup
from mpidistutils import Extension as Ext
from mpidistutils import Executable as Exe
#
from mpidistutils import build_src
build_src.sources = sources()
#
metadata = get_metadata()
builder_args = dict(
ext_modules = [Ext(**ext) for ext in extensions()],
executables = [Exe(**exe) for exe in executables()],
)
if setuptools:
builder_args['zip_safe'] = False
else:
metadata.pop('project_urls')
metadata.pop('python_requires')
metadata.pop('long_description_content_type')
#
setup_args = dict(i for d in (
metadata,
package_info,
builder_args,
) for i in d.items())
#
setup(**setup_args)
def run_skbuild():
"""Call setuptools.setup(*args, **kwargs)."""
from setuptools import setup
#
metadata = get_metadata()
builder_args = dict(
cmake_source_dir = '.',
)
#
setup_args = dict(i for d in (
metadata,
package_info,
builder_args,
) for i in d.items())
#
setup(**setup_args)
# --------------------------------------------------------------------
def main():
try:
import builder
name = builder.get_build_backend_name()
except RuntimeError as exc:
sys.exit(exc)
if name == 'setuptools':
run_setup()
if name == 'skbuild':
run_skbuild()
if __name__ == '__main__':
if sys.version_info < require_python:
raise SystemExit(
"error: requires Python version " +
".".join(map(str, require_python))
)
main()
# --------------------------------------------------------------------
|