import io
import os
import re

from setuptools import find_packages
from setuptools import setup

PROJECT_ROOT = os.path.dirname(__file__)


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_backend.{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_backend/__init__.py', 'rt', encoding='utf8') as f:
    version = re.search(r"""__version__ = '(.*?)'""", f.read()).group(1)

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

setup(
    name='homehub_backend',
    version=version,
    url='https://www.bthlabs.pl/',
    license='Apache License Version 2.0',
    author='BTHLabs',
    author_email='contact@bthlabs.pl',
    maintainer='BTHLabs',
    maintainer_email='contact@bthlabs.pl',
    description='BTHLabs HomeHub - Backend Application',
    long_description=readme,
    classifiers=[
        'License :: OSI Approved :: Apache Software License',
    ],
    packages=packages,
    include_package_data=True,
    python_requires='>=3.10',
    install_requires=requirements,
)
