-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·154 lines (133 loc) · 5.06 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·154 lines (133 loc) · 5.06 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#
# CodeSnake Setup Script
# One-time setup to get CodeSnake ready to use
#
set -e
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
NC='\033[0m'
# Configuration
VENV_NAME="codesnake-venv"
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VENV_PATH="${SCRIPT_DIR}/${VENV_NAME}"
echo -e "${CYAN}"
cat << "EOF"
____ _ ____ _
/ ___|___ __| | ___ / ___| _ __ __ _| | _____
| | / _ \ / _` |/ _ \\___ \| '_ \ / _` | |/ / _ \
| |__| (_) | (_| | __/___) | | | | (_| | < __/
\____\___/ \__,_|\___|____/|_| |_|\__,_|_|\_\___|
Setup Script - Let's get you started! 🐍
EOF
echo -e "${NC}\n"
# Check Python version
echo -e "${BLUE}[1/5] Checking Python version...${NC}"
if ! command -v python3 &> /dev/null; then
echo -e "${RED}Error: Python 3 is not installed${NC}"
echo -e "${YELLOW}Please install Python 3.10 or higher${NC}"
exit 1
fi
PYTHON_VERSION=$(python3 --version | awk '{print $2}')
echo -e "${GREEN}✓ Found Python ${PYTHON_VERSION}${NC}\n"
# Create virtual environment
echo -e "${BLUE}[2/5] Creating virtual environment...${NC}"
if [ -d "${VENV_PATH}" ]; then
echo -e "${YELLOW}Virtual environment already exists${NC}"
read -p "Recreate it? (y/N): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -rf "${VENV_PATH}"
python3 -m venv "${VENV_PATH}"
echo -e "${GREEN}✓ Virtual environment recreated${NC}"
else
echo -e "${GREEN}✓ Using existing virtual environment${NC}"
fi
else
python3 -m venv "${VENV_PATH}"
echo -e "${GREEN}✓ Virtual environment created${NC}"
fi
echo
# Activate virtual environment
source "${VENV_PATH}/bin/activate"
# Upgrade pip
echo -e "${BLUE}[3/5] Upgrading pip...${NC}"
pip install --upgrade pip --quiet
echo -e "${GREEN}✓ pip upgraded${NC}\n"
# Install this project from pyproject.toml
echo -e "${BLUE}[4/5] Installing CodeSnake${NC}"
echo -e "${YELLOW}CodeSnake works standalone, but can also install optional tools:${NC}"
echo
echo " • pylint - Advanced Python linter"
echo " • flake8 - Style guide enforcement (PEP 8)"
echo " • mypy - Static type checker"
echo " • bandit - Security vulnerability scanner"
echo " • isort - Import sorting"
echo
read -p "Install optional tools? (recommended) (Y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
echo -e "${YELLOW}Installing CodeSnake with optional tools (pyproject.toml)...${NC}"
pip install -e "${SCRIPT_DIR}[tools]" --quiet
echo -e "${GREEN}✓ CodeSnake and optional tools installed${NC}"
else
echo -e "${YELLOW}Installing CodeSnake (no optional tools)...${NC}"
pip install -e "${SCRIPT_DIR}" --quiet
echo -e "${GREEN}✓ CodeSnake installed${NC}"
fi
echo
# Make scripts executable
echo -e "${BLUE}[5/5] Making scripts executable...${NC}"
chmod +x "${SCRIPT_DIR}/codesnake.sh" 2>/dev/null || true
chmod +x "${SCRIPT_DIR}/codesnake-launcher.sh" 2>/dev/null || true
chmod +x "${SCRIPT_DIR}/setup.sh" 2>/dev/null || true
echo -e "${GREEN}✓ Scripts are executable${NC}\n"
# Create default config if it doesn't exist
if [ ! -f "${SCRIPT_DIR}/.codesnake.json" ]; then
echo -e "${YELLOW}Creating default configuration file...${NC}"
PYTHONPATH="${SCRIPT_DIR}/src" python3 -m codesnake config -o "${SCRIPT_DIR}/.codesnake.json" > /dev/null
echo -e "${GREEN}✓ Created .codesnake.json${NC}\n"
fi
# Test installation
echo -e "${BLUE}Testing CodeSnake installation...${NC}"
if python3 -m codesnake --help &> /dev/null; then
echo -e "${GREEN}✓ CodeSnake is working!${NC}\n"
else
echo -e "${RED}Warning: Could not verify CodeSnake installation${NC}\n"
fi
# Summary
echo -e "${GREEN}"
echo "═══════════════════════════════════════════════════════════"
echo " Setup Complete! 🎉"
echo "═══════════════════════════════════════════════════════════"
echo -e "${NC}"
echo -e "${CYAN}Quick Start:${NC}"
echo
echo " 1. Check a file:"
echo -e " ${YELLOW}./codesnake.sh test/example_bad_code.py${NC}"
echo
echo " 2. Check with JSON output:"
echo -e " ${YELLOW}./codesnake-launcher.sh --format json your_code.py${NC}"
echo
echo " 3. Run tests:"
echo -e " ${YELLOW}./codesnake-launcher.sh --test${NC}"
echo
echo " 4. Show banner:"
echo -e " ${YELLOW}./codesnake-launcher.sh --banner${NC}"
echo
echo -e "${CYAN}Manual activation:${NC}"
echo -e " ${YELLOW}source ${VENV_NAME}/bin/activate${NC}"
echo
echo -e "${CYAN}Configuration:${NC}"
echo -e " Edit ${YELLOW}.codesnake.json${NC} to customize behavior"
echo
echo -e "${CYAN}Documentation:${NC}"
echo " • README.md - Usage, rules, configuration"
echo " • docs/INTEGRATIONS.md - pre-commit, CI, editor setup"
echo " • docs/BASH_SCRIPTS_GUIDE.md - These scripts and the venv"
echo
echo -e "${GREEN}Happy coding! 🐍✨${NC}"