# -*- coding: utf-8 -*-
import os
import subprocess

from distutils.core import setup
from setuptools import find_packages

with open('README.md') as readme:
    long_description = readme.read()

with open('requirements.txt') as reqs:
    install_requires = [
        line for line in reqs.read().split('\n') if (line and not
                                                     line.startswith('--'))
    ]

# Fetch version from git tags, and write to version.py.
# Also, when git is not available (PyPi package), use stored version.py.
version_py = os.path.join(os.path.dirname(__file__), 'VERSION.txt')

try:
    version_git = subprocess.check_output(
        ["git", "describe", "--tags"]).rstrip().decode('utf-8')
except Exception:
    with open(version_py, 'r') as fh:
        version_git = open(
            version_py).read().strip().split('=')[-1].replace('"', '').strip()

version_msg = "# Do not edit this file, " \
              "pipeline versioning is governed by git tags"
with open(version_py, 'w') as fh:
    fh.write(version_msg + os.linesep + 'VERSION=' + version_git)

setup(
    name='revo-client',
    version=version_git,
    author='myotest SA',
    author_email='dev@myotest.com',
    packages=find_packages(),
    include_package_data=True,
    url='https://github.com/Myotest/python-revo-client',
    license='MIT',
    description='Python client for Myotest smart coaching API',
    long_description=long_description,
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Environment :: Console',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Topic :: Software Development :: Libraries :: Pike Modules',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
    ],
    zip_safe=False,
    install_requires=install_requires,
    test_suite='tests',
    python_requires='>=3',
)
