Cleanup setup process.

这个提交包含在:
Craig Warren
2021-12-04 09:44:28 +01:00
父节点 76f2c6a08b
当前提交 498bb21321

219
setup.py
查看文件

@@ -17,7 +17,7 @@
# along with gprMax. If not, see <http://www.gnu.org/licenses/>. # along with gprMax. If not, see <http://www.gnu.org/licenses/>.
try: try:
from setuptools import setup, Extension from setuptools import Extension, setup
except ImportError: except ImportError:
from distutils.core import setup from distutils.core import setup
from distutils.extension import Extension from distutils.extension import Extension
@@ -34,9 +34,13 @@ import shutil
import sys import sys
from pathlib import Path from pathlib import Path
# SetupTools Required to make package from jinja2 import Environment, FileSystemLoader
import setuptools
from jinja2 import Environment, FileSystemLoader, select_autoescape MIN_PYTHON_VERSION = (3, 7)
# Check Python version
if sys.version_info[:2] < MIN_PYTHON_VERSION:
sys.exit('\nExited: Requires Python 3.7 or newer!\n')
def build_dispersive_material_templates(): def build_dispersive_material_templates():
@@ -119,14 +123,6 @@ with open('gprMax/__init__.py', 'r') as fd:
packages = [packagename, 'tests', 'tools', 'user_libs'] packages = [packagename, 'tests', 'tools', 'user_libs']
# Parse long_description from README.rst file.
with open('README.rst','r') as fd:
long_description = fd.read()
# Python version
if sys.version_info[:2] < (3, 7):
sys.exit('\nExited: Requires Python 3.7 or newer!\n')
# Process 'build' command line argument # Process 'build' command line argument
if 'build' in sys.argv: if 'build' in sys.argv:
print("Running 'build_ext --inplace'") print("Running 'build_ext --inplace'")
@@ -183,100 +179,113 @@ if 'cleanall' in sys.argv:
# Now do a normal clean # Now do a normal clean
sys.argv[1] = 'clean' # this is what distutils understands sys.argv[1] = 'clean' # this is what distutils understands
# Set compiler options else:
# Windows # Compiler options - Windows
if sys.platform == 'win32': if sys.platform == 'win32':
compile_args = ['/O2', '/openmp', '/w'] # No static linking as no static version of OpenMP library; /w disables warnings compile_args = ['/O2', '/openmp', '/w'] # No static linking as no static version of OpenMP library; /w disables warnings
linker_args = [] linker_args = []
extra_objects = [] libraries=[]
libraries=[]
# macOS - needs gcc (usually via HomeBrew) because the default compiler LLVM
# (clang) does not support OpenMP. With gcc -fopenmp option implies -pthread
elif sys.platform == 'darwin':
gccpath = glob.glob('/usr/local/bin/gcc-[4-9]*')
gccpath += glob.glob('/usr/local/bin/gcc-[10-11]*')
if gccpath:
# Use newest gcc found
os.environ['CC'] = gccpath[-1].split(os.sep)[-1]
rpath = '/usr/local/opt/gcc/lib/gcc/' + gccpath[-1].split(os.sep)[-1][-1] + '/'
else:
raise('Cannot find gcc 4-10 in /usr/local/bin. gprMax requires gcc to be installed - easily done through the Homebrew package manager (http://brew.sh). Note: gcc with OpenMP support is required.')
compile_args = ['-O3', '-w', '-fopenmp', '-march=native'] # Sometimes worth testing with '-fstrict-aliasing', '-fno-common'
linker_args = ['-fopenmp', '-Wl,-rpath,' + rpath]
libraries=['iomp5', 'pthread']
extra_objects = []
# Linux
elif sys.platform == 'linux':
compile_args = ['-O3', '-w', '-fopenmp', '-march=native']
linker_args = ['-fopenmp']
extra_objects = []
libraries=[]
# Build a list of all the extensions # Compiler options - macOS - needs gcc (usually via HomeBrew) because the
extensions = [] # default compiler LLVM (clang) does not
for file in cythonfiles: # support OpenMP. With gcc -fopenmp option
tmp = os.path.splitext(file) # implies -pthread
elif sys.platform == 'darwin':
gccpath = glob.glob('/usr/local/bin/gcc-[4-9]*')
gccpath += glob.glob('/usr/local/bin/gcc-[10-11]*')
if gccpath:
# Use newest gcc found
os.environ['CC'] = gccpath[-1].split(os.sep)[-1]
else:
raise('Cannot find gcc in /usr/local/bin. gprMax requires gcc to be installed - easily done through the Homebrew package manager (http://brew.sh). Note: gcc with OpenMP support is required.')
# Minimum supported macOS deployment target
MIN_MACOS_VERSION = '10.13'
try:
os.environ['MACOSX_DEPLOYMENT_TARGET']
del os.environ['MACOSX_DEPLOYMENT_TARGET']
except:
pass
os.environ['MIN_SUPPORTED_MACOSX_DEPLOYMENT_TARGET'] = MIN_MACOS_VERSION
compile_args = ['-O3', '-w', '-fopenmp', '-march=native', '-mmacosx-version-min=' + MIN_MACOS_VERSION] # Sometimes worth testing with '-fstrict-aliasing', '-fno-common'
linker_args = ['-fopenmp', '-mmacosx-version-min=' + MIN_MACOS_VERSION]
libraries=['gomp']
# Compiler options - Linux
elif sys.platform == 'linux':
compile_args = ['-O3', '-w', '-fopenmp', '-march=native']
linker_args = ['-fopenmp']
libraries=[]
# Build list of all the extensions - Cython source files
extensions = []
for file in cythonfiles:
tmp = os.path.splitext(file)
if USE_CYTHON:
fileext = tmp[1]
else:
fileext = '.c'
extension = Extension(tmp[0].replace(os.sep, '.'),
[tmp[0] + fileext],
language='c',
include_dirs=[np.get_include()],
extra_compile_args=compile_args,
extra_link_args=linker_args,
libraries=libraries)
extensions.append(extension)
# Cythonize - build .c files
if USE_CYTHON: if USE_CYTHON:
fileext = tmp[1] from Cython.Build import cythonize
else: extensions = cythonize(extensions,
fileext = '.c' compiler_directives={
extension = Extension(tmp[0].replace(os.sep, '.'), 'boundscheck': False,
[tmp[0] + fileext], 'wraparound': False,
language='c', 'initializedcheck': False,
include_dirs=[np.get_include()], 'embedsignature': True,
extra_compile_args=compile_args, 'language_level': 3
extra_link_args=linker_args, },
libraries=libraries, nthreads=None,
extra_objects=extra_objects) annotate=False)
extensions.append(extension)
# Cythonize (build .c files) # Parse long_description from README.rst file.
if USE_CYTHON: with open('README.rst','r') as fd:
from Cython.Build import cythonize long_description = fd.read()
extensions = cythonize(extensions,
compiler_directives={
'boundscheck': False,
'wraparound': False,
'initializedcheck': False,
'embedsignature': True,
'language_level': 3
},
annotate=False)
setup(name=packagename,
setup(name=packagename, version=version,
version=version, author='Craig Warren, Antonis Giannopoulos, and John Hartley',
author='Craig Warren, Antonis Giannopoulos, and John Hartley', url='http://www.gprmax.com',
url='http://www.gprmax.com', description='Electromagnetic Modelling Software based on the Finite-Difference Time-Domain (FDTD) method',
description='Electromagnetic Modelling Software based on the Finite-Difference Time-Domain (FDTD) method', long_description=long_description,
long_description=long_description, long_description_content_type="text/x-rst",
long_description_content_type="text/x-rst", license='GPLv3+',
license='GPLv3+', classifiers=[
classifiers=[ 'Environment :: Console',
'Environment :: Console', 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', 'Operating System :: MacOS',
'Operating System :: MacOS', 'Operating System :: Microsoft :: Windows',
'Operating System :: Microsoft :: Windows', 'Operating System :: POSIX :: Linux',
'Operating System :: POSIX :: Linux', 'Programming Language :: Cython',
'Programming Language :: Cython', 'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3', 'Topic :: Scientific/Engineering'
'Topic :: Scientific/Engineering' ],
], #requirements
#requirements python_requires='>' + str(MIN_PYTHON_VERSION[0]) + '.' + str(MIN_PYTHON_VERSION[1]),
python_requires=">3.7", install_requires=[
install_requires=[ 'colorama',
"colorama", 'cython',
"cython", 'h5py',
"h5py", 'jinja2',
"jupyter", 'jupyter',
"matplotlib", 'matplotlib',
"numpy", 'numpy',
"psutil", 'psutil',
"scipy", 'scipy',
"terminaltables", 'terminaltables',
"tqdm", 'tqdm',
], ],
ext_modules=extensions, ext_modules=extensions,
packages=packages, packages=packages,
include_package_data=True, include_package_data=True,
include_dirs=[np.get_include()]) include_dirs=[np.get_include()])