from __future__ import print_function
from __future__ import absolute_import

import os
import sys
import platform
import re

from setuptools import setup
from numpy.distutils.core import setup
from numpy.distutils.core import Extension



# =============================================================================
# helper functions to extract meta-info from package
# =============================================================================
def read_version_file(*parts):
    return open(os.path.join(*parts), 'r').read()

def read(fname):
    return open(os.path.join(os.path.dirname(__file__), fname)).read()

def find_version(*file_paths):
    version_file = read_version_file(*file_paths)
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string.")

def find_name(*file_paths):
    version_file = read_version_file(*file_paths)
    version_match = re.search(r"^__name__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find name string.")

def find_author(*file_paths):
    version_file = read_version_file(*file_paths)
    version_match = re.search(r"^__author__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find author string.")



print ("\n" + 60*'#' + "\n")




# =============================================================================
# fortran module
# =============================================================================
optional_fortran_extension = \
        [Extension(
                name = 'pyGDM2_retard.pyGDM2_retard_for', 
                sources = [
                    'fortran_src/propagator_retard_123.f90',
                    'fortran_src/slatec_minimal.f90',
                          ],
                define_macros = [('F2PY_REPORT_ON_ARRAY_COPY','1')],
                extra_compile_args = ['-O3', '-mcmodel=medium'],
                extra_link_args = ['-O3'],
                )
         ]
    
print ("\n" + 60*'#' + 2*"\n")



# =============================================================================
# main setup    
# =============================================================================
setup(
    name = find_name("pyGDM2_retard", "__init__.py"),
    version = find_version("pyGDM2_retard", "__init__.py"),
    author = find_author("pyGDM2_retard", "__init__.py"),
    author_email = "pwiecha@laas.fr",
    description = ("A python full-field electrodynamical solver, "
                   "based on the Green dyadic method (volume integral technique "
                   "in frequency domain)."),
    license = "GPLv3+",
    long_description=read('README.rst'),
    packages=['pyGDM2_retard'],
    ext_modules=optional_fortran_extension,
    classifiers=[
        "Development Status :: 5 - Production/Stable",
        "Topic :: Scientific/Engineering :: Physics",
        "Environment :: Console",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "Programming Language :: Python :: 3.7",
        "Programming Language :: Python :: 3.8",
        "Programming Language :: Python :: 3.9",
        "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
        "Intended Audience :: Science/Research"
    ],
    url = 'https://gitlab.com/wiechapeter/pyGDM2',
    download_url = '',
    keywords = ['coupled dipoles method', 'green dyadic method', 'electrodynamical simulations', 'nano optics', 'frequency-domain'],
    install_requires=['numpy', 'numba'],
    python_requires='>=3.5',
) 
