#!/usr/bin/env python3
# coding: utf-8
'''
Author: Park Lam <lqmonline@gmail.com>
'''
from setuptools import setup, find_packages
import os

LONG_DESCRIPTION = None
with open('README.md', 'r') as fp:
    LONG_DESCRIPTION = fp.read()

REQUIREMENTS = None
with open('requirements/runtime.txt', 'r') as fp:
    REQUIREMENTS = [ line.strip() for line in fp.readlines() \
            if not line.strip().startswith('#') ]

VERSION = None
with open('VERSION', 'r') as fp:
    VERSION = fp.read().strip()

with open('unipark/version.py', 'w') as fp:
    fp.write(f'# Generated by "setup.py" file.\n'
            f'VERSION=\'{ VERSION }\'')

def find_package_data(data_dir, exts=('*',)):
    paths = []
    for root, dirs, files in os.walk(data_dir):
        for file in files:
            if not exts \
                    or '*' in exts \
                    or [ ext for ext in exts if file.endswith(ext) ]:
                paths.append(os.path.join(root, file))
    return paths

if __name__ == '__main__':
    setup(
        name='unipark',
        version=VERSION,
        description='Common library of UniPark',
        long_description=LONG_DESCRIPTION,
        long_description_content_type='text/markdown',
        author='Park Lam',
        author_email='lqmonline@gmail.com',
        url='https://www.unipark.io',
        license='Apache2.0',
        install_requires=REQUIREMENTS,
        packages=find_packages(
            include=[ 'unipark*', ],
            exclude=[ 'ez_setup', 'test*', ]),
        package_data={
            'unipark': find_package_data('data') \
                    + [ 'licenses.txt', ]},
        entry_points={
            'console_scripts': [ 'unipark = unipark:main' ],
        },
    )
