From 1f5720cd8cd2fc73f909e7232e43b48eca6d3e86 Mon Sep 17 00:00:00 2001 From: latinogino <154024559+latinogino@users.noreply.github.com> Date: Thu, 28 Aug 2025 18:45:40 +0200 Subject: [PATCH] Add setup script for development environment --- setup.py | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 setup.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f98f11c --- /dev/null +++ b/setup.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""Setup script for Dolibarr MCP development environment.""" + +import os +import subprocess +import sys +import platform + +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}") + return result.stdout + except subprocess.CalledProcessError as e: + print(f"โŒ Command failed: {' '.join(command) if isinstance(command, list) else command}") + 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...") + + # Determine platform-specific paths + if platform.system() == "Windows": + venv_name = "venv_dolibarr" + python_exe = os.path.join(venv_name, "Scripts", "python.exe") + pip_exe = os.path.join(venv_name, "Scripts", "pip.exe") + else: + venv_name = "venv_dolibarr" + python_exe = os.path.join(venv_name, "bin", "python") + pip_exe = os.path.join(venv_name, "bin", "pip") + + # Create virtual environment + 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...") + run_command([python_exe, "-m", "pip", "install", "--upgrade", "pip"]) + + # Install requirements + if os.path.exists("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...") + 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...") + if os.path.exists(".env.example"): + import shutil + shutil.copy(".env.example", ".env") + print("โš ๏ธ Please edit .env file with your Dolibarr credentials") + else: + with open(".env", "w") 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("\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("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...") + + # Determine platform-specific python path + if platform.system() == "Windows": + python_exe = os.path.join("venv_dolibarr", "Scripts", "python.exe") + else: + 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')"] + if run_command(test_command): + print("โœ… Installation test passed!") + return True + else: + print("โŒ Installation test failed!") + return False + +if __name__ == "__main__": + setup_development_environment() + test_installation()