diff --git a/setup.py b/setup.py index f98f11c..9cf1196 100644 --- a/setup.py +++ b/setup.py @@ -1,25 +1,34 @@ #!/usr/bin/env python3 +# -*- coding: utf-8 -*- """Setup script for Dolibarr MCP development environment.""" import os import subprocess import sys import platform +import io + +# Ensure stdout can handle Unicode characters on Windows +if platform.system() == 'Windows': + sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace') + sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace') def run_command(command, shell=False): """Run a command and handle errors.""" try: - result = subprocess.run(command, shell=shell, check=True, capture_output=True, text=True) - print(f"โœ… {' '.join(command) if isinstance(command, list) else command}") + result = subprocess.run(command, shell=shell, check=True, capture_output=True, text=True, encoding='utf-8', errors='replace') + command_str = ' '.join(command) if isinstance(command, list) else command + print(f"[OK] {command_str}") return result.stdout except subprocess.CalledProcessError as e: - print(f"โŒ Command failed: {' '.join(command) if isinstance(command, list) else command}") + command_str = ' '.join(command) if isinstance(command, list) else command + print(f"[ERROR] Command failed: {command_str}") print(f"Error: {e.stderr}") return None def setup_development_environment(): """Set up the development environment for Dolibarr MCP.""" - print("๐Ÿš€ Setting up Dolibarr MCP Development Environment...") + print("Setting up Dolibarr MCP Development Environment...") # Determine platform-specific paths if platform.system() == "Windows": @@ -32,49 +41,49 @@ def setup_development_environment(): pip_exe = os.path.join(venv_name, "bin", "pip") # Create virtual environment - print(f"๐Ÿ“ฆ Creating virtual environment: {venv_name}") + print(f"Creating virtual environment: {venv_name}") if run_command([sys.executable, "-m", "venv", venv_name]): print(f"Virtual environment created at: {os.path.abspath(venv_name)}") # Upgrade pip - print("โฌ†๏ธ Upgrading pip...") + print("Upgrading pip...") run_command([python_exe, "-m", "pip", "install", "--upgrade", "pip"]) # Install requirements if os.path.exists("requirements.txt"): - print("๐Ÿ“‹ Installing requirements from requirements.txt...") + print("Installing requirements from requirements.txt...") run_command([pip_exe, "install", "-r", "requirements.txt"]) # Install package in development mode - print("๐Ÿ”ง Installing package in development mode...") + print("Installing package in development mode...") run_command([pip_exe, "install", "-e", "."]) # Create .env file if it doesn't exist if not os.path.exists(".env"): - print("๐Ÿ“ Creating .env file from template...") + print("Creating .env file from template...") if os.path.exists(".env.example"): import shutil shutil.copy(".env.example", ".env") - print("โš ๏ธ Please edit .env file with your Dolibarr credentials") + print("Please edit .env file with your Dolibarr credentials") else: - with open(".env", "w") as f: + with open(".env", "w", encoding='utf-8') as f: f.write("# Dolibarr MCP Configuration\n") f.write("DOLIBARR_URL=https://your-dolibarr-instance.com/api/index.php\n") f.write("DOLIBARR_API_KEY=your_api_key_here\n") f.write("LOG_LEVEL=INFO\n") - print("โš ๏ธ Please edit .env file with your Dolibarr credentials") + print("Please edit .env file with your Dolibarr credentials") - print("\nโœ… Development environment setup complete!") - print(f"๐Ÿ Python executable: {os.path.abspath(python_exe)}") - print(f"๐Ÿ“ Virtual environment: {os.path.abspath(venv_name)}") - print("\n๐Ÿ”ง Next steps:") + print("\nDevelopment environment setup complete!") + print(f"Python executable: {os.path.abspath(python_exe)}") + print(f"Virtual environment: {os.path.abspath(venv_name)}") + print("\nNext steps:") print("1. Edit .env file with your Dolibarr instance details") print("2. Test the connection: python -m dolibarr_mcp.dolibarr_mcp_server") print("3. Or run with Docker: docker-compose up") def test_installation(): """Test if the installation works.""" - print("\n๐Ÿงช Testing installation...") + print("\nTesting installation...") # Determine platform-specific python path if platform.system() == "Windows": @@ -83,12 +92,12 @@ def test_installation(): python_exe = os.path.join("venv_dolibarr", "bin", "python") # Test import - test_command = [python_exe, "-c", "from dolibarr_mcp.config import Config; print('โœ… Import test passed')"] + test_command = [python_exe, "-c", "from dolibarr_mcp.config import Config; print('[OK] Import test passed')"] if run_command(test_command): - print("โœ… Installation test passed!") + print("Installation test passed!") return True else: - print("โŒ Installation test failed!") + print("Installation test failed!") return False if __name__ == "__main__":