import io
import re

from setuptools import find_packages
from setuptools import setup


def _process_requirements(requirements):
    return list(
        filter(lambda x: x != '', map(lambda x: x.strip(), requirements)),
    )


def _process_packages(packages):
    return list(
        map(lambda x: 'homehub_tradfri.{package}'.format(package=x), packages),
    )


with io.open('README.md', 'rt', encoding='utf8') as f:
    readme = f.read()

with io.open('requirements.txt', 'rt', encoding='utf8') as f:
    requirements = _process_requirements(f.read().split('\n'))

with io.open('homehub_tradfri/__init__.py', 'rt', encoding='utf8') as f:
    version = re.search(r"""__version__ = '(.*?)'""", f.read()).group(1)

packages = ['homehub_tradfri']
packages.extend(_process_packages(find_packages(
    'homehub_tradfri', exclude=[
        'testing', 'testing.*', 'tests', 'tests.*',
    ],
)))

setup(
    name='homehub_tradfri',
    version=version,
    license='Apache License Version 2.0',
    author='BTHLabs',
    author_email='contact@bthlabs.pl',
    maintainer='BTHLabs',
    maintainer_email='contact@bthlabs.pl',
    description='BTHLabs HomeHub - IKEA Tradfri Integration',
    long_description=readme,
    classifiers=[
        'License :: OSI Approved :: Apache Software License',
    ],
    packages=packages,
    include_package_data=True,
    python_requires='>=3.7',
    install_requires=requirements,
)
