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

from os import path
from setuptools import setup
import sys

basedir = path.dirname(path.abspath(__file__))
extra_args = {}

if (3, 6) > sys.version_info >= (3, 5):
    in_dir = path.join(basedir, 'pyppeteer')
    out_dir = path.join(basedir, '.pyppeteer')
    packages = ['pyppeteer']
    package_dir = {'pyppeteer': '.pyppeteer'}
    if not path.exists(out_dir):
        if path.exists(in_dir):
            try:
                from py_backwards.compiler import compile_files
            except ImportError:
                import subprocess
                subprocess.run(
                    [sys.executable, '-m', 'pip', 'install', 'py-backwards']
                )
                from py_backwards.compiler import compile_files
            target = (sys.version_info[0], sys.version_info[1])
            compile_files(in_dir, out_dir, target)
        else:
            raise Exception('Could not find package directory')
else:
    packages = ['pyppeteer']
    package_dir = {'pyppeteer': 'pyppeteer'}

readme_file = path.join(basedir, 'README.md')
with open(readme_file) as f:
    src = f.read()
readme = src

requirements = [
    'pyee',
    'websockets',
    'appdirs',
    'urllib3',
    'tqdm'
]

test_requirements = [
    'syncer',
    'tornado>=5',
]

setup(
    name='pyppeteer-box',
    version='0.0.26',
    description=('Headless chrome/chromium automation library '
                 '(unofficial port of puppeteer)'),
    long_description=readme,
    long_description_content_type="text/markdown",

    author="Hiroyuki Takagi",
    author_email='miyako.dev@gmail.com',
    url='https://github.com/pjialin/pyppeteer',

    packages=packages,
    package_dir=package_dir,
    include_package_data=True,
    install_requires=requirements,
    entry_points={
        'console_scripts': [
            'pyppeteer-install = pyppeteer.command:install',
        ],
    },

    license="MIT license",
    zip_safe=False,
    keywords='pyppeteer',
    classifiers=[
        'Development Status :: 3 - Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: MIT License',
        'Natural Language :: English',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
    ],
    python_requires='>=3.5',
    test_suite='tests',
    tests_require=test_requirements,
    **extra_args
)
