Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
128 changes: 128 additions & 0 deletions setup_dev.bat
Original file line number Diff line number Diff line change
@@ -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

135 changes: 135 additions & 0 deletions setup_dev.sh
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +76 to +84
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pre-commit installation logic differs between the bash and Windows scripts. The bash script checks if pre-commit exists before installing (lines 61-69), while the Windows script always installs it (setup_dev.bat line 63). For consistency, consider either always installing pre-commit (since pip install -e ".[dev]" doesn't include it in pyproject.toml) or checking for it in both scripts. The current approach in the bash script is correct since pre-commit is not in the dev extras.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback


# 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! πŸš€"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟑 Minor

Add newline at end of file (flagged by pre-commit).

The pre-commit hook detected that the file is missing a trailing newline, which is required by POSIX standards for text files.

Add a blank line after line 120 to fix this issue.

πŸ€– Prompt for AI Agents
In setup_dev.sh around line 120, the file is missing a trailing newline required
by POSIX; open the file and add a single blank line (press Enter) after line 120
so the file ends with a newline character, then save and re-run pre-commit.

Loading