Skip to content

Commit 022f66b

Browse files
pushing changes
1 parent a2daed7 commit 022f66b

File tree

2 files changed

+36
-53
lines changed

2 files changed

+36
-53
lines changed

scripting_tools/setup.sh

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,67 @@
11
#!/bin/bash
22

3-
# Enhanced Python virtual environment setup script with global zap-cli and global package installation
4-
set -e
3+
# Python virtual environment setup script with zap-cli global symlink
54

6-
# Colors for output
7-
GREEN='\033[0;32m'
8-
RED='\033[0;31m'
9-
YELLOW='\033[1;33m'
10-
NC='\033[0m' # No Color
5+
set -euo pipefail
116

12-
# Automatically detect the script's root directory dynamically
13-
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
14-
ROOT_DIR="$HOME" # Set root directory to user's home directory
15-
16-
# Define the virtual environment directory and requirements file path
7+
ROOT_DIR="$HOME"
178
VENV_DIR="${ROOT_DIR}/venv"
189
REQUIREMENTS_FILE="${ROOT_DIR}/requirements.txt"
1910
ZAP_CLI_PATH="${ROOT_DIR}/zap_cli.py"
2011

21-
# Check if Python3 is installed
22-
if ! command -v python3 &> /dev/null; then
23-
echo -e "${RED}Error: Python3 is not installed. Please install Python3 and try again.${NC}"
12+
error_exit() {
13+
echo "Error: $1"
2414
exit 1
25-
fi
15+
}
16+
17+
info() {
18+
echo "[INFO] $1"
19+
}
2620

27-
# Check if the python3-venv package is installed, and install it if missing
28-
if ! dpkg -s python3-venv &> /dev/null; then
29-
echo -e "${YELLOW}Installing python3-venv...${NC}"
21+
command -v python3 >/dev/null || error_exit "Python3 is not installed."
22+
23+
if command -v dpkg &> /dev/null && ! dpkg -s python3-venv &> /dev/null; then
24+
info "Installing python3-venv..."
3025
sudo apt update && sudo apt install -y python3-venv
3126
fi
3227

33-
# If the requirements file is not found, search for it in the parent directory
3428
if [ ! -f "$REQUIREMENTS_FILE" ]; then
35-
echo -e "${YELLOW}Requirements file not found in $ROOT_DIR. Searching in subdirectories...${NC}"
29+
info "requirements.txt not found. Searching..."
3630
REQUIREMENTS_FILE=$(find "$ROOT_DIR" -name "requirements.txt" -print -quit)
37-
38-
if [ -z "$REQUIREMENTS_FILE" ]; then
39-
echo -e "${RED}Error: requirements.txt not found.${NC}"
40-
exit 1
41-
else
42-
echo -e "${YELLOW}Found requirements.txt at $REQUIREMENTS_FILE.${NC}"
43-
fi
31+
[ -z "$REQUIREMENTS_FILE" ] && error_exit "requirements.txt not found."
32+
info "Found requirements.txt at $REQUIREMENTS_FILE."
4433
fi
4534

46-
# Create or recreate the virtual environment
4735
if [ ! -d "$VENV_DIR" ]; then
48-
echo -e "${YELLOW}Creating virtual environment at $VENV_DIR...${NC}"
36+
info "Creating virtual environment at $VENV_DIR..."
4937
python3 -m venv "$VENV_DIR"
5038
else
51-
echo -e "${GREEN}Virtual environment already exists at $VENV_DIR.${NC}"
39+
info "Virtual environment already exists at $VENV_DIR."
5240
fi
5341

54-
# Activate the virtual environment
55-
echo -e "${YELLOW}Activating the virtual environment...${NC}"
5642
source "$VENV_DIR/bin/activate"
5743

58-
# Upgrade pip and install dependencies from requirements.txt
59-
echo -e "${YELLOW}Upgrading pip and installing packages in the virtual environment...${NC}"
44+
info "Upgrading pip and installing packages..."
6045
pip install --upgrade pip
6146
pip install -r "$REQUIREMENTS_FILE"
6247

63-
# Create a symlink for the zap-cli command globally
48+
# Create symlink
6449
if [ -f "$ZAP_CLI_PATH" ]; then
65-
echo -e "${YELLOW}Creating global symlink for zap-cli...${NC}"
66-
sudo ln -sf "$ZAP_CLI_PATH" /usr/local/bin/zap-cli
50+
if [ ! -L /usr/local/bin/zap-cli ]; then
51+
sudo ln -s "$ZAP_CLI_PATH" /usr/local/bin/zap-cli
52+
echo "[INFO] zap-cli command created."
53+
else
54+
echo "[INFO] zap-cli command already exists."
55+
fi
6756
else
68-
echo -e "${RED}Error: zap-cli.py not found at $ZAP_CLI_PATH.${NC}"
6957
deactivate
70-
exit 1
58+
error_exit "zap_cli.py not found at $ZAP_CLI_PATH."
7159
fi
7260

73-
# Install pip packages globally (if any additional packages need to be globally installed)
74-
echo -e "${YELLOW}Installing global pip packages...${NC}"
75-
sudo pip install -r "$REQUIREMENTS_FILE" # Install globally
76-
77-
# Final messages
78-
echo -e "${GREEN}Setup complete. Virtual environment is ready to use.${NC}"
79-
echo -e "${GREEN}To activate the virtual environment manually, run:${NC}"
80-
echo -e "${GREEN}source ${VENV_DIR}/bin/activate${NC}"
81-
82-
echo -e "${GREEN}You can now run the CLI with:${NC}"
83-
echo -e "${GREEN}zap-cli --help${NC}"
61+
info "Setup complete."
62+
info "To activate the virtual environment manually, run:"
63+
echo "source ${VENV_DIR}/bin/activate"
64+
info "You can now run:"
65+
echo "zap-cli --help"
8466

85-
# Deactivate the virtual environment
8667
deactivate

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33
"""
4-
setup.py fo dev-cli
4+
setup.py for zap-cli
55
66
This script is used to package and distribute the zap-cli project.
77
It includes details like the package name, version, dependencies,
@@ -40,4 +40,6 @@
4040
'Operating System :: OS Independent',
4141
],
4242
python_requires='>=3.6',
43+
long_description=open('README.md').read(),
44+
long_description_content_type='text/markdown',
4345
)

0 commit comments

Comments
 (0)