-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup_dev.sh
More file actions
executable file
·134 lines (116 loc) · 4.23 KB
/
setup_dev.sh
File metadata and controls
executable file
·134 lines (116 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/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! 🚀"