Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| import subprocess | |
| import logging | |
| from pathlib import Path | |
| # Setup logging | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| def check_python_version(): | |
| """Check if Python version is compatible""" | |
| if sys.version_info < (3, 11): | |
| logger.error("Python 3.11 or higher is required") | |
| sys.exit(1) | |
| logger.info(f"Python version {sys.version_info.major}.{sys.version_info.minor} detected") | |
| def create_virtual_environment(): | |
| """Create and activate virtual environment""" | |
| venv_name = "synthex_env" | |
| if not os.path.exists(venv_name): | |
| logger.info(f"Creating virtual environment: {venv_name}") | |
| subprocess.run([sys.executable, "-m", "venv", venv_name], check=True) | |
| else: | |
| logger.info(f"Virtual environment {venv_name} already exists") | |
| def install_requirements(): | |
| """Install required packages""" | |
| logger.info("Installing requirements...") | |
| subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True) | |
| def create_directories(): | |
| """Create necessary directories""" | |
| directories = [ | |
| "data/raw", | |
| "data/processed", | |
| "data/reports", | |
| "data/reports/plots" | |
| ] | |
| for directory in directories: | |
| Path(directory).mkdir(parents=True, exist_ok=True) | |
| logger.info(f"Created directory: {directory}") | |
| def setup_environment(): | |
| """Setup the complete environment""" | |
| try: | |
| logger.info("Starting environment setup...") | |
| # Check Python version | |
| check_python_version() | |
| # Create virtual environment | |
| create_virtual_environment() | |
| # Install requirements | |
| install_requirements() | |
| # Create directories | |
| create_directories() | |
| logger.info("Environment setup completed successfully!") | |
| logger.info("\nNext steps:") | |
| logger.info("1. Activate the virtual environment:") | |
| logger.info(" - Windows: synthex_env\\Scripts\\activate") | |
| logger.info(" - Unix/MacOS: source synthex_env/bin/activate") | |
| logger.info("2. Run data collection: python setup_data.py") | |
| logger.info("3. Analyze data quality: python analyze_data_quality.py") | |
| except subprocess.CalledProcessError as e: | |
| logger.error(f"Error during setup: {str(e)}") | |
| sys.exit(1) | |
| except Exception as e: | |
| logger.error(f"Unexpected error: {str(e)}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| setup_environment() |