anycoder-1392568b / utils.py
tats2bzr's picture
Upload utils.py with huggingface_hub
7acd197 verified
import subprocess
import sys
import os
import time
from datetime import datetime
def check_dependencies():
"""Check if all required dependencies are installed"""
required_packages = [
'streamlit', 'pandas', 'numpy', 'plotly',
'python-dateutil', 'pytz', 'openpyxl',
'watchdog', 'python-dotenv', 'pydantic',
'sqlalchemy', 'psycopg2-binary', 'bcrypt', 'jinja2'
]
missing_packages = []
for package in required_packages:
try:
__import__(package)
except ImportError:
missing_packages.append(package)
return missing_packages
def install_package(package_name):
"""Install a Python package using pip"""
try:
subprocess.check_call([sys.executable, "-m", "pip", "install", package_name])
return True
except subprocess.CalledProcessError:
return False
def create_virtual_environment(env_name="venv"):
"""Create a virtual environment"""
try:
subprocess.check_call([sys.executable, "-m", "venv", env_name])
return True
except subprocess.CalledProcessError:
return False
def setup_database():
"""Setup database configuration"""
# This is a placeholder function
# In a real application, this would configure database connections
return True
def log_message(message, level="info"):
"""Log messages with timestamp"""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
log_entry = f"[{timestamp}] [{level.upper()}] {message}"
# Print to console
print(log_entry)
# In a real application, you might write to a log file
# with open("installation.log", "a") as f:
# f.write(log_entry + "\n")
return log_entry
def validate_python_version():
"""Validate Python version"""
import platform
version = platform.python_version()
major, minor, patch = map(int, version.split('.'))
if major < 3 or (major == 3 and minor < 11):
return False, f"Python 3.11+ required, but found {version}"
return True, f"Python {version} is compatible"
def test_database_connection(config):
"""Test database connection"""
# This is a placeholder function
# In a real application, this would test the actual database connection
return True, "Database connection successful"<|end_of_box|>
<|begin_of_box|>