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

""" A Flask extension that prevents browser access to API. """

import os
import sys

from setuptools import find_packages, setup
from setuptools.command.install import install

VERSION = '1.0.9'


def readme():
    """ Transform the given markdown README to RST. """
    try:
        from m2r import parse_from_file
        return parse_from_file('README.md')
    except ImportError:
        with open('README.md') as stream:
            return stream.read()


class VerifyVersionCommand(install):
    """ Custom command to verify that the git tag matches our version """

    description = 'verify that the git tag matches our version'

    def run(self):
        tag = os.getenv('CIRCLE_TAG')
        if tag != VERSION:
            sys.exit(
                'Git tag %s does not match the current flask fool version %s'
                % (tag, VERSION))

_URL = 'https://github.com/Faylixe/flask-fool'
_TAG_URL = _URL + '/archive/%s.tar.gz'

setup(
    name='flask-fool',
    version=VERSION,
    description=__doc__,
    long_description=readme(),
    keywords='flask fool',
    license='Apache Licence 2.0',
    author='<NAME>',
    author_email='<EMAIL>',
    url=_URL,
    download_url=_TAG_URL % VERSION,
    packages=['flask_fool'],
    include_package_data=True,
    install_requires=['Flask'],
    cmdclass={'verify': VerifyVersionCommand},
    classifiers=[
        'Environment :: Web Environment',
        'Intended Audience :: Developers',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
        'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
        'Topic :: Software Development :: Libraries :: Python Modules',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Development Status :: 5 - Production/Stable',
    ]
)
