from setuptools import setup, find_packages
from setuptools.command.install import install
import subprocess
import sys
import os

class CreateVenvInstall(install):
    def run(self):
        # Create the virtual environment before installation
        python = sys.executable
        venv_dir = os.path.join(os.getcwd(), "my_new_venv")

        # Check if the virtual environment already exists
        if not os.path.exists(venv_dir):
            print(f"Creating virtual environment at {venv_dir}")
            subprocess.check_call([python, "-m", "venv", venv_dir])

        # Install the package into the new virtual environment
        print(f"Installing the package into the virtual environment at {venv_dir}")
        subprocess.check_call([os.path.join(venv_dir, "bin", "pip"), "install", "."])

        # Call the default install command
        install.run(self)

setup(
    name='odoo_monitoring',               # Name of the package
    version='0.1',                         # Version number
    author='Your Name',
    author_email='your.email@example.com',
    description='A monitoring system with an agent and a server.',
    long_description=open('README.md').read(),
    long_description_content_type='text/markdown',
    packages=find_packages(),                # Finds all subpackages automatically
    include_package_data=True,               # Includes files specified in MANIFEST.in
    install_requires=[
        # List your dependencies here
        'flask',  # Example dependency
        'psutil'
    ],
    package_data={
        'my_package': ['config.conf'],  # Include the config file in the package
    },
    entry_points={
        'console_scripts': [
            'start-agent=odoo_monitor.main.py:main',  # New command to run all
        ],
    },
    classifiers=[
        'Programming Language :: Python :: 3',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
    ],
    python_requires='>=3.6',
)
