forked from atiilla/pyzmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpip-package.sh
More file actions
79 lines (64 loc) · 2.22 KB
/
pip-package.sh
File metadata and controls
79 lines (64 loc) · 2.22 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
#!/bin/bash
set -e
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${GREEN}Starting Python package build process...${NC}"
# Check if Python and required tools are installed
if ! command -v python3 &> /dev/null; then
echo -e "${RED}Python 3 is not installed. Please install it first.${NC}"
exit 1
fi
# Create and activate a virtual environment
echo -e "${GREEN}Creating a virtual environment...${NC}"
VENV_DIR=".venv"
# Check if python3-venv or python-venv is installed
if ! python3 -m venv $VENV_DIR 2>/dev/null; then
echo -e "${RED}Failed to create virtual environment. Installing python3-venv...${NC}"
if command -v apt &> /dev/null; then
sudo apt install -y python3-venv
elif command -v dnf &> /dev/null; then
sudo dnf install -y python3-venv
else
echo -e "${RED}Please install python3-venv package for your distribution.${NC}"
exit 1
fi
python3 -m venv $VENV_DIR
fi
# Source the virtual environment
if [ -f "$VENV_DIR/bin/activate" ]; then
source "$VENV_DIR/bin/activate"
else
source "$VENV_DIR/Scripts/activate" # For Windows
fi
# Install required packaging tools in the virtual environment
echo -e "${GREEN}Installing required packaging tools in virtual environment...${NC}"
pip install --upgrade pip build twine
# Clean previous builds
echo -e "${GREEN}Cleaning previous builds...${NC}"
rm -rf build/ dist/ *.egg-info/
# Run tests if they exist
if [ -d "tests" ]; then
echo -e "${GREEN}Running tests...${NC}"
python -m unittest discover
fi
# Build the package using modern build tool
echo -e "${GREEN}Building package...${NC}"
python -m build
# Check the package
echo -e "${GREEN}Checking package with twine...${NC}"
twine check dist/*
# Upload to PyPI
echo -e "${GREEN}Ready to upload to PyPI.${NC}"
read -p "Do you want to upload to PyPI? (y/n): " upload_answer
if [[ $upload_answer == "y" || $upload_answer == "Y" ]]; then
echo -e "${GREEN}Uploading to PyPI...${NC}"
twine upload dist/*
echo -e "${GREEN}Upload complete!${NC}"
else
echo -e "${GREEN}Upload skipped. Package files are available in the 'dist' directory.${NC}"
fi
# Deactivate the virtual environment
deactivate
echo -e "${GREEN}All done!${NC}"