import re

# First, we try to use setuptools. If it's not available locally,
# we fall back on ez_setup.
try:
    from setuptools import setup
except ImportError:
    from ez_setup import use_setuptools
    use_setuptools()
    from setuptools import setup


# Following the recommendations of PEP 396 we parse the version number
# out of the module.
def parseVersion(moduleFile):
    """
    Parses the version string from the specified file.

    This implementation is ugly, but there doesn't seem to be a good way
    to do this in general at the moment.
    """
    f = open(moduleFile)
    s = f.read()
    f.close()
    match = re.findall("__version__ = '([^']+)'", s)
    return match[0]

f = open("README.pypi.rst")
ga4ghReadme = f.read()
f.close()
ga4ghVersion = parseVersion("ga4gh/__init__.py")
# Flask must come after all other requirements that have "flask" as a prefix
# due to a setuptools bug.
requirements = [
    "Flask-Cors==2.0.1",
    "Flask==0.10.1",
    "avro==1.7.7",
    "humanize==0.5.1",
    "pysam==0.8.3",
    "oic==0.7.6",
    "requests==2.7.0",
]

setup(
    name="ga4gh",
    version=ga4ghVersion,
    description="A reference implementation of the ga4gh API",
    license='Apache License 2.0',
    long_description=ga4ghReadme,
    packages=["ga4gh", "ga4gh.datamodel", "ga4gh.templates"],
    include_package_data=True,
    zip_safe=False,
    author="Global Alliance for Genomics and Health",
    author_email="theglobalalliance@genomicsandhealth.org",
    url="https://github.com/ga4gh/server",
    entry_points={
        'console_scripts': [
            'ga4gh_client=ga4gh.cli:client_main',
            'ga4gh_configtest=ga4gh.cli:configtest_main',
            'ga4gh_server=ga4gh.cli:server_main',
            'ga2vcf=ga4gh.cli:ga2vcf_main',
            'ga2sam=ga4gh.cli:ga2sam_main',
        ]
    },
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: Apache Software License',
        'Natural Language :: English',

        # We should add other versions that we can confirm pass the tests
        # (2.6?)
        'Programming Language :: Python :: 2.7',

        'Topic :: Scientific/Engineering :: Bio-Informatics',
    ],
    keywords='genomics reference',
    install_requires=requirements,
)
