diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7179515..1346880 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,34 +28,42 @@ git clone https://github.com/YOUR_USERNAME/Refactron_lib.git cd Refactron_lib ``` -### 2. Set Up Environment +### 2. Set Up Environment (Automated) + +**Quick way (recommended):** + +```bash +# On macOS/Linux: +bash setup_dev.sh + +# On Windows: +setup_dev.bat +``` + +This script will: +- Create a virtual environment +- Install all dependencies +- Set up pre-commit hooks +- Verify the installation +- Run tests to ensure everything works + +**Manual way (if you prefer):** + ```bash # Create virtual environment python3 -m venv venv source venv/bin/activate # Windows: venv\Scripts\activate # Install in development mode -pip install -e . -pip install -r requirements-dev.txt -``` +pip install -e ".[dev]" -### 3. Install Pre-commit Hooks (Optional but Recommended) -```bash +# Install pre-commit hooks pip install pre-commit pre-commit install -``` -### 4. Verify Installation -```bash -# Run tests +# Verify installation pytest - -# Check code quality -black --check refactron tests -flake8 refactron --max-line-length=100 - -# Try the CLI -refactron --help +refactron --version ``` **You're ready to contribute!** See [Making Your First Contribution](#making-your-first-contribution) below. diff --git a/README.md b/README.md index ae7b817..b7034b3 100644 --- a/README.md +++ b/README.md @@ -84,8 +84,8 @@ Quick start: ```bash git clone https://github.com/Refactron-ai/Refactron_lib.git cd Refactron_lib -pip install -e ".[dev]" -pytest # Make sure tests pass +bash setup_dev.sh # macOS/Linux - automatically sets everything up +# OR setup_dev.bat # Windows ``` See [CONTRIBUTING.md](CONTRIBUTING.md) for the full guide. We follow the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). diff --git a/setup_dev.bat b/setup_dev.bat new file mode 100644 index 0000000..71d0f0c --- /dev/null +++ b/setup_dev.bat @@ -0,0 +1,128 @@ +@echo off +REM Refactron Development Setup Script for Windows +REM This script automates the setup of the development environment + +echo ๐Ÿš€ Setting up Refactron development environment... +echo. + +REM Check if Python is available +python --version >nul 2>&1 +if errorlevel 1 ( + echo โŒ Error: Python is required but not found. + echo Please install Python 3.8 or higher and try again. + exit /b 1 +) + +REM Check Python version (must be 3.8 or higher) +python -c "import sys; sys.exit(0 if sys.version_info >= (3, 8) else 1)" >nul 2>&1 +if errorlevel 1 ( + echo โŒ Error: Python 3.8 or higher is required. + echo Detected Python version is lower than 3.8. + exit /b 1 +) +echo โœ… Python detected +echo. + +REM Create virtual environment if it doesn't exist +if not exist "venv" ( + echo ๐Ÿ“ฆ Creating virtual environment... + python -m venv venv + echo โœ… Virtual environment created +) else ( + echo โœ… Virtual environment already exists +) + +echo. +echo ๐Ÿ”„ Activating virtual environment... +call venv\Scripts\activate.bat + +REM Upgrade pip +echo. +echo โฌ†๏ธ Upgrading pip... +python -m pip install --upgrade pip --quiet +if errorlevel 1 ( + echo โŒ Error: Failed to upgrade pip + exit /b 1 +) + +REM Install the package in editable mode with dev dependencies +echo. +echo ๐Ÿ“ฅ Installing Refactron in development mode... +python -m pip install -e ".[dev]" --quiet +if errorlevel 1 ( + echo โŒ Error: Failed to install Refactron in development mode + exit /b 1 +) + +REM Install additional dev dependencies if requirements-dev.txt exists +if exist "requirements-dev.txt" ( + echo ๐Ÿ“ฅ Installing additional development dependencies... + python -m pip install -r requirements-dev.txt --quiet + if errorlevel 1 ( + echo โŒ Error: Failed to install development dependencies + exit /b 1 + ) +) + +REM Install pre-commit hooks +echo. +echo ๐Ÿ”ง Setting up pre-commit hooks... +python -m pip install pre-commit --quiet +if errorlevel 1 ( + echo โŒ Error: Failed to install pre-commit + exit /b 1 +) +pre-commit install +if errorlevel 1 ( + echo โŒ Error: Failed to install pre-commit hooks + exit /b 1 +) +echo โœ… Pre-commit hooks installed + +REM Verify installation +echo. +echo ๐Ÿงช Verifying installation... +python -c "import refactron; print('โœ… Refactron imported successfully')" 2>nul +if errorlevel 1 ( + echo โŒ Error: Could not import refactron + exit /b 1 +) + +REM Check CLI +echo. +echo ๐Ÿ” Checking CLI... +refactron --version >nul 2>&1 +if errorlevel 1 ( + echo โŒ Error: CLI not working + exit /b 1 +) else ( + for /f "tokens=*" %%i in ('refactron --version') do set VERSION=%%i + echo โœ… CLI working: %VERSION% +) + +REM Run test suite with pytest to verify setup +echo. +echo ๐Ÿงช Running test suite with pytest... +pytest +if errorlevel 1 ( + echo โš ๏ธ Warning: Some tests failed. Please review the pytest output above. +) else ( + echo โœ… All tests passed successfully. +) + +echo. +echo โœจ Development environment setup complete! +echo. +echo ๐Ÿ“ Next steps: +echo 1. Activate the virtual environment: venv\Scripts\activate +echo 2. Make your changes +echo 3. Run tests: pytest +echo 4. Format code: black refactron tests +echo 5. Check code quality: flake8 refactron +echo. +echo ๐Ÿ’ก To activate the environment in the future, run: +echo venv\Scripts\activate +echo. +echo Happy coding! ๐Ÿš€ +pause + diff --git a/setup_dev.sh b/setup_dev.sh new file mode 100755 index 0000000..41f560e --- /dev/null +++ b/setup_dev.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +# Refactron Development Setup Script +# This script automates the setup of the development environment + +set -e # Exit on any error + +echo "๐Ÿš€ Setting up Refactron development environment..." +echo "" + +# Check if Python 3 is available +if ! command -v python3 &> /dev/null; then + echo "โŒ Error: Python 3 is required but not found." + echo "Please install Python 3.8 or higher and try again." + exit 1 +fi + +# Check Python version (must be 3.8+) +PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))') +if ! python3 -c "import sys; exit(0 if sys.version_info >= (3, 8) else 1)" 2>/dev/null; then + echo "โŒ Error: Python 3.8 or higher is required. Found Python $PYTHON_VERSION" + exit 1 +fi + +echo "โœ… Python $PYTHON_VERSION detected" + +# Create virtual environment if it doesn't exist +if [ ! -d "venv" ]; then + echo "" + echo "๐Ÿ“ฆ Creating virtual environment..." + python3 -m venv venv + echo "โœ… Virtual environment created" +else + echo "โœ… Virtual environment already exists" +fi + +# Activate virtual environment +echo "" +echo "๐Ÿ”„ Activating virtual environment..." +source venv/bin/activate + +# Upgrade pip +echo "" +echo "โฌ†๏ธ Upgrading pip..." +pip install --upgrade pip --quiet + +# Install the package in editable mode with dev dependencies +echo "" +echo "๐Ÿ“ฅ Installing Refactron in development mode..." +pip install -e ".[dev]" --quiet + +# Install additional (non-core) dev dependencies if requirements-dev.txt exists +# NOTE: +# - Core development tools (pytest, black, mypy, flake8, isort, etc.) are installed +# via the [dev] extra in pyproject.toml (see the pip install -e ".[dev]" above). +# - To avoid redundant installations and version conflicts, we only use +# requirements-dev.txt for *extra* tools such as documentation dependencies. +if [ -f "requirements-dev.txt" ]; then + echo "๐Ÿ“ฅ Installing additional documentation/development dependencies from requirements-dev.txt..." + + # Extract Sphinx-related requirements (e.g., sphinx, sphinx-rtd-theme) from + # requirements-dev.txt and install only those. This avoids re-installing tools + # that are already provided by the [dev] extra. + DOC_REQUIREMENTS=$(grep -E '^[[:space:]]*sphinx' requirements-dev.txt || true) + + if [ -n "$DOC_REQUIREMENTS" ]; then + echo "$DOC_REQUIREMENTS" | xargs -n1 pip install --quiet + else + echo "โ„น๏ธ No additional documentation dependencies detected in requirements-dev.txt; skipping." + fi +fi + +# Install pre-commit hooks +echo "" +echo "๐Ÿ”ง Setting up pre-commit hooks..." +if command -v pre-commit &> /dev/null || pip show pre-commit &> /dev/null; then + pre-commit install + echo "โœ… Pre-commit hooks installed" +else + echo "โš ๏ธ pre-commit not found. Installing..." + pip install pre-commit --quiet + pre-commit install + echo "โœ… Pre-commit hooks installed" +fi + +# Verify installation +echo "" +echo "๐Ÿงช Verifying installation..." +# Use python3 for consistency (venv should have it, but python3 is more reliable) +if python3 -c "import refactron; print('โœ… Refactron imported successfully')" 2>/dev/null; then + echo "โœ… Installation verified" +else + echo "โŒ Error: Could not import refactron" + exit 1 +fi + +# Check CLI +echo "" +echo "๐Ÿ” Checking CLI..." +if refactron --version &> /dev/null; then + VERSION=$(refactron --version) + echo "โœ… CLI working: $VERSION" +else + echo "โŒ Error: CLI not working" + exit 1 +fi + +# Run tests to verify everything works +echo "" +echo "๐Ÿงช Running tests to verify setup..." +if pytest --version &> /dev/null; then + if ! pytest tests/ -v --tb=short -x; then + echo "" + echo "โš ๏ธ Some tests failed, but setup is complete." + echo "You can investigate test failures later." + fi +else + echo "โš ๏ธ pytest not found. Setup complete, but tests couldn't run." +fi + +echo "" +echo "โœจ Development environment setup complete!" +echo "" +echo "๐Ÿ“ Next steps:" +echo " 1. Activate the virtual environment: source venv/bin/activate" +echo " 2. Make your changes" +echo " 3. Run tests: pytest" +echo " 4. Format code: black refactron tests" +echo " 5. Check code quality: flake8 refactron" +echo "" +echo "๐Ÿ’ก To activate the environment in the future, run:" +echo " source venv/bin/activate" +echo "" +echo "Happy coding! ๐Ÿš€" +