# coding: utf-8
###################################################################
# Copyright (c) 2016-2020 European Synchrotron Radiation Facility #
#                                                                 #
# Author: Marius Retegan                                          #
#                                                                 #
# This work is licensed under the terms of the MIT license.       #
# For further information, see https://github.com/mretegan/crispy #
###################################################################
import os
import sys

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

from crispy import __version__ as version


def get_readme():
    _dir = os.path.dirname(os.path.abspath(__file__))
    long_description = ""
    with open(os.path.join(_dir, "README.rst")) as f:
        for line in f:
            if "main_window" not in line:
                long_description += line
    return long_description


def get_version():
    return version


def get_requirements():
    requirements = list()
    with open("requirements.txt") as fp:
        for line in fp:
            if line.startswith("#") or line == "\n":
                continue
            line = line.strip("\n")
            requirements.append(line)
    return requirements


def main():
    """The main entry point."""
    if sys.version_info < (2, 7):
        sys.exit("Crispy requires at least Python 2.7")
    elif sys.version_info[0] == 3 and sys.version_info < (3, 4):
        sys.exit("Crispy requires at least Python 3.4")

    kwargs = dict(
        name="crispy",
        version=get_version(),
        description="Core-Level Spectroscopy Simulations in Python",
        long_description=get_readme(),
        license="MIT",
        author="Marius Retegan",
        author_email="marius.retegan@esrf.eu",
        url="https://github.com/mretegan/crispy",
        download_url="https://github.com/mretegan/crispy/releases",
        keywords="gui, spectroscopy, simulation, synchrotron, science",
        install_requires=get_requirements(),
        platforms=["MacOS :: MacOS X", "Microsoft :: Windows", "POSIX :: Linux",],
        packages=[
            "crispy",
            "crispy.gui",
            "crispy.gui.quanty",
            "crispy.quanty",
            "crispy.utils",
        ],
        package_data={
            "crispy.gui.icons": ["*.svg",],
            "crispy.gui.uis": ["*.ui", "quanty/*.ui", "quanty/details/*.ui"],
            "crispy.quanty": [
                "parameters/*.h5",
                "templates/*.lua",
                "calculations.json",
            ],
        },
        classifiers=[
            "Development Status :: 4 - Beta",
            "Environment :: X11 Applications :: Qt",
            "Intended Audience :: Education",
            "Intended Audience :: Science/Research",
            "License :: OSI Approved :: MIT License",
            "Operating System :: MacOS :: MacOS X",
            "Operating System :: Microsoft :: Windows",
            "Operating System :: POSIX :: Linux",
            "Programming Language :: Python :: 3.7",
            "Topic :: Scientific/Engineering :: Visualization",
        ],
    )

    # At the moment pip/setuptools doesn't play nice with shebang paths
    # containing white spaces.
    # See: https://github.com/pypa/pip/issues/2783
    #      https://github.com/xonsh/xonsh/issues/879
    # The most straight forward workaround is to have a .bat script to run
    # crispy on Windows.

    if "win32" in sys.platform:
        kwargs["scripts"] = ["scripts/crispy.bat"]
    else:
        kwargs["scripts"] = ["scripts/crispy"]

    setup(**kwargs)


if __name__ == "__main__":
    main()
