#!/usr/bin/env python3
"""
Installation and setup script for Azure Pricing MCP Server
This script sets up the virtual environment and installs the package in development mode.
"""
import os
import subprocess
import sys
from pathlib import Path
def create_venv():
"""Create virtual environment if it doesn't exist."""
venv_path = Path(".venv")
if not venv_path.exists():
print("š§ Creating virtual environment...")
subprocess.run([sys.executable, "-m", "venv", ".venv"], check=True)
print("ā
Virtual environment created")
else:
print("ā
Virtual environment already exists")
def get_python_executable():
"""Get the Python executable path for the virtual environment."""
if os.name == "nt": # Windows
return Path(".venv") / "Scripts" / "python.exe"
else: # Unix/Linux/Mac
return Path(".venv") / "bin" / "python"
def install_package():
"""Install the package in development mode."""
python_exe = get_python_executable()
print("š¦ Installing package in development mode...")
subprocess.run([str(python_exe), "-m", "pip", "install", "-e", ".[dev]"], check=True)
print("ā
Package installed")
def verify_installation():
"""Verify the installation was successful."""
python_exe = get_python_executable()
print("\nš Verifying installation...")
try:
result = subprocess.run(
[str(python_exe), "-c", "import azure_pricing_mcp; print('2.1.0')"],
capture_output=True,
text=True,
check=True,
)
version = result.stdout.strip()
print(f"ā
Installation verified - version {version}")
return True
except subprocess.CalledProcessError:
print("ā Installation verification failed")
return False
def print_next_steps():
"""Print instructions for next steps."""
print("\n" + "=" * 60)
print("š Setup complete!")
print("=" * 60)
print("\nNext steps:")
print("1. Activate the virtual environment:")
if os.name == "nt":
print(" .venv\\Scripts\\activate")
else:
print(" source .venv/bin/activate")
print("\n2. Run the server:")
print(" python -m azure_pricing_mcp")
print("\n3. Or use the console script:")
print(" azure-pricing-mcp")
print("\n4. Configure your MCP client (VS Code, Claude, etc.)")
print(" See README.md for configuration examples")
print("=" * 60)
def main():
"""Main setup function."""
try:
print("š Setting up Azure Pricing MCP Server...")
print()
create_venv()
install_package()
if verify_installation():
print_next_steps()
else:
print("\nā ļø Installation may have issues. Please check the output above.")
sys.exit(1)
except KeyboardInterrupt:
print("\nš Setup cancelled")
sys.exit(1)
except subprocess.CalledProcessError as e:
print(f"\nā Error during setup: {e}")
sys.exit(1)
except Exception as e:
print(f"\nā Unexpected error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()