#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import subprocess
from setuptools import setup, find_packages

YEAR = 2020
MONTH = 4
STATUS = 'dev0'


def get_git_version():
    if not os.path.exists('.git'):
        return None

    git_rev = None
    try:
        git_rev = subprocess.check_output(
                ['git', 'rev-parse', 'HEAD'], stderr=subprocess.STDOUT
                ).strip().decode('ascii')
    except (subprocess.SubprocessError, OSError):
        pass

    if git_rev is None:
        git_rev = "Unknown"

    return git_rev


VERSION = (YEAR, MONTH)
VERSION_TEXT = '%d.%d%s' % (YEAR, MONTH, STATUS)
GIT_REVISION = get_git_version()

VERSION_FILE = "lappy/version.py"
VER_DICT = {
        'version': VERSION,
        'version_status': STATUS,
        'version_text': VERSION_TEXT,
        'git_revision': GIT_REVISION}

# rewrite version file every time
with open(VERSION_FILE, 'w') as a:
    a.write("""##################################################
# THIS FILE IS GENERATED BY LAPPY SETUP.PY
##################################################

VERSION = '%(version)s'
VERSION_STATUS = '%(version_status)s'
VERSION_TEXT = '%(version_text)s'
GIT_REVISION = '%(git_revision)s'
""" % VER_DICT)

setup(name="lappy",
      version=VER_DICT['version_text'],
      description="Lazy array programming in Python",
      long_description=open("README.rst").read(),
      classifiers=[
          'Development Status :: 4 - Beta',
          'Intended Audience :: Developers',
          'Intended Audience :: Other Audience',
          'Intended Audience :: Science/Research',
          'License :: OSI Approved :: MIT License',
          'Natural Language :: English',
          'Programming Language :: Python',
          'Programming Language :: Python',
          'Programming Language :: Python :: 2',
          'Programming Language :: Python :: 2.6',
          'Programming Language :: Python :: 2.7',
          'Programming Language :: Python :: 3',
          'Programming Language :: Python :: 3.3',
          'Programming Language :: Python :: 3.4',
          'Topic :: Scientific/Engineering',
          'Topic :: Scientific/Engineering :: Information Analysis',
          'Topic :: Scientific/Engineering :: Mathematics',
          'Topic :: Scientific/Engineering :: Visualization',
          'Topic :: Software Development :: Libraries',
          'Topic :: Utilities',
          ],

      install_requires=[
          "loo.py",
          "numpy",
          ],

      extras_require={
          "test": ["pytest", ],
          "doc": ["sphinx", "sphinx_rtd_theme"],
          },

      author="Sophia Lin, Andreas Kloeckner, Xiaoyu Wei",
      url="http://pypi.python.org/pypi/lappy",
      author_email="svlin2@illinois.edu",
      license="MIT",
      packages=find_packages())
